当前位置: 首页>>代码示例>>C++>>正文


C++ PropertyBase::set方法代码示例

本文整理汇总了C++中PropertyBase::set方法的典型用法代码示例。如果您正苦于以下问题:C++ PropertyBase::set方法的具体用法?C++ PropertyBase::set怎么用?C++ PropertyBase::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PropertyBase的用法示例。


在下文中一共展示了PropertyBase::set方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: assert

PropertyBase * Entity::setAttr(const std::string & name, const Element & attr)
{
    PropertyBase * prop;
    // If it is an existing property, just update the value.
    PropertyDict::const_iterator I = m_properties.find(name);
    if (I != m_properties.end()) {
        prop = I->second;
        // Mark it as unclean
        prop->resetFlags(per_clean);
    } else {
        PropertyDict::const_iterator I;
        if (m_type != 0 &&
            (I = m_type->defaults().find(name)) != m_type->defaults().end()) {
            prop = I->second->copy();
        } else {
            // This is an entirely new property, not just a modifcation of
            // one in defaults, so we need to install it to this Entity.
            prop = PropertyManager::instance()->addProperty(name,
                                                            attr.getType());
            prop->install(this, name);
        }
        assert(prop != 0);
        m_properties[name] = prop;
    }

    prop->set(attr);
    // Allow the value to take effect.
    prop->apply(this);
    // Mark the Entity as unclean
    resetFlags(entity_clean);
    return prop;
}
开发者ID:cyclefusion,项目名称:cyphesis,代码行数:32,代码来源:Entity.cpp

示例2: testSetByType

void PropertyExerciser::testSetByType(PropertyBase & property,
                                      Element::Type element_type,
                                      const std::vector<T> & values)
{
    typename std::vector<T>::const_iterator I = values.begin();
    typename std::vector<T>::const_iterator Iend = values.end();
    for (; I != Iend; ++I) {
        property.set(*I);
        testGet(property, element_type);
        testAdd(property, element_type);
    }
}
开发者ID:erikogenvik,项目名称:cyphesis,代码行数:12,代码来源:PropertyExerciser.cpp

示例3: addProperties

void TypeNode::addProperties(const MapType & attributes)
{
    MapType::const_iterator J = attributes.begin();
    MapType::const_iterator Jend = attributes.end();
    PropertyBase * p;
    for (; J != Jend; ++J) {
        p = PropertyManager::instance()->addProperty(J->first,
                                                     J->second.getType());
        assert(p != 0);
        p->set(J->second);
        p->setFlags(flag_class);
        m_defaults[J->first] = p;
    }
}
开发者ID:9cat,项目名称:cyphesis,代码行数:14,代码来源:TypeNode.cpp

示例4: main

