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

object_visitor.hpp

Go to the documentation of this file.
00001 // See ../license.txt for license information.
00002 //
00003 // object_visitor.hpp
00004 //
00005 // 4-Jul-2003  phamilton  Created
00006 //
00007 
00008 #ifndef incREFLECT_OBJECT_VISITOR
00009 #define incREFLECT_OBJECT_VISITOR
00010 
00011 // forwards
00012 #include <vector>
00013 #include <string>
00014 #include "../common/object.hpp"
00015 #include "../common/visitable_object.hpp"
00016 #include "config.hpp"
00017 
00018 namespace ph {
00019 namespace reflect {
00020 
00021 class REFLECT_DECL get_composite_object_visitor : public ph::common::object_name_visitor
00022 /**
00023         Concrete subclass of object_visitor used to dump the value of a member.
00024 */
00025 {
00026 public:
00027         get_composite_object_visitor(const std::string &name) :
00028                 _name(name), _obj(0)
00029                         {};
00030                         
00031         ph::common::object_base *obj() { return _obj; }
00032         
00033         // const_object_visitor ovverides.
00034         virtual bool visit(const ph::common::object_base *obj, const ph::common::nameable_object_base *name)
00035                 { return true; }
00036         virtual bool visit_composite(const ph::common::object_base *obj, const ph::common::nameable_object_base *name);
00037         
00038 private:
00039         std::string _name;
00040         ph::common::object_base *_obj;
00041 };
00042 
00043 class REFLECT_DECL get_object_visitor : public ph::common::object_name_visitor
00044 /**
00045         Concrete subclass of object_visitor used to search for an object given the name.
00046 */
00047 {
00048 public:
00049         get_object_visitor(const std::string &name, bool recurse=false) :
00050                 _name(name), _recurse(recurse), _obj(0)
00051                         {};
00052                         
00053         ph::common::object_base *obj() { return _obj; }
00054         
00055         // const_object_visitor ovverides.
00056         virtual bool recurse() { return _recurse; }
00057         virtual bool visit(const ph::common::object_base *obj, const ph::common::nameable_object_base *name);
00058         virtual bool visit_composite(const ph::common::object_base *obj, const ph::common::nameable_object_base *name)
00059                 { return true; }
00060         
00061 private:
00062         std::string _name;
00063         bool        _recurse;
00064         ph::common::object_base *_obj;
00065 };
00066 
00067 class REFLECT_DECL get_object_with_type_visitor : public ph::common::object_name_visitor
00068 /**
00069         Concrete subclass of object_visitor used to search for an object given the name
00070         and type.
00071 */
00072 {
00073 public:
00074         get_object_with_type_visitor(const std::string &type, 
00075                 const std::string &name, bool recurse=false) :
00076                 _type(type), _name(name), _recurse(recurse), _obj(0)
00077                         {};
00078                         
00079         ph::common::object_base *obj() { return _obj; }
00080         
00081         // const_object_visitor ovverides.
00082         virtual bool recurse() { return _recurse; }
00083         virtual bool visit(const ph::common::object_base *obj, const ph::common::nameable_object_base *name);
00084         virtual bool visit_composite(const ph::common::object_base *obj, const ph::common::nameable_object_base *name)
00085                 { return true; }
00086         
00087 private:
00088         std::string _type;
00089         std::string _name;
00090         bool        _recurse;
00091         ph::common::object_base *_obj;
00092 };
00093 
00094 class REFLECT_DECL get_nth_object_visitor : public ph::common::object_name_visitor
00095 /**
00096         Concrete subclass of object_visitor used to dump the value of a member.
00097         
00098         This visitor is 0 based.
00099 */
00100 {
00101 public:
00102         get_nth_object_visitor(long index) :
00103                 _index(index), _obj(0)
00104                         {};
00105                         
00106         ph::common::object_base *obj() { return _obj; }
00107         
00108         // const_object_visitor ovverides.
00109         virtual bool visit(const ph::common::object_base *obj, const ph::common::nameable_object_base *name);
00110         virtual bool visit_composite(const ph::common::object_base *obj, const ph::common::nameable_object_base *name)
00111                 { return true; }
00112         
00113 private:
00114         int _index;
00115         ph::common::object_base *_obj;
00116 };
00117 
00118 class REFLECT_DECL dump_object_visitor : public ph::common::const_object_visitor
00119 /**
00120         Concrete subclass of object_visitor used to dump the value of a member.
00121 */
00122 {
00123 public:
00124         dump_object_visitor(std::ostream *stream, bool debug=false) :
00125                 _stream(stream), _debug(debug), _indent(0)
00126                         {};
00127         ~dump_object_visitor();
00128                 
00129         // object_visitor ovverides.
00130         virtual bool recurse() { return true; }
00131         virtual bool visit(const ph::common::object_base *obj);
00132         virtual bool visit_composite(const ph::common::object_base *obj);
00133         
00134 private:
00135         std::ostream              *_stream;
00136         bool                       _debug;
00137         int                        _indent;
00138         std::vector<const ph::common::object_base *> _stack;
00139 
00140         void calc_indent(const ph::common::object_base *obj);
00141         void indent();
00142         void close_stack();
00143         void obj_out(const std::string &msg, const ph::common::object_base *obj);
00144 };
00145 
00146 }; // reflect
00147 }; // ph
00148 
00149 #endif // incREFLECT_OBJECT_VISITOR

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