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

CdbBdbSBtreeP.ddl

Go to the documentation of this file.
00001 #ifndef CDBBDBSHARED_BTREE_P_HH
00002 #define CDBBDBSHARED_BTREE_P_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbSBtreeP.ddl,v 1.7 2004/03/24 07:09:30 gapon Exp $
00006 
00007 #include "BdbUtil/Bdb.hh"
00008 
00009 #include "CdbBdbShared/CdbBdbSAbsBtree.hh"
00010 #include "CdbBdbShared/CdbBdbSPagedVarrayP.hh"
00011 
00012 /// This is a persistent implementation for of a B-tree.
00013 /**
00014   */
00015 template< class K,
00016           class FCP   = CdbBdbSBtreeDefaultFCP<K>,
00017           class ORDER = CdbBdbSBtreeDefaultOrder >
00018 class CdbBdbSBtreeP : public BdbPersObj,
00019                       public CdbBdbSAbsBtree<K,FCP,ORDER> {
00020 
00021 private:
00022 
00023   /// Node definition
00024   /**
00025     * The only reason to have this definition is to avoid DDL compilation problem
00026     * for the following definitions:
00027     *
00028     *     ooRef( template_class< another_template_class< ... > > )
00029     */
00030     typedef CdbBdbSPagedVarrayP< CdbBdbSBtreeNode<K,ORDER> > PagedVarrayOfNodeP;
00031 
00032 public:
00033 
00034   // Constructors
00035 
00036     CdbBdbSBtreeP( );
00037 
00038   // Destructor
00039 
00040     virtual ~CdbBdbSBtreeP( );
00041 
00042 protected:
00043 
00044   /// Get a root node of the B-tree
00045   /**
00046     * Implements the corresponding method of the base class.
00047     *
00048     * @see CdbBdbSAbsBtree::root()
00049     */
00050     virtual d_ULong root( ) const;
00051 
00052   /// Set new root node of the B-tree
00053   /**
00054     * Implements the corresponding method of the base class.
00055     *
00056     * @see CdbBdbSAbsBtree::root()
00057     */
00058     virtual void set_root( d_ULong node );
00059 
00060   /// Get a copy of specified node
00061   /**
00062     * Implements the corresponding method of the base class.
00063     *
00064     * @see CdbBdbSAbsBtree::readNode()
00065     */
00066     virtual CdbBdbSBtreeNode<K,ORDER> readNode( d_ULong node ) const;
00067 
00068   /// Save back the value of specified node
00069   /**
00070     * Implements the corresponding method of the base class.
00071     *
00072     * @see CdbBdbSAbsBtree::updateNode()
00073     */
00074     virtual void updateNode( d_ULong                          node,
00075                              const CdbBdbSBtreeNode<K,ORDER>& value );
00076 
00077   /// Allocator
00078   /**
00079     * Implements the corresponding method of the base class.
00080     *
00081     * @see CdbBdbSAbsBtree::root()
00082     */
00083     virtual d_ULong allocate( d_ULong parent = 0 );
00084 
00085   /// Disposer
00086   /**
00087     * Implements the corresponding method of the base class.
00088     *
00089     * @see CdbBdbSAbsBtree::root()
00090     */
00091     virtual void release( d_ULong node );
00092 
00093 private:
00094 
00095   /// This is in fact a normal/default constructor for specified node.
00096   /**
00097     * By default the node does not have a parent.
00098     */
00099     void init_node( d_ULong node,
00100                     d_ULong parent );
00101 
00102   /// Extend a list of free nodes
00103   /**
00104     * This list is only extended if it's empty.
00105     */
00106     void extend_free_list( );
00107 
00108 private:
00109 
00110   /// The actual storage.
00111   /**
00112     * The first element of the array (index = 0) is not used, because
00113     * this number is meant to simulate "null pointer".
00114     *
00115     * The second element (index = 1) is used as a default root node.
00116     * This will change as the tree will expand.
00117     *
00118     * Initially spare elements begin from the index = 2.
00119     * This will also change as the tree will expand.
00120     *
00121     * NOTE: The use of "OO_COMMA" instead of regual comma symbol. This is due to
00122     *       the way the BdbRef/ooRef macros get expanded. See Objectivity/DB DDL
00123     *       manual (page 47) for details.
00124     */
00125     BdbRef( PagedVarrayOfNodeP ) _bufRef;
00126 
00127   /// An index of the root node
00128 
00129     d_ULong _root;
00130 
00131   /// An index of the first spare node
00132   /**
00133     * These nodes form a linked list. So the first spare node is actually
00134     * the head of the list.
00135     */
00136     d_ULong _free;
00137 };
00138 
00139 // Explicit template instantiation for B-Trees of primitive types of elements
00140 //
00141 // NOTE: The sebsequent definitions assume that the corresponding definitions
00142 //       have already been made for Paged V-Array.
00143 
00144 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_1_NOPVARRAY( T ) \
00145 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( CdbBdbSBtreeNode< T > ); \
00146 template class CdbBdbSBtreeP< T >
00147 
00148 /// Macros for the explicit template instantiation of non-trivial types.
00149 /**
00150   * The macro will provide all the nessesary declarations for specified
00151   * type of elements (first paremeter). It will also introduce new type
00152   * as required by the second parameter.
00153   *
00154   * NOTE: Pay attention to the primitive types to avoid declaring them
00155   *       more than once.
00156   */
00157 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_1( T ) \
00158 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( T ); \
00159 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( CdbBdbSBtreeNode< T > ); \
00160 template class CdbBdbSBtreeP< T >
00161 
00162 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_2( T1 , T2 ) \
00163 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_2( T1 , T2 ); \
00164 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_2( CdbBdbSBtreeNode< T1 , T2 > ); \
00165 template class CdbBdbSBtreeP              < T1 , T2 >
00166 
00167 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_3( T1 , T2 , T3 ) \
00168 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_3( T1 , T2 , T3 ); \
00169 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_3( CdbBdbSBtreeNode< T1 , T2 , T3 > ); \
00170 template class CdbBdbSBtreeP              < T1 , T2 , T3 >
00171 
00172 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_1_FCP_1( T , FCP ) \
00173 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( T ); \
00174 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_1( CdbBdbSBtreeNode< T > ); \
00175 template class CdbBdbSBtreeP              < T , FCP >
00176 
00177 #define EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_2_FCP_2( T1 , T2 , FCP1 , FCP2 ) \
00178 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_2( T1 , T2 ); \
00179 EXPLICIT_INSTANTIATE_CdbBdbSPagedVarrayP_2( CdbBdbSBtreeNode< T1 , T2 > ); \
00180 template class CdbBdbSBtreeP              < T1 , T2 , FCP1 , FCP2 >
00181 
00182 // Template class implementation
00183 
00184 #ifdef    BABAR_COMP_INST
00185 #include "CdbBdbShared/CdbBdbSBtreeP.cc"
00186 #endif /* BABAR_COMP_INST */
00187 
00188 #endif /* CDBBDBSHARED_BTREE_P_HH */

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