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

dumpobj.hpp

Go to the documentation of this file.
00001 // See ../license.txt for license information.
00002 //
00003 // dumpobj.hpp
00004 //
00005 // 21-Jul-2003  phamilton  Created
00006 //
00007 
00008 #ifndef incPERSIST_DUMP_OBJECT
00009 #define incPERSIST_DUMP_OBJECT
00010 
00011 // forwards
00012 #include <iostream>
00013 #include <string>
00014 #include <map>
00015 #include "../common/persistable_object.hpp"
00016 #include "config.hpp"
00017 
00018 namespace ph {
00019 namespace persist {
00020 
00021 class PERSIST_DECL dumpobj : public ph::common::object_writer
00022 /**
00023         A concrete subclass of object_writer which dumps an object.
00024 
00025         We write the objects like this:
00026         
00027         object ::=  
00028                 object-start
00029                         sub-object-list
00030                 object-end
00031                 
00032         object-start ::=
00033                 TAGNAME ["(" attr-list ")"] "{" 
00034 
00035         object-end ::=
00036                 "}"
00037 
00038         sub-object-list ::=
00039                 (data-object | object)*
00040 
00041         data-object ::=
00042                 TAGNAME "=" data
00043                  
00044         attr-list ::= 
00045                 [attr-pair ([", " attr-pair])*]
00046                                 
00047         attr-pair ::=
00048                 name "=" value
00049                 
00050         And a typical tree might be:
00051         
00052         root(name=root)
00053         {
00054                 x=1
00055                 foos
00056                 {
00057                         foo(name=foo_1)
00058                         {
00059                                 x=1
00060                                 y=2.1
00061                                 z=true
00062                         }
00063                         foo(name=foo_2)
00064                         {
00065                           x=4
00066                           y=10
00067                           z=false
00068                         }
00069                 }
00070         }
00071 */
00072 {
00073 public:
00074         dumpobj(std::ostream *stream, std::ostream *console) :
00075                 _stream(stream), _console(console), 
00076                 _tabs(0), _tagname(""), _data("")
00077                         {};
00078         
00079         // ph::common::object_writer overrides
00080         virtual bool start(const std::string &tagname);
00081         virtual bool attr(const std::string &name, const std::string &value);
00082         virtual bool data(const std::string &d);
00083         virtual bool end(const std::string &tagname);
00084         
00085 private:
00086         std::ostream *_stream;
00087         std::ostream *_console;
00088         int           _tabs;
00089         std::string   _tagname;
00090         std::map<std::string, std::string> _attrs;
00091         std::string   _data;
00092         
00093         void object_start();
00094         void object_end();
00095         void data_object();
00096         void tabs();
00097         void cr();
00098 };
00099 
00100 }; // persist
00101 }; // ph
00102 
00103 #endif // incPERSIST_DUMP_OBJECT

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