void ClientConnection::processAnonymousGet(const Get& get) { const std::vector<Root>& args = get->getArgs(); if (args.empty()) { Info serverInfo; RootEntity svObj; Atlas::Message::ListType prs; prs.push_back("server"); svObj->setParentsAsList(prs); svObj->setName("Bob's StubServer"); svObj->setAttr("server", "stubserver"); svObj->setAttr("ruleset", "stub-world"); svObj->setAttr("uptime", 666.0); svObj->setAttr("clients", 42); serverInfo->setArgs1(svObj); send(serverInfo); } else { std::string typeName = args.front()->getId(); if (m_server->m_types.count(typeName)) { Info typeInfo; typeInfo->setArgs1(m_server->m_types[typeName]); typeInfo->setRefno(get->getSerialno()); send(typeInfo); } else sendError("unknown type " + typeName, get); } }
void check_float_list3(const Atlas::Message::ListType &list, double el1, double el2, double el3) { assert( list.size() == 3 ); Atlas::Message::ListType::const_iterator i = list.begin(); assert( (*i++) == el1 ); assert( (*i++) == el2 ); assert( (*i++) == el3 ); i++; }
void EntityImporterBase::updateRule(const Root& existingDefinition, const Root& newDefinition, OpVector & res) { m_state = RULE_UPDATING; Root updatedDefinition = newDefinition.copy(); //If the existing definition had any children that aren't part of the import, we should preserve those std::list<std::string> existingChildren, newChildren; extractChildren(existingDefinition, existingChildren); extractChildren(newDefinition, newChildren); for (auto& child : newChildren) { existingChildren.remove(child); } for (auto& child : existingChildren) { if (mPersistedRules.find(child) == mPersistedRules.end()) { newChildren.push_back(child); } } if (!newChildren.empty() && !existingChildren.empty()) { Atlas::Message::ListType childrenElement; for (auto& child : newChildren) { childrenElement.emplace_back(child); } updatedDefinition->setAttr("children", childrenElement); } if (updatedDefinition->asMessage() != existingDefinition->asMessage()) { S_LOG_INFO("Updating server rule '"<< updatedDefinition->getId() << "'."); Atlas::Objects::Operation::Set setOp; setOp->setFrom(mAccountId); setOp->setArgs1(updatedDefinition); setOp->setSerialno(newSerialNumber()); res.push_back(setOp); } else { mStats.rulesProcessedCount++; EventProgress.emit(); S_LOG_VERBOSE("Not updating server rule '"<< updatedDefinition->getId() << "' as nothing is changed."); walkRules(res); } }
float extractFloat(const Atlas::Message::ListType& params, size_t position) { if (params.size() > position) { const Atlas::Message::Element& elem(params[position]); if (elem.isNum()) { return elem.asNum(); } } return 0; }
void testApplyMod() { bool shouldQuit, pollEris; MainLoopController loopController(shouldQuit, pollEris); Ogre::Root root; TerrainSetup terrainSetup; Terrain::TerrainHandler& terrainHandler = terrainSetup.terrainHandler; DummyEntity entity; EntityHolder entityHolder(entity); entity.setAttr("pos", WFMath::Point<3>::ZERO().toAtlas()); float terrainHeight = 25.0f; CPPUNIT_ASSERT(terrainSetup.createBaseTerrain(terrainHeight)); CPPUNIT_ASSERT(terrainSetup.createPages()); CPPUNIT_ASSERT(terrainSetup.reloadTerrain()); Atlas::Message::ListType polygon; polygon.push_back(WFMath::Point<2>(-10, -10).toAtlas()); polygon.push_back(WFMath::Point<2>(-10, 10).toAtlas()); polygon.push_back(WFMath::Point<2>(10, 10).toAtlas()); polygon.push_back(WFMath::Point<2>(10, -10).toAtlas()); Atlas::Message::MapType shape; shape["points"] = polygon; shape["type"] = "polygon"; Atlas::Message::MapType mod; mod["shape"] = shape; mod["type"] = "levelmod"; mod["heightoffset"] = 2.0f; entity.setAttr("terrainmod", mod); OgreView::Terrain::TerrainMod terrainMod(entity); terrainMod.init(); terrainHandler.addTerrainMod(&terrainMod); }
int main() { Eris::Logged.connect(sigc::ptr_fun(writeLog)); Eris::setLogLevel(Eris::LOG_DEBUG); { TestConnection con("name", "localhost", 6767, true); TestAccount acc(&con); std::string fake_char_id("1"); TestAvatar ea(&acc, fake_char_id); acc.setup_insertActiveCharacters(&ea); TestEntity* char_ent = new TestEntity(fake_char_id, 0, ea.getView()); ea.setup_setEntity(char_ent); typedef std::map<std::string, Atlas::Message::Element> ElementStore; ElementStore modTypes; ElementStore shapes; ElementStore levelMods; Atlas::Message::MapType levelMod1; levelMod1["type"] = Atlas::Message::Element("levelmod"); levelMods["1"] = levelMod1; Atlas::Message::MapType levelMod2(levelMod1); levelMod2["height"] = 20; levelMods["2"] = levelMod2; Atlas::Message::MapType levelMod3(levelMod1); levelMod2["heightoffset"] = 30; levelMods["3"] = levelMod3; ElementStore adjustMods; Atlas::Message::MapType adjustMod1; adjustMod1["type"] = Atlas::Message::Element("adjustmod"); adjustMods["1"] = levelMod1; Atlas::Message::MapType adjustMod2(adjustMod1); adjustMod2["height"] = 20; adjustMods["2"] = adjustMod2; Atlas::Message::MapType adjustMod3(adjustMod1); adjustMod2["heightoffset"] = 30; adjustMods["3"] = adjustMod3; Atlas::Message::MapType craterMod1; craterMod1["type"] = Atlas::Message::Element("cratermod"); ElementStore slopeMods; Atlas::Message::MapType slopeMod1; slopeMod1["type"] = Atlas::Message::Element("slopemod"); Atlas::Message::ListType slopes; slopes.push_back(10); slopes.push_back(20); slopeMod1["slopes"] = slopes; slopeMods["1"] = slopeMod1; Atlas::Message::MapType shapeCircle; shapeCircle["radius"] = 15; shapeCircle["position"] = Atlas::Message::ListType(2, 0.); shapeCircle["type"] = "ball"; shapes["ball"] = shapeCircle; Atlas::Message::MapType shapePolygon; Atlas::Message::ListType points; points.push_back(WFMath::Point<2>(0,0).toAtlas()); points.push_back(WFMath::Point<2>(10,0).toAtlas()); points.push_back(WFMath::Point<2>(10,10).toAtlas()); points.push_back(WFMath::Point<2>(0,10).toAtlas()); shapePolygon["points"] = points; shapePolygon["type"] = "polygon"; shapes["polygon"] = shapePolygon; shapes["empty"] = Atlas::Message::MapType(); //no terrain mod info { Atlas::Message::MapType emptyElement; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", emptyElement); Eris::TerrainModObserver mod(mod_ent); assert(!mod.init()); } //no shape { Atlas::Message::MapType modElement = levelMod1; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", modElement); Eris::TerrainModObserver mod(mod_ent); assert(!mod.init()); } //test level mod for (ElementStore::iterator I = levelMods.begin(); I != levelMods.end(); ++I) { for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) { std::cout << "Testing level mod " << I->first << " with " << J->first << std::endl; Atlas::Message::Element modElement = I->second; modElement.asMap()["shape"] = J->second; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", modElement); Eris::TerrainModObserver mod(mod_ent); if (J->first == "empty") { assert(!mod.init()); } else { assert(mod.init()); } } } //test adjust mod for (ElementStore::iterator I = adjustMods.begin(); I != adjustMods.end(); ++I) { for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) { std::cout << "Testing adjust mod " << I->first << " with " << J->first << std::endl; Atlas::Message::Element modElement = I->second; modElement.asMap()["shape"] = J->second; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", modElement); Eris::TerrainModObserver mod(mod_ent); if (J->first == "empty") { assert(!mod.init()); } else { assert(mod.init()); } } } //test slope mod for (ElementStore::iterator I = slopeMods.begin(); I != slopeMods.end(); ++I) { for (ElementStore::iterator J = shapes.begin(); J != shapes.end(); ++J) { std::cout << "Testing slope mod " << I->first << " with " << J->first << std::endl; Atlas::Message::Element modElement = I->second; modElement.asMap()["shape"] = J->second; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", modElement); Eris::TerrainModObserver mod(mod_ent); if (J->first == "empty") { assert(!mod.init()); } else { assert(mod.init()); } } } Atlas::Message::MapType shapeBall; shapeBall["radius"] = 15; shapeBall["position"] = Atlas::Message::ListType(3, 0.); shapeBall["type"] = "ball"; //test crater mod { Atlas::Message::MapType modElement = craterMod1; modElement["shape"] = shapeCircle; TestEntity* mod_ent = new TestEntity("2", 0, ea.getView()); mod_ent->setup_setAttr("terrainmod", modElement); Eris::TerrainModObserver mod(mod_ent); assert(mod.init()); } } return 0; }
void EntityImporterBase::sendMinds() { if (!mResolvedMindMapping.empty()) { S_LOG_INFO("Sending minds."); for (auto mind : mResolvedMindMapping) { Atlas::Message::MapType message; mind.second->addToMessage(message); Atlas::Message::Element thoughtsElem = message["thoughts"]; Atlas::Message::ListType thoughtArgs; if (thoughtsElem.isList()) { Atlas::Message::ListType thoughtList = thoughtsElem.List(); for (auto& thought : thoughtList) { //If the thought is a list of things the entity owns, we should adjust it with the new entity ids. if (thought.isMap()) { auto& thoughtMap = thought.Map(); if (thoughtMap.count("things") > 0) { auto& thingsElement = thoughtMap.find("things")->second; if (thingsElement.isMap()) { for (auto& thingI : thingsElement.asMap()) { if (thingI.second.isList()) { Atlas::Message::ListType newList; for (auto& thingId : thingI.second.asList()) { if (thingId.isString()) { const auto& entityIdLookupI = mEntityIdMap.find(thingId.asString()); //Check if the owned entity has been created with a new id. If so, replace the data. if (entityIdLookupI != mEntityIdMap.end()) { newList.emplace_back(entityIdLookupI->second); } else { newList.push_back(thingId); } } else { newList.push_back(thingId); } } thingI.second = newList; } } } } if (thoughtMap.count("pending_things") > 0) { //things that the entity owns, but haven't yet discovered are expressed as a list of entity ids auto& pendingThingsElement = thoughtMap.find("pending_things")->second; if (pendingThingsElement.isList()) { Atlas::Message::ListType newList; for (auto& thingId : pendingThingsElement.asList()) { if (thingId.isString()) { const auto& entityIdLookupI = mEntityIdMap.find(thingId.asString()); //Check if the owned entity has been created with a new id. If so, replace the data. if (entityIdLookupI != mEntityIdMap.end()) { newList.emplace_back(entityIdLookupI->second); } else { newList.push_back(thingId); } } else { newList.push_back(thingId); } } pendingThingsElement = newList; } } if (thoughtMap.count("object") > 0) { auto& objectElement = thoughtMap.find("object")->second; if (objectElement.isString()) { std::string& objectString = objectElement.String(); //Other entities are referred to using the syntax "'$eid:...'". //For example, the entity with id 2 would be "'$eid:2'". auto pos = objectString.find("$eid:"); if (pos != std::string::npos) { auto quotePos = objectString.find('\'', pos); if (quotePos != std::string::npos) { auto id = objectString.substr(pos + 5, quotePos - pos - 5); auto I = mEntityIdMap.find(id); if (I != mEntityIdMap.end()) { objectString.replace(pos + 5, quotePos - 7, I->second); } } } } } } thoughtArgs.push_back(thought); } } Atlas::Objects::Operation::RootOperation thinkOp; thinkOp->setParent("think"); thinkOp->setTo(mind.first); //By setting it TO an entity and FROM our avatar we'll make the server deliver it as //if it came from the entity itself (the server rewrites the FROM to be of the entity). thinkOp->setFrom(mAvatarId); thinkOp->setSerialno(newSerialNumber()); Atlas::Objects::Operation::Set setOp; setOp->setArgsAsList(thoughtArgs); thinkOp->setArgs1(setOp); mStats.mindsProcessedCount++; S_LOG_VERBOSE("Restoring mind of " << mind.first); mThoughtOpsInTransit++; sigc::slot<void, const Operation&> slot = sigc::mem_fun(*this, &EntityImporterBase::operationThinkResult); sendAndAwaitResponse(thinkOp, slot); EventProgress.emit(); } mResolvedMindMapping.clear(); } else { complete(); } }
void testUpdateMod() { Ogre::Root root; TerrainSetup terrainSetup; TestTerrainHandler& terrainHandler = terrainSetup.terrainHandler; DummyEntity entity; EntityHolder entityHolder(entity); entity.setAttr("pos", WFMath::Point<3>::ZERO().toAtlas()); float terrainHeight = 25.0f; CPPUNIT_ASSERT(terrainSetup.createBaseTerrain(terrainHeight)); CPPUNIT_ASSERT(terrainSetup.createPages()); CPPUNIT_ASSERT(terrainSetup.reloadTerrain()); Atlas::Message::ListType polygon; polygon.push_back(WFMath::Point<2>(-10, -10).toAtlas()); polygon.push_back(WFMath::Point<2>(-10, 10).toAtlas()); polygon.push_back(WFMath::Point<2>(10, 10).toAtlas()); polygon.push_back(WFMath::Point<2>(10, -10).toAtlas()); Atlas::Message::MapType shape; shape["points"] = polygon; shape["type"] = "polygon"; Atlas::Message::MapType mod; mod["shape"] = shape; mod["type"] = "levelmod"; mod["heightoffset"] = 2.0f; entity.setAttr("terrainmod", mod); OgreView::Terrain::TerrainMod* terrainMod = new Terrain::TerrainMod(entity); terrainMod->init(); { AfterTerrainUpdateListener afterTerrainUpdateListener(terrainHandler.EventAfterTerrainUpdate); //The shape should affect all four pages. terrainHandler.addTerrainMod(terrainMod); { Timer timer; do { terrainSetup.es.processAllHandlers(); } while (afterTerrainUpdateListener.getCompletedCount() < 4); } CPPUNIT_ASSERT(afterTerrainUpdateListener.getCompletedCount() == 4); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, -5, 2.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, 5, 2.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, 5, 2.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, -5, 2.0f)); } mod["heightoffset"] = 20.0f; //Setting the attribute should trigger a mod change entity.setAttr("terrainmod", mod); { AfterTerrainUpdateListener afterTerrainUpdateListener(terrainHandler.EventAfterTerrainUpdate); { Timer timer; do { terrainSetup.es.processAllHandlers(); // } while ((!timer.hasElapsed(5000)) && afterTerrainUpdateListener.getCompletedCount() < 4); } while (afterTerrainUpdateListener.getCompletedCount() < 4); } CPPUNIT_ASSERT(afterTerrainUpdateListener.getCompletedCount() == 4); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, -5, 20.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, 5, 20.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, 5, 20.0f)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, -5, 20.0f)); } //Move the mod out of the way entity.setAttr("pos", WFMath::Point<3>(40, 40, 0).toAtlas()); { AfterTerrainUpdateListener afterTerrainUpdateListener(terrainHandler.EventAfterTerrainUpdate); { Timer timer; do { terrainSetup.es.processAllHandlers(); } while ((!timer.hasElapsed(5000)) && afterTerrainUpdateListener.getCompletedCount() < 4); } CPPUNIT_ASSERT(afterTerrainUpdateListener.getCompletedCount() == 4); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, -5, 25)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(-5, 5, 25)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, 5, 25)); CPPUNIT_ASSERT(terrainHandler.checkTerrainHeight(5, -5, 25)); } }
void testXML() { RootEntity human; human->setId("foo"); Move move_op; move_op->setFrom(std::string("bar")); std::vector<Root> move_args(1); move_args[0] = human; move_op->setArgs(move_args); Atlas::Message::ListType velocity; velocity.push_back(2.0); velocity.push_back(1.0); velocity.push_back(0.0); human->setVelocityAsList(velocity); // typedef BaseObjectData *(*alloc_func)(); // alloc_func alloc_entity = &Entity::RootEntityDataInstance::alloc; // BaseObjectData *bod = alloc_entity(); //Root human2(bod); Root human2 = Atlas::Objects::factory<Atlas::Objects::Entity::RootEntityData>("root_enitty", Atlas::Objects::Entity::RootEntity()->getClassNo()); std::cout<<"human.id="<<human->getId()<<std::endl; std::cout<<"human2.id="<<human2->getId()<<std::endl; #if 0 typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs; FactoryCodecs *myCodecs = &Factory<Codec >::factories(); FactoryCodecs::iterator i; std::cout<<"myCodecs: "<<myCodecs->size(); for (i = myCodecs->begin(); i != myCodecs->end(); ++i) std::cout<<":"<<(*i)->getName(); std::cout<<std::endl; #endif //DebugBridge bridge; TestDecoder bridge; #if USE_FILE fstream stream; std::string atlas_xml_path; char * srcdir_env = getenv("srcdir"); if (srcdir_env != 0) { atlas_xml_path = srcdir_env; atlas_xml_path += "/"; } atlas_xml_path += "../../protocol/spec/atlas.xml"; stream.open(atlas_xml_path, std::ios::in); assert(!!stream); #else std::stringstream stream; #endif // typedef std::list<Atlas::Factory<Atlas::Codec >*> FactoryCodecs; // FactoryCodecs *myCodecs = &Factory<Codec >::factories(); // FactoryCodecs::iterator codec_i; // Atlas::Codec *codec = NULL; // for(codec_i = myCodecs->begin(); codec_i != myCodecs->end(); ++codec_i) // { // std::cout<<(*codec_i)->getName()<<std::endl; // if ((*codec_i)->getName() == "XML") { // codec = (*codec_i)->New(Codec::Parameters(stream, &bridge)); // } // } // assert(codec); Account account; Login l; account->setAttr("id", std::string("al")); account->setAttr("password", std::string("ping")); //list<Message::Object> args(1,account->asObject()); //l->setArgsAsList(args); std::vector<Root> args(1); args[0] = account; l->setArgs(args); //coder->streamObjectsMessage((Root&)l); //<map><list name="args"><map><std::string name="id">al</strin //g></map></list><list name="parents"><std::string>root</std::string></list><std::string name="ob //jtype">op_definition</std::string></map> Atlas::Codec *codec; #if USE_XML codec = new Atlas::Codecs::XML((std::iostream&)stream, bridge); #else codec = new Atlas::Codecs::Packed(stream, bridge); #endif assert(codec); #if USE_FILE while(stream) { codec->poll(); //std::cout<<"--------"<<std::endl; } #else codec->streamBegin(); Atlas::Objects::ObjectsEncoder eno(*codec); // eno.streamObjectsMessage(move_op); eno.streamObjectsMessage(l); Anonymous e; eno.streamObjectsMessage(e); e->setId("foo"); eno.streamObjectsMessage(e); // Atlas::Message::Encoder en(codec); // en.streamObjectsMessage(human->asObject()); codec->streamEnd(); std::cout<<std::endl<<stream.str()<<std::endl; //[$from=bar(args=[$id=foo])][$id=foo] //<atlas><map><std::string name="from">bar</std::string><list name="args"><map><std::string name="id">foo</std::string></map></list></map><map><std::string name="id">foo</std::string></map></atlas> #endif delete codec; }
void test() { const double x1 = 3.5; const double y1 = -4.6; const double z1 = 2.0; const double x2 = 42.0; const double y2 = 7.0; std::vector<RootEntity> ent_vec(10); for(int i=0; i<10; i++) { DEBUG_PRINT(std::cout<<std::endl<<"round:"<<i<<std::endl); RootEntity human; //check for empty default: DEBUG_PRINT(std::cout<<"empty ok?"<<std::endl); Atlas::Message::ListType empty = human->getVelocityAsList(); if(i==0) check_float_list3(empty, 0.0, 0.0, 0.0); else check_float_list3(empty, 0.0, y2, 0.0); //check after setting it DEBUG_PRINT(std::cout<<"setting ok?"<<std::endl); Atlas::Message::ListType velocity; velocity.push_back(x1); velocity.push_back(y1); velocity.push_back(z1); check_float_list3(velocity, x1, y1, z1); human->setVelocityAsList(velocity); Atlas::Message::ListType foo = human->getVelocityAsList(); check_float_list3(foo, x1, y1, z1); DEBUG_PRINT(std::cout<<"changing it?"<<std::endl); std::vector<double> &foo2 = human->modifyVelocity(); *foo2.begin() = x2; check_float_list3(human->getVelocityAsList(), x2, y1, z1); DEBUG_PRINT(std::cout<<"check change result?"<<std::endl); foo = human->getVelocityAsList(); check_float_list3(foo, x2, y1, z1); DEBUG_PRINT(std::cout<<"std::vector of entities?"<<std::endl); const Atlas::Message::ListType &ent_velocity = ent_vec[i]->getVelocityAsList(); if(i==0) check_float_list3(ent_velocity, 0.0, 0.0, 0.0); else check_float_list3(ent_velocity, 0.0, y2, 0.0); DEBUG_PRINT(std::cout<<"base?"<<std::endl); RootEntity base_entity = Atlas::Objects::Entity::RootEntityData::allocator.getDefaultObjectInstance(); std::vector<double> &base = base_entity->modifyVelocity(); base[1] = y2; check_float_list3(base_entity->getVelocityAsList(), 0.0, y2, 0.0); RootOperation move_op; std::vector<Root> move_args(1); move_args[0] = human; move_op->setArgs(move_args); RootOperation sight_op; //sight_op->setFrom(humanent.asObjectPtr()); std::vector<Root> sight_args(1); sight_args[0] = move_op; sight_op->setArgs(sight_args); //test DEBUG_PRINT(std::cout<<"get move_op?"<<std::endl); const std::vector<Root>& test_args = sight_op->getArgs(); assert(test_args.size() == 1); RootOperation test_op = (RootOperation&)test_args[0]; DEBUG_PRINT(std::cout<<"get human_ent?"<<std::endl); const std::vector<Root>& test_args2 = test_op->getArgs(); assert(test_args2.size() == 1); RootEntity test_ent = (RootEntity&)test_args2[0]; Atlas::Message::ListType foo3 = test_ent->getVelocityAsList(); check_float_list3(foo3, x2, y1, z1); std::vector<double> coords(3, 0.0); human->setPos(coords); human->setVelocity(coords); human->modifyVelocity()[0] = 1.0; check_float_list3(human->getPosAsList(), 0.0, 0.0, 0.0); check_float_list3(human->getVelocityAsList(), 1.0, 0.0, 0.0); } }
void testValues() { Account account; Login l; account->setId("al"); account->setAttr("password", std::string("ping")); l->setArgs1(account); // assert(l->getArgs()[0]->getLongDescription()=="Later in hierarchy tree objtype changes to 'object' when actual game objects are made."); // assert(l->getArgs()[0]->getDescription()=="Base class for accounts"); assert(l->getId()==""); assert(l->getParents().front()=="login"); assert(l->getObjtype()=="op"); // std::cout<<std::endl<<"account.long_description: " // <<l->getArgs()[0]->getLongDescription()<<std::endl; { Atlas::Message::MapType mobj; Atlas::Message::ListType parents; parents.push_back(std::string("account")); mobj["parents"] = parents; mobj["name"] = std::string("foo"); mobj["objtype"] = std::string("op"); Root obj = Atlas::Objects::Factories::instance()->createObject(mobj); assert(obj->getClassNo() == Atlas::Objects::Entity::ACCOUNT_NO); assert(obj->getId() == ""); assert(obj->isDefaultId() == true); assert(obj->getName() == "foo"); assert(obj->isDefaultName() == false); assert(obj->getParents().front() == "account"); //should this be true? modify MessageObject2ClassObject if yes assert(obj->isDefaultParents() == false); assert(obj->getObjtype() == "op"); assert(obj->isDefaultObjtype() == false); //should this be true? // assert(obj->getDescription() == "Base class for accounts"); // assert(obj->isDefaultDescription() == true); } { Atlas::Message::MapType mobj; Root obj = Atlas::Objects::objectDefinitions.find(std::string("account"))->second; assert(obj->getClassNo() == Atlas::Objects::Entity::ACCOUNT_NO); assert(obj->getId() == "account"); assert(obj->isDefaultId() == false); assert(obj->getName() == ""); assert(obj->isDefaultName() == true); assert(obj->getParents().front() == "admin_entity"); assert(obj->isDefaultParents() == false); assert(obj->getObjtype() == "class"); assert(obj->isDefaultObjtype() == false); // assert(obj->getDescription() == "Base class for accounts"); // assert(obj->isDefaultDescription() == false); } { Atlas::Message::MapType mobj; Root obj = Atlas::Objects::Factories::instance()->createObject(mobj); assert(obj->getClassNo() == Atlas::Objects::Entity::ANONYMOUS_NO); assert(obj->getId() == ""); assert(obj->getName() == ""); assert(obj->getParents().size() == 0); assert(obj->getObjtype() == "obj"); // assert(obj->getDescription() == ""); } { Atlas::Message::MapType mobj; mobj["id"] = std::string("bar"); mobj["name"] = std::string("foo"); Atlas::Message::ListType parents; parents.push_back(std::string("account")); mobj["parents"] = parents; Root obj = Atlas::Objects::Factories::instance()->createObject(mobj); assert(obj->getClassNo() == Atlas::Objects::Entity::ANONYMOUS_NO); assert(obj->getId() == "bar"); assert(obj->getName() == "foo"); assert(obj->getParents().front() == "account"); assert(obj->getObjtype() == "obj"); // assert(obj->getDescription() == ""); } { Atlas::Message::MapType maccount; maccount["id"] = std::string("bar"); maccount["name"] = std::string("foo"); Atlas::Message::ListType parents; parents.push_back(std::string("player")); maccount["parents"] = parents; maccount["objtype"] = "obj"; Atlas::Message::MapType mcreate; mcreate["from"] = std::string("bar"); Atlas::Message::ListType parents2; parents2.push_back(std::string("create")); mcreate["parents"] = parents2; Atlas::Message::ListType args; args.push_back(maccount); mcreate["args"] = args; mcreate["objtype"] = "op"; Create op = Atlas::Objects::smart_dynamic_cast<Create>(Atlas::Objects::Factories::instance()->createObject(mcreate)); assert(op->getClassNo() == Atlas::Objects::Operation::CREATE_NO); assert(op->instanceOf(Atlas::Objects::Operation::CREATE_NO)); assert(op->instanceOf(Atlas::Objects::Operation::ACTION_NO)); assert(op->instanceOf(Atlas::Objects::ROOT_NO)); assert(!op->instanceOf(Atlas::Objects::Operation::COMBINE_NO)); assert(!op->instanceOf(Atlas::Objects::Entity::ACCOUNT_NO)); assert(op->getFrom() == "bar"); assert(op->getParents().size() == 1); assert(op->getParents().front() == "create"); assert(op->getObjtype() == "op"); // assert(op->getDescription() == // "Create new things from nothing using this operator."); assert(op->getArgs().size() == 1); Account op_arg = (Account&)op->getArgs().front(); assert(op_arg->getClassNo() == Atlas::Objects::Entity::PLAYER_NO); assert(!op_arg->instanceOf(Atlas::Objects::Operation::CREATE_NO)); assert(!op_arg->instanceOf(Atlas::Objects::Operation::ACTION_NO)); assert(op_arg->instanceOf(Atlas::Objects::ROOT_NO)); assert(!op_arg->instanceOf(Atlas::Objects::Operation::COMBINE_NO)); assert(op_arg->instanceOf(Atlas::Objects::Entity::ACCOUNT_NO)); assert(op_arg->instanceOf(Atlas::Objects::Entity::PLAYER_NO)); assert(op_arg->getId() == "bar"); assert(op_arg->getParents().size() == 1); assert(op_arg->getParents().front() == "player"); assert(op_arg->getObjtype() == "obj"); // assert(op_arg->getDescription() == "Player accounts"); assert(op_arg->getName() == "foo"); #if 0 //tmp assert(op_arg->hasAttr("password")); assert(op_arg->getAttr("password").isString()); assert(op_arg->getAttr("password").asString() == ""); #endif assert(op_arg->hasAttr("name")); assert(!op_arg->hasAttr("foo")); assert(!op_arg->hasAttr("pos")); assert(!op_arg->isDefaultName()); assert(op_arg->isDefaultPos()); } }