Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

persist/test/root.cpp

Go to the documentation of this file.
00001 // See ../../license.txt for license information.
00002 //
00003 // root.cpp
00004 //
00005 // 4-Jul-2003  phamilton  Created
00006 //
00007 
00008 #include "root.hpp"
00009 #include "boost/lexical_cast.hpp"
00010 #include <boost/test/test_tools.hpp>
00011 #include "foo.hpp"
00012 #include "bar.hpp"
00013 
00014 using namespace persist_test;
00015 
00016 ph::common::object_base *root::get_composite_object(const std::string &name)
00017 {
00018         if (name == "foos")
00019                 return &foos;
00020         else if (name == "bars")
00021                 return &bars;
00022         else if (name == "a_foo")
00023                 return &a_foo;
00024         else if (name == "templates")
00025                 return &templates;
00026         else
00027                 return 0;
00028 }
00029 
00030 bool root::has(const std::string &name) const
00031 {
00032         return name == "name" || name == "type" || name == "x" || name == "foos" || 
00033                 name == "bars" || name == "a_foo" || name == "templates";
00034 }
00035 
00036 void root::set(const std::string &name, const std::string &value)
00037 {
00038         if (name == "name")
00039                 _name = value;
00040         else if (name == "type")
00041                 _type = value;
00042         else if (name == "x")
00043                 x = boost::lexical_cast<int>(value);
00044 }
00045 
00046 std::string root::get(const std::string &name) const
00047 {
00048         if (name == "name")
00049                 return _name;
00050         else if (name == "type")
00051                 return _type;
00052         else if (name == "x")
00053                 return boost::lexical_cast<std::string>(x);
00054         else
00055                 return "unknown: " + name;
00056 }
00057 
00058 bool root::write(ph::common::object_writer *writer) const
00059 {
00060         ph::common::object_writer_context c1(writer, _type);
00061         c1.attr("name", _name);
00062         {
00063                 ph::common::object_writer_context c2(writer, "x");
00064                 c2.data(boost::lexical_cast<std::string>(x));
00065         }       
00066         if (foos.vector()->size() > 0)
00067         {
00068                 ph::common::object_writer_context c2(writer, "foos");
00069                 for (std::vector<ph::common::object_base *>::const_iterator i = foos.vector()->begin(); 
00070                                 i != foos.vector()->end(); i++)
00071                         if ((*i)->persistable())
00072                                 (*i)->persistable()->write(writer);
00073         }
00074         if (bars.vector()->size() > 0)
00075         {
00076                 ph::common::object_writer_context c2(writer, "bars");
00077                 for (std::vector<ph::common::object_base *>::const_iterator i = bars.vector()->begin(); 
00078                                 i != bars.vector()->end(); i++)
00079                         if ((*i)->persistable())
00080                                 (*i)->persistable()->write(writer);
00081         }
00082         if (a_foo.obj() != 0)
00083         {
00084                 ph::common::object_writer_context c2(writer, "a_foo");
00085                 if (a_foo.obj()->persistable())
00086                         a_foo.obj()->persistable()->write(writer);
00087         }
00088         if (templates.vector()->size() > 0)
00089         {
00090                 ph::common::object_writer_context c2(writer, "templates");
00091                 for (std::vector<ph::common::object_base *>::const_iterator i = templates.vector()->begin(); 
00092                                 i != templates.vector()->end(); i++)
00093                         if ((*i)->persistable())
00094                                 (*i)->persistable()->write(writer);
00095         }
00096         
00097         return true;
00098 }

Generated on Wed Apr 5 22:03:26 2006 for cppxmlobj by  doxygen 1.4.3