int main()
{

    {
        // Test constructor
        PropertyBase * pb = new EntityProperty();
        delete pb;
    }

    {
        // Check constructor has set flags correctly to zero
        PropertyBase * pb = new EntityProperty;
        assert(pb->flags().m_flags == 0);
        delete pb;
    }

    {
        // Check getting the value fails when property is unassigned
        Element val;

        PropertyBase * pb = new EntityProperty;
        assert(pb->get(val) == -1);
        delete pb;
    }

    {
        // Check that setting the value to a pointer works
        Entity ent("1", 1);

        PropertyBase * pb = new EntityProperty;
        pb->set(Atlas::Message::Element(&ent));
        delete pb;
    }

    {
        // Check that setting the value to a pointer works can get retrieved
        Entity ent("1", 1);
        Element val;

        PropertyBase * pb = new EntityProperty;
        pb->set(Atlas::Message::Element(&ent));
        assert(pb->get(val) == 0);
        assert(val.isMap());
        assert(val.asMap().find("$eid")->second == ent.getId());
        delete pb;
    }

    {
        // Check that adding the uninitialised value to a message works.
        MapType map;
        static const std::string key = "foo";

        PropertyBase * pb = new EntityProperty;

        MapType::const_iterator I = map.find(key);
        assert(I == map.end());

        pb->add(key, map);

        I = map.find(key);
        assert(I != map.end());
        assert(I->second.isString());
        assert(I->second.String().empty());
        delete pb;
    }

    {
        // Check that adding the uninitialised value to an argument works.
        Anonymous arg;
        static const std::string key = "foo";
        Element val;

        PropertyBase * pb = new EntityProperty;

        assert(!arg->hasAttr(key));
        assert(arg->copyAttr(key, val) != 0);

        pb->add(key, arg);

        assert(arg->hasAttr(key));
        assert(arg->copyAttr(key, val) == 0);
        assert(val.isString());
        assert(val.String().empty());
        delete pb;
    }

    {
        // Check that adding the uninitialised value to an argument as a hard
        // attribute works
        Anonymous arg;
        static const std::string key = "id";
        Element val;

        PropertyBase * pb = new EntityProperty;

        assert(!arg->hasAttr(key));
        // Hard coded attribute ID has not been set, so returns false, but
        // copying it gives us the default
        assert(arg->copyAttr(key, val) == 0);
        assert(val.isString());
//.........这里部分代码省略.........
开发者ID:worldforge,项目名称:cyphesis,代码行数:101,代码来源:EntityPropertyTest.cpp

示例5: main

int main()
{
    // Assertions to verify the flags have the desired properties.
    assert((per_clean | per_mask) == per_mask);
    assert((per_ephem | per_mask) == per_mask);
    assert((per_ephem | per_clean) == per_mask);

    assert((per_clean & per_mask) == per_clean);
    assert((per_ephem & per_mask) == per_ephem);
    assert((per_ephem & per_clean) == 0);

    assert((vis_hidden | vis_mask) == vis_mask);
    assert((vis_internal | vis_mask) == vis_mask);
    assert((vis_internal | vis_hidden) == vis_mask);

    assert((vis_hidden & vis_mask) == vis_hidden);
    assert((vis_internal & vis_mask) == vis_internal);
    assert((vis_internal & vis_hidden) == 0);

    assert((vis_mask & per_mask) == 0);

    Element val;

    {
    PropertyBase * pb = new MinimalProperty;
    exerciseProperty(pb);
    delete pb;
    }

    {
    long i = 23;
    PropertyBase * pb = new SoftProperty;
    assert(pb->flags() == 0);
    pb->set(i);
    pb->get(val);
    assert(val == i);
    exerciseProperty(pb);
    delete pb;
    }

    {
    long i = 23;
    PropertyBase * pb = new SoftProperty(i);
    assert(pb->flags() == 0);
    pb->get(val);
    assert(val == i);
    exerciseProperty(pb);
    delete pb;
    }

    {
    long i = 23;
    PropertyBase * pb = new Property<int>(0);
    assert(pb->flags() == 0);
    pb->set(i);
    pb->get(val);
    assert(val == i);
    exerciseProperty(pb);
    delete pb;
    }

    {
    long i = 23;
    PropertyBase * pb = new Property<long>(0);
    assert(pb->flags() == 0);
    pb->set(i);
    pb->get(val);
    assert(val == i);
    exerciseProperty(pb);
    delete pb;
    }

    {
    float f = 17.2f;
    PropertyBase * pb = new Property<float>(1);
    assert(pb->flags() == 1);
    pb->set(f);
    pb->get(val);
    assert(val == f);
    exerciseProperty(pb);
    delete pb;
    }

    {
    double d = 65.4;
    PropertyBase * pb = new Property<double>(2);
    assert(pb->flags() == 2);
    pb->set(d);
    pb->get(val);
    assert(val == d);
    exerciseProperty(pb);
    delete pb;
    }

    {
    std::string s = "Test String";
    PropertyBase * pb = new Property<std::string>(3);
    assert(pb->flags() == 3);
    pb->set(s);
    pb->get(val);
//.........这里部分代码省略.........
开发者ID:erikogenvik,项目名称:cyphesis,代码行数:101,代码来源:Propertytest.cpp

示例6: assert

void EntityBuildertest::test_sequence4()
{
    EntityBuilder & entity_factory = *EntityBuilder::instance();
    // Attributes for test entities being created
    Anonymous attributes;

    // Check that creating an entity of a type we know we have not yet
    // installed results in a null pointer.
    assert(entity_factory.newEntity("1", 1, "custom_type", attributes, BaseWorld::instance()) == 0);

    // Get a reference to the internal dictionary of entity factories.
    const FactoryDict & factory_dict = entity_factory.m_entityFactories;

    // Make sure it has some factories in it already.
    assert(!factory_dict.empty());

    // Assert the dictionary does not contain the factory we know we have
    // have not yet installed.
    assert(factory_dict.find("custom_type") == factory_dict.end());

    // Set up a type description for a new type, and install it
    EntityFactoryBase * custom_type_factory = new EntityFactory<Entity>();
    custom_type_factory->m_attributes["test_custom_type_attr"] =
          "test_value";
    {
        int ret;
        ret = entity_factory.installFactory("custom_type",
                                            atlasClass("custom_type", "thing"),
                                            custom_type_factory);
        custom_type_factory->m_type = new TypeNode("custom_type");

        ASSERT_EQUAL(ret, 0);
    }

    PropertyBase * p = new Property<std::string>; 
    custom_type_factory->m_type->addProperty("test_custom_type_attr", p);
    p->set("test_value");

    // Check that the factory dictionary now contains a factory for
    // the custom type we just installed.
    FactoryDict::const_iterator I = factory_dict.find("custom_type");
    assert(I != factory_dict.end());
    assert(custom_type_factory == I->second);

    MapType::const_iterator J;
    // Check the factory has the attributes we described on the custom
    // type.
    J = custom_type_factory->m_attributes.find("test_custom_type_attr");
    assert(J != custom_type_factory->m_attributes.end());
    assert(J->second.isString());
    assert(J->second.String() == "test_value");

    // Create an instance of our custom type, ensuring that it works.
    LocatedEntity * test_ent = entity_factory.newEntity("1", 1, "custom_type", attributes, BaseWorld::instance());
    assert(test_ent != 0);

    assert(test_ent->getType() == custom_type_factory->m_type);

    // Check that creating an entity of a type we know we have not yet
    // installed results in a null pointer.
    assert(entity_factory.newEntity("1", 1, "custom_inherited_type", attributes, BaseWorld::instance()) == 0);

    // Assert the dictionary does not contain the factory we know we have
    // have not yet installed.
    assert(factory_dict.find("custom_inherited_type") == factory_dict.end());
}
开发者ID:Arsakes,项目名称:cyphesis,代码行数:66,代码来源:EntityBuildertest.cpp

示例7: restorePropertiesRecursively

void StorageManager::restorePropertiesRecursively(LocatedEntity * ent)
{
    Database * db = Database::instance();
    PropertyManager * pm = PropertyManager::instance();
    DatabaseResult res = db->selectProperties(ent->getId());

    //Keep track of those properties that have been set on the instance, so we'll know what
    //type properties we should ignore.
    std::unordered_set<std::string> instanceProperties;

    DatabaseResult::const_iterator I = res.begin();
    DatabaseResult::const_iterator Iend = res.end();
    for (; I != Iend; ++I) {
        const std::string name = I.column("name");
        if (name.empty()) {
            log(ERROR, compose("No name column in property row for %1",
                               ent->getId()));
            continue;
        }
        const std::string val_string = I.column("value");
        if (name.empty()) {
            log(ERROR, compose("No value column in property row for %1,%2",
                               ent->getId(), name));
            continue;
        }
        MapType prop_data;
        db->decodeMessage(val_string, prop_data);
        MapType::const_iterator J = prop_data.find("val");
        if (J == prop_data.end()) {
            log(ERROR, compose("No property value data for %1:%2",
                               ent->getId(), name));
            continue;
        }
        assert(ent->getType() != 0);
        const Element & val = J->second;

        Element existingVal;
        if (ent->getAttr(name, existingVal) == 0) {
            if (existingVal == val) {
                //If the existing property, either on the instance or the type, is equal to the persisted one just skip it.
                continue;
            }
        }


        PropertyBase * prop = ent->modProperty(name);
        if (prop == nullptr) {
            prop = pm->addProperty(name, val.getType());
            prop->install(ent, name);
            //This transfers ownership of the property to the entity.
            ent->setProperty(name, prop);
        }

        //If we get to here the property either doesn't exists, or have a different value than the default or existing property.
        prop->set(val);
        prop->setFlags(per_clean | per_seen);
        prop->apply(ent);
        instanceProperties.insert(name);
    }

    if (ent->getType()) {
        for (auto& propIter : ent->getType()->defaults()) {
            if (!instanceProperties.count(propIter.first)) {
                PropertyBase * prop = propIter.second;
                // If a property is in the class it won't have been installed
                // as setAttr() checks
                prop->install(ent, propIter.first);
                // The property will have been applied if it has an overriden
                // value, so we only apply it the value is still default.
                prop->apply(ent);
            }
        }
    }


    //Now restore all properties of the child entities.
    if (ent->m_contains) {
        for (auto& childEntity : *ent->m_contains) {
            restorePropertiesRecursively(childEntity);
        }
    }

    //We must send a sight op to the entity informing it of itself before we send any thoughts.
    //Else the mind won't have any information about itself.
    {
        Atlas::Objects::Operation::Sight sight;
        sight->setTo(ent->getId());
        Atlas::Objects::Entity::Anonymous args;
        ent->addToEntity(args);
        sight->setArgs1(args);
        ent->sendWorld(sight);
    }
    //We should also send a sight op to the parent entity which owns the entity.
    //TODO: should this really be necessary or should we rely on other Sight functionality?
    if (ent->m_location.m_loc) {
        Atlas::Objects::Operation::Sight sight;
        sight->setTo(ent->m_location.m_loc->getId());
        Atlas::Objects::Entity::Anonymous args;
        ent->addToEntity(args);
        sight->setArgs1(args);
//.........这里部分代码省略.........
开发者ID:Arsakes,项目名称:cyphesis,代码行数:101,代码来源:StorageManager.cpp


注:本文中的PropertyBase::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。