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

CdbBdbObjectVisitorImpl.hh

Go to the documentation of this file.
00001 #ifndef CDBBDB_OBJECT_VISITOR_IMPL_HH
00002 #define CDBBDB_OBJECT_VISITOR_IMPL_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbObjectVisitorImpl.hh,v 1.2 2004/10/21 20:35:51 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <string>
00010 
00011 #include <oo.h>         // Objectivity/DB core API
00012 #include <ooas.h>       // Objectivity/DB Active Schema API
00013 
00014 // Forward declarations
00015 
00016 class CdbBdbObjectVisitorUserAction;
00017 class CdbBdbObjectVisitorContext;
00018 
00019 template< class T > class CdbBdbCache;
00020 
00021 /// This class implements the "object visiting" facility for a graph of persistent objects.
00022 /**
00023   * More details...
00024   */
00025 class CdbBdbObjectVisitorImpl {
00026 
00027     friend class CdbBdbObjectVisitor;     // who is able to create and destroy me
00028 
00029 private:
00030 
00031   /// Default constructor (NOT IMPLEMENTED)
00032   /**
00033     * Implements the contract of the corresponding method of the facade class.
00034     *
00035     * @see CdbBdbObjectVisitor::CdbBdbObjectVisitor()
00036     */
00037     CdbBdbObjectVisitorImpl( );
00038 
00039   /// Normal constructor
00040   /**
00041     * Implements the contract of the corresponding method of the facade class.
00042     *
00043     * @see CdbBdbObjectVisitor::CdbBdbObjectVisitor()
00044     */
00045     CdbBdbObjectVisitorImpl( CdbBdbObjectVisitorUserAction* theUserAction,
00046                                                        bool verboseMode,
00047                                                        bool debugMode );
00048 
00049   /// Destructor
00050   /**
00051     * Implements the contract of the corresponding method of the facade class.
00052     *
00053     * @see CdbBdbObjectVisitor::~CdbBdbObjectVisitor()
00054     */
00055     virtual ~CdbBdbObjectVisitorImpl( );
00056 
00057   /// Visit the specified object
00058   /**
00059     * Implements the contract of the corresponding method of the facade class.
00060     *
00061     * @see CdbBdbObjectVisitor::visit()
00062     */
00063     virtual bool visit( const ooHandle(ooObj)& theInputH );
00064 
00065   /// Set user action
00066   /**
00067     * Implements the contract of the corresponding method of the facade class.
00068     *
00069     * @see CdbBdbObjectVisitor::setUserAction()
00070     */
00071     CdbBdbObjectVisitorUserAction* setUserAction( CdbBdbObjectVisitorUserAction* theUserAction );
00072 
00073 private:
00074 
00075     /// An automatic prefix class
00076     /**
00077       * This internal helper class is meant to help with forming a proper prefix
00078       * string depending on the current "level" in a visited graph.
00079       */
00080     class Prefix {
00081 
00082     private:
00083 
00084       /// Default constructor (NOT IMPLEMENTED)
00085       /**
00086         * The object's default does not make any sense at all.
00087         */
00088         Prefix( );
00089 
00090       /// Copy constructor (NOT IMPLEMENTED)
00091       /**
00092         * Copying of these objects does not make any sense at all.
00093         */
00094         Prefix( const Prefix& );
00095 
00096       /// Assignment operator (NOT IMPLEMENTED)
00097       /**
00098         * Copying of these objects does not make any sense at all.
00099         */
00100         Prefix& operator=( const Prefix& );
00101 
00102     public:
00103 
00104       /// Normal constructor
00105       /**
00106         * Decrement the current level at the caller's context.
00107         * Set up the current prefix string at the current context.
00108         */
00109         Prefix(               int& theLevel,        /**< a reference onto the caller's context */
00110                 const std::string& theStep = "  "   /**< the step between levels */
00111               );
00112 
00113       /// Destructor
00114       /**
00115         * Decrement the current level at the caller's context.
00116         */
00117         ~Prefix( );
00118 
00119       /// An explicit type conversion operator
00120       /**
00121         * Will return a pointer onto the current prefix string.
00122         *
00123         * NONE: The returned string is bound to the local object's context.
00124         */
00125         const char* c_str( ) const;
00126 
00127     private:
00128 
00129                int& _level;   // a reference onto the caller's context
00130         std::string _str;     // the current prefix
00131     };
00132 
00133   // Helper methods
00134 
00135     bool visitObject( const ooHandle(ooObj)& theH );
00136 
00137     bool visitObjectContents( const ooas::Class_Object& theClassObject,
00138                                           const Prefix& thePrefix );
00139 
00140 private:
00141 
00142   // Current context
00143 
00144     bool _verboseMode;
00145     bool   _debugMode;
00146 
00147     CdbBdbObjectVisitorUserAction* _userAction;
00148 
00149   // A set to mark OID-s of input objects which were already visited.
00150   // The set is used for the following reasons:
00151   //
00152   // - to avoid visiting objects which have already been visited
00153   // - to escape from the cyclic graph problem
00154 
00155     CdbBdbCache< ooRef(ooObj) >* _dictionary;
00156 
00157   // The context object to be passed down to the user defined action
00158 
00159     CdbBdbObjectVisitorContext* _context;
00160 
00161   // Supplementary data structures
00162 
00163     int _level;     // the current level in a visited graph (begins with 0 for the initial object)
00164 };
00165 
00166 #endif  // CDBBDB_OBJECT_VISITOR_IMPL_HH

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