Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbBdbObjectVisitorContext.hh

Go to the documentation of this file.
00001 #ifndef CDBBDB_OBJECT_VISITOR_CONTEXT_HH
00002 #define CDBBDB_OBJECT_VISITOR_CONTEXT_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbObjectVisitorContext.hh,v 1.2 2004/10/21 20:35:50 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <oo.h>     // ooRef(ooObj), ooHandle(ooObj)
00010 
00011 #include <string>
00012 #include <vector>
00013 
00014 /// The current context of the objects visitor procedure
00015 /**
00016   * An object of this class is prepared by the visitor procedure and then
00017   * is passed down to the user defined action method alongside with an
00018   * objects to be evaluated in the current context.
00019   * 
00020   * IMPLEMENTATION NOTES:
00021   *
00022   *   (1) This class violates CDB API convention on the inclusion
00023   *       of "CdbBase/CdbCommon.hh" header file to avoid STD namespace
00024   *       conflicts of the kind described above.
00025   */
00026 class CdbBdbObjectVisitorContext {
00027 
00028 public:
00029 
00030   /// An internal elmnet of the contex
00031  /**
00032    * More details...
00033    */
00034     class Element {
00035 
00036     public:
00037 
00038       /// A kind of an element
00039       /**
00040         * These values determine the semantics and usability of other data
00041         * members of particular elements.
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       /// Default constructor (NOT IMPLEMENTED)
00055 
00056       /// Universal constructor
00057       /**
00058         * This constructor is only meant to be used by 'virtual' c-tors defined below.
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       // 'Virtual' c-tors
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       /// Copy constructor
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       /// Assignment operator
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       // Accessors
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   /// The default constructor
00200   /**
00201     * Initializes an empty context
00202     */
00203     CdbBdbObjectVisitorContext( );
00204 
00205   /// The destructor
00206   /**
00207     * Moe details...
00208     */
00209     virtual ~CdbBdbObjectVisitorContext( );
00210 
00211   /// Reset the context to its initial state
00212 
00213     void reset( );
00214 
00215   /// Append ne more element at the end
00216 
00217     void push( const Element& theElement );
00218 
00219   /// Remove the last element (if any) from the very end
00220 
00221     void pop( );
00222 
00223   /// Get to the first element
00224 
00225     const Element& first( ) const;
00226 
00227   /// Get to the last element
00228 
00229     const Element& last( ) const;
00230 
00231   /// Get the total number of elements
00232 
00233     size_t size( ) const;
00234 
00235   /// Access elements using the array kind manner
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

Generated on Mon Dec 5 18:22:00 2005 for CDB by doxygen1.3-rc3