~ubuntu-branches/ubuntu/breezy/atlas-cpp/breezy

« back to all changes in this revision

Viewing changes to tests/Objects/encoder1.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2005-10-02 11:41:44 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051002114144-8qmn4d1cdn9g27ta
Tags: 0.5.98-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
class RootDecoder : public Atlas::Message::DecoderBase
 
11
{
 
12
protected:
 
13
    virtual void messageArrived(const Atlas::Message::MapType& o)
 
14
    {
 
15
        assert(o.find(std::string("parents")) != o.end());
 
16
        assert((*o.find("parents")).second.asList().size() == 1);
 
17
        assert(*(*o.find("parents")).second.asList().begin() ==
 
18
                std::string("root"));
 
19
    }
 
20
};
 
21
 
 
22
int main(int argc, char** argv)
 
23
{
 
24
    try {
 
25
        Atlas::Objects::loadDefaults("../../../../protocols/atlas/spec/atlas.xml");
 
26
    } catch(Atlas::Objects::DefaultLoadingException e) {
 
27
        std::cout << "DefaultLoadingException: "
 
28
             << e.getDescription() << std::endl;
 
29
    }
 
30
    RootDecoder rd;
 
31
    Atlas::Objects::ObjectsEncoder re(rd);
 
32
 
 
33
    rd.streamBegin(); // important, otherwise we'll segfault!
 
34
    Atlas::Objects::Root root_inst;
 
35
    root_inst->setAttr("id", std::string("root_instantiation"));
 
36
    re.streamObjectsMessage(root_inst);
 
37
    rd.streamEnd();
 
38
}