00001 #ifndef CDBBDB_OBJECT_VISITOR_CONTEXT_HH
00002 #define CDBBDB_OBJECT_VISITOR_CONTEXT_HH
00003
00004
00005
00006
00007 #include "CdbBase/CdbCommon.hh"
00008
00009 #include <oo.h>
00010
00011 #include <string>
00012 #include <vector>
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 class CdbBdbObjectVisitorContext {
00027
00028 public:
00029
00030
00031
00032
00033
00034 class Element {
00035
00036 public:
00037
00038
00039
00040
00041
00042
00043 typedef enum { OBJECT,
00044 BASE_CLASS,
00045 EMBEDDED_OBJECT,
00046 MAP_ELEMENT,
00047 REFERENCE,
00048 MANY_RELATIONSHIP,
00049 ONE_RELATIONSHIP
00050 } Type;
00051
00052 private:
00053
00054
00055
00056
00057
00058
00059
00060 Element( Type theType,
00061 const ooRef(ooObj)& theRef,
00062 const char* theName,
00063 const char* theName_2,
00064 size_t theIndex ) :
00065 _type (theType),
00066 _ref (theRef),
00067 _name (theName),
00068 _name_2(theName_2),
00069 _index (theIndex)
00070 { }
00071
00072 public:
00073
00074
00075
00076 static Element createObject( const ooRef(ooObj)& theRef,
00077 const char* theClassName )
00078 {
00079 return Element( OBJECT,
00080 theRef,
00081 theClassName,
00082 "",
00083 0 );
00084 }
00085 static Element createBaseClass( const char* theClassName )
00086 {
00087 return Element( BASE_CLASS,
00088 0,
00089 theClassName,
00090 "",
00091 0 );
00092 }
00093 static Element createEmbeddedObject( const char* theClassName,
00094 const char* theName,
00095 size_t theIndex = 0 )
00096 {
00097 return Element( EMBEDDED_OBJECT,
00098 0,
00099 theClassName,
00100 theName,
00101 theIndex );
00102 }
00103 static Element createMapElement( const char* theKeyName )
00104 {
00105 return Element( MAP_ELEMENT,
00106 0,
00107 theKeyName,
00108 "",
00109 0 );
00110 }
00111 static Element createReference( const char* theName,
00112 size_t theIndex = 0 )
00113 {
00114 return Element( REFERENCE,
00115 0,
00116 theName,
00117 "",
00118 theIndex );
00119 }
00120 static Element createManyRelationship( const char* theName )
00121 {
00122 return Element( MANY_RELATIONSHIP,
00123 0,
00124 theName,
00125 "",
00126 0 );
00127 }
00128 static Element createOneRelationship( const char* theName )
00129 {
00130 return Element( ONE_RELATIONSHIP,
00131 0,
00132 theName,
00133 "",
00134 0 );
00135 }
00136
00137
00138
00139 Element( const Element& theOther ) :
00140 _type (theOther._type),
00141 _ref (theOther._ref),
00142 _name (theOther._name),
00143 _name_2(theOther._name_2),
00144 _index (theOther._index)
00145 { }
00146
00147
00148
00149 Element& operator=( const Element& theOther )
00150 {
00151 if( &theOther != this ) {
00152 _type = theOther._type;
00153 _ref = theOther._ref;
00154 _name = theOther._name;
00155 _name_2 = theOther._name_2;
00156 _index = theOther._index;
00157 }
00158 return *this;
00159 }
00160
00161
00162
00163 Type type( ) const
00164 {
00165 return _type;
00166 }
00167
00168 const ooRef(ooObj)& ref( ) const
00169 {
00170 return _ref;
00171 }
00172
00173 const std::string& name( ) const
00174 {
00175 return _name;
00176 }
00177
00178 const std::string& name_2( ) const
00179 {
00180 return _name_2;
00181 }
00182
00183 size_t index( ) const
00184 {
00185 return _index;
00186 }
00187
00188 private:
00189
00190 Type _type;
00191 ooRef(ooObj) _ref;
00192 std::string _name;
00193 std::string _name_2;
00194 size_t _index;
00195 };
00196
00197 public:
00198
00199
00200
00201
00202
00203 CdbBdbObjectVisitorContext( );
00204
00205
00206
00207
00208
00209 virtual ~CdbBdbObjectVisitorContext( );
00210
00211
00212
00213 void reset( );
00214
00215
00216
00217 void push( const Element& theElement );
00218
00219
00220
00221 void pop( );
00222
00223
00224
00225 const Element& first( ) const;
00226
00227
00228
00229 const Element& last( ) const;
00230
00231
00232
00233 size_t size( ) const;
00234
00235
00236
00237 const Element& operator[]( size_t theIndex ) const;
00238
00239 private:
00240
00241 std::vector<Element> _elements;
00242 };
00243
00244 #endif // CDBBDB_OBJECT_VISITOR_CONTEXT_HH