File: encoder1.cpp

package info (click to toggle)
atlas-cpp 0.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,192 kB
  • sloc: sh: 9,080; cpp: 6,447; xml: 3,660; python: 1,492; makefile: 166
file content (46 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Atlas/Objects/Root.h>
#include <Atlas/Objects/SmartPtr.h>
#include <Atlas/Objects/Encoder.h>
#include <Atlas/Message/DecoderBase.h>
#include <Atlas/Objects/loadDefaults.h>

#include <string>
#include <iostream>
#include <cstdlib>

class RootDecoder : public Atlas::Message::DecoderBase
{
protected:
    virtual void messageArrived(const Atlas::Message::MapType& o)
    {
        assert(o.find(std::string("parents")) != o.end());
        assert((*o.find("parents")).second.asList().size() == 1);
        assert(*(*o.find("parents")).second.asList().begin() ==
                std::string("root"));
    }
};

int main(int argc, char** argv)
{
    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";
    try {
	Atlas::Objects::loadDefaults(atlas_xml_path);
    } catch(Atlas::Objects::DefaultLoadingException e) {
	std::cout << "DefaultLoadingException: "
             << e.getDescription() << std::endl;
    }
    RootDecoder rd;
    Atlas::Objects::ObjectsEncoder re(rd);

    rd.streamBegin(); // important, otherwise we'll segfault!
    Atlas::Objects::Root root_inst;
    root_inst->setAttr("id", std::string("root_instantiation"));
    re.streamObjectsMessage(root_inst);
    rd.streamEnd();
}