00001 #ifndef CDBBDBSHARED_COLLECTION_P_HH 00002 #define CDBBDBSHARED_COLLECTION_P_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdbSCollectionP.ddl,v 1.9 2004/08/06 05:54:24 bartoldu Exp $ 00006 00007 #include "BdbUtil/Bdb.hh" 00008 #include "ooMap.h" 00009 00010 #include "CdbBdbShared/CdbBdbSBtreeP.hh" 00011 #include "CdbBdbShared/CdbBdbSCollectionBte.hh" 00012 #include "CdbBdbShared/CdbBdbSCollectionElementP.hh" 00013 00014 #include <iostream> 00015 00016 //------------------------------------------------------------------ 00017 // Explicit template instantiatin for the persistent B-tree class -- 00018 //------------------------------------------------------------------ 00019 00020 EXPLICIT_INSTANTIATE_CdbBdbSBtreeP_1( CdbBdbSCollectionBte ); 00021 00022 /// Persistent collection class 00023 /** 00024 * This class represents persistent 00025 * "collection" of objects each having an identifier and/or a name 00026 * in the scope of the collection. 00027 * 00028 * Elements stored in the collection must be of 00029 * the "CdbBdbSCollectionElementP" class or derive from it. 00030 * 00031 * This collection is "unique" in respect to the values of the 00032 * keys (names and identifiers) of stored elements. 00033 * 00034 * The constructor allows to decide of either or both keys (name and 00035 * identifier) of the stored elements are used. At least one key is expected. 00036 */ 00037 class CdbBdbSCollectionP : public BdbPersObj { 00038 00039 public: 00040 00041 /// Type definitions for the collection's iterators 00042 /** 00043 * These types are being introduced here to facilitate more flexible 00044 * type parametrisation of the collection's clients (including its 00045 * direct and indirect subclasses). 00046 */ 00047 typedef CdbItr< const char* > IteratorOfNames; 00048 typedef CdbItr< d_UShort > IteratorOfIdentifiers; 00049 00050 /// B-tree and its entries types definition 00051 /** 00052 * The only reason to have this definition is to avoid DDL compilation problem 00053 * for the following definitions: 00054 * 00055 * ooRef( template_class< another_template_class< ... > > ) 00056 * 00057 * NOTE: That each specialization of the B-tree has to be explicitly 00058 * instantiated by a user of this class for concrete values of 00059 * of the d_UShort. 00060 */ 00061 typedef CdbBdbSCollectionBte BTreeEntry; 00062 typedef CdbBdbSBtreeP< BTreeEntry > BTreeP; 00063 00064 public: 00065 00066 /// Default & normal constructor 00067 /** 00068 * Initializes an empty collection. It's _REQUIRED_ that 00069 * at least one of the flags passed as parameters must be true. 00070 */ 00071 CdbBdbSCollectionP( bool useIdFlag = true, /**< tells the collection to use elements identifiers */ 00072 bool useNameFlag = true /**< tells the collection to use elements names */ 00073 ); 00074 00075 /// Destructor 00076 /** 00077 * Will also destroy all the elements. 00078 */ 00079 virtual ~CdbBdbSCollectionP( ); 00080 00081 /// Check if elements identifiers are used to sort elements in the collection. 00082 00083 bool useId( ) const; 00084 00085 /// Check if elements names are used to sort elements in the collection. 00086 00087 bool useName( ) const; 00088 00089 /// get the number of elements 00090 00091 d_ULong elements( ) const; 00092 00093 /// Insert an element 00094 /** 00095 * Both the element's name and its identifier are obtained from the element. 00096 * They both must be unique in the collection's scope. 00097 * 00098 * The collections taks over the ownership of the stored elements. 00099 */ 00100 virtual CdbStatus insert( const BdbRef( CdbBdbSCollectionElementP )& theRef /**< the object to insert */ 00101 ); 00102 00103 /// Find an object by its name 00104 /** 00105 * This method does not return the element's ownership 00106 * 00107 * The method will return CdbStatus::NotFound if the object was not 00108 * found in the folder. Other possible completion statuses are as usual. 00109 */ 00110 virtual CdbStatus find( const char* theName, /**< the object's name in the collection's scope */ 00111 BdbRef( CdbBdbSCollectionElementP )& theRef /**< the reference to be initialized upon successfull completion */ 00112 ) const; 00113 00114 /// Find an object by its identifier 00115 /** 00116 * The method will return CdbStatus::NotFound if the condition was not 00117 * found in the folder. Other possible completion statuses are as usual. 00118 */ 00119 virtual CdbStatus find( d_UShort theId, /**< the object's identifier */ 00120 BdbRef( CdbBdbSCollectionElementP )& theRef /**< the reference to be initialized upon successfull completion */ 00121 ) const; 00122 00123 /// Remove an element by its name 00124 /** 00125 * The found element will be also destroyed. 00126 * 00127 * The method will return CdbStatus::NotFound if the object was not 00128 * found in the folder. Other possible completion statuses are as usual. 00129 */ 00130 virtual CdbStatus remove( const char* theName /**< the object's name in the collection's scope */ 00131 ); 00132 00133 /// Remove an element by its name 00134 /** 00135 * The found element will be also destroyed. 00136 * 00137 * The method will return CdbStatus::NotFound if the object was not 00138 * found in the folder. Other possible completion statuses are as usual. 00139 */ 00140 virtual CdbStatus remove( d_UShort theId /**< the object's identifier */ 00141 ); 00142 00143 /// Get an instance of an iterator for names 00144 /** 00145 * This kind of iterator provides "non-sorted" access to the keys. 00146 */ 00147 IteratorOfNames iterator_names( ) const; 00148 00149 /// Get an instance of an iterator for identifiers 00150 /** 00151 * This kind of iterator provides "non-sorted" access to the keys. 00152 */ 00153 IteratorOfIdentifiers iterator_identifiers( ) const; 00154 00155 /// Dump the contents of the collection 00156 /** 00157 */ 00158 virtual void dump( std::ostream& o ) const; 00159 00160 private: 00161 00162 /// General verification for the passed element 00163 /** 00164 * Every input to the collection element passes this verification. 00165 */ 00166 bool verifyElement( const BdbRef( CdbBdbSCollectionElementP )& theRef ) const; 00167 00168 private: 00169 00170 /** 00171 * NOTE: Don't forget about proper template instantiation for the concrete template 00172 * parameters of the B-tree. 00173 */ 00174 BdbRef( BTreeP ) _treeRef; 00175 00176 /// The (oo-)Map will store elements by their names 00177 00178 BdbRef( BdbMap ) _mapRef; 00179 00180 /// Total number of elements in the collection 00181 00182 d_ULong _elements; 00183 }; 00184 00185 #endif /* CDBBDBSHARED_COLLECTION_P_HH */
1.3-rc3