1 #include <Atlas/Objects/Root.h> 2 #include <Atlas/Objects/SmartPtr.h> 3 #include <Atlas/Objects/Encoder.h> 4 #include <Atlas/Message/DecoderBase.h> 5 #include <Atlas/Objects/loadDefaults.h> 6 7 #include <string> 8 #include <iostream> 9 #include <cstdlib> 10 11 class RootDecoder : public Atlas::Message::DecoderBase 12 { 13 protected: messageArrived(const Atlas::Message::MapType & o)14 virtual void messageArrived(const Atlas::Message::MapType& o) 15 { 16 assert(o.find(std::string("parents")) != o.end()); 17 assert((*o.find("parents")).second.asList().size() == 1); 18 assert(*(*o.find("parents")).second.asList().begin() == 19 std::string("root")); 20 } 21 }; 22 main(int argc,char ** argv)23int main(int argc, char** argv) 24 { 25 std::string atlas_xml_path; 26 char * srcdir_env = getenv("srcdir"); 27 if (srcdir_env != 0) { 28 atlas_xml_path = srcdir_env; 29 atlas_xml_path += "/"; 30 } 31 atlas_xml_path += "../../protocol/spec/atlas.xml"; 32 try { 33 Atlas::Objects::loadDefaults(atlas_xml_path); 34 } catch(Atlas::Objects::DefaultLoadingException e) { 35 std::cout << "DefaultLoadingException: " 36 << e.getDescription() << std::endl; 37 } 38 RootDecoder rd; 39 Atlas::Objects::ObjectsEncoder re(rd); 40 41 rd.streamBegin(); // important, otherwise we'll segfault! 42 Atlas::Objects::Root root_inst; 43 root_inst->setAttr("id", std::string("root_instantiation")); 44 re.streamObjectsMessage(root_inst); 45 rd.streamEnd(); 46 } 47