![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbTrees/BdbGenericHdrT.cc
Go to the documentation of this file.00001 #if !defined(BDBGENERICHDRT_CC) 00002 #define BDBGENERICHDRT_CC 00003 //-------------------------------------------------------------------------- 00004 // File and Version Information: 00005 // $Id: BdbGenericHdrT.cc,v 1.12 2002/06/10 23:29:32 becla Exp $ 00006 // 00007 // Description: 00008 // Class BdbGenericHdrT 00009 // 00010 // Environment: 00011 // Software developed for the BaBar Detector at the SLAC B-Factory. 00012 // 00013 // Author List: 00014 // Simon Patton Originator 00015 // 00016 // Copyright Information: 00017 // Copyright (C) 1999 LBNL 00018 // 00019 //------------------------------------------------------------------------ 00020 00021 //----------------------- 00022 // This Class's Header -- 00023 //----------------------- 00024 #include "BdbTrees/BdbGenericHdrT.hh" 00025 00026 //------------- 00027 // C Headers -- 00028 //------------- 00029 extern "C" { 00030 #include <assert.h> 00031 } 00032 00033 //--------------- 00034 // C++ Headers -- 00035 //--------------- 00036 00037 //---------------- 00038 // BaBar Header -- 00039 //---------------- 00040 #include "BaBar/BaBar.hh" 00041 00042 //------------------------------- 00043 // Collaborating Class Headers -- 00044 //------------------------------- 00045 #include "BdbTrees/BdbTypeAndString.hh" 00046 #include "BdbTrees/BdbGenericHdr.hh" 00047 #include "BdbTrees/BdbGenericMutualHdr.hh" 00048 00049 //------------------------------------ 00050 // Collaborating Class Declarations -- 00051 //------------------------------------ 00052 00053 //----------------------------------------------------------------------- 00054 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00055 //----------------------------------------------------------------------- 00056 00057 // ----------------------------------------------- 00058 // -- Static Data & Function Member Definitions -- 00059 // ----------------------------------------------- 00060 00061 // --------------------------------- 00062 // -- Member Function Definitions -- 00063 // --------------------------------- 00064 00065 //---------------- 00066 // Constructors -- 00067 //---------------- 00068 00069 BdbGenericHdrT::BdbGenericHdrT( BdbRef( BdbGenericHdr )& header ) 00070 : _bdbRef( header ) 00071 { 00072 } 00073 00074 BdbGenericHdrT::BdbGenericHdrT( BdbHandle( BdbGenericHdr )& header ) 00075 : _bdbRef( header ) 00076 { 00077 } 00078 00079 BdbGenericHdrT::BdbGenericHdrT( const BdbGenericHdrT& aRhs ) 00080 : _bdbRef( aRhs._bdbRef ) 00081 { 00082 } 00083 00084 // BdbGenericHdrT::BdbGenericHdrT( const BdbGenericHdrT& aRhs ) 00085 // { 00086 // } 00087 00088 const BdbGenericHdrT& 00089 BdbGenericHdrT::operator=( const BdbRef( BdbGenericHdr )& p ) 00090 { 00091 _bdbRef = p; 00092 return *this; 00093 } 00094 00095 const BdbGenericHdrT& 00096 BdbGenericHdrT::operator=( const BdbHandle( BdbGenericHdr )& p ) 00097 { 00098 _bdbRef = p; 00099 return *this; 00100 } 00101 00102 //-------------- 00103 // Destructor -- 00104 //-------------- 00105 00106 BdbGenericHdrT::~BdbGenericHdrT() 00107 { 00108 } 00109 00110 00111 //------------- 00112 // Operators -- 00113 //------------- 00114 00115 // const BdbGenericHdrT& BdbGenericHdrT::operator=( const BdbGenericHdrT& aRhs ) 00116 // { 00117 // } 00118 00119 //------------- 00120 // Selectors -- 00121 //------------- 00122 00123 d_Boolean 00124 BdbGenericHdrT::isNull() const 00125 { 00126 return( _bdbRef.isNull() ) ; 00127 } 00128 00129 const BdbRefAny& 00130 BdbGenericHdrT::getPersistent() const 00131 { 00132 assert( ! isNull() ) ; 00133 return( _bdbRef ) ; 00134 } 00135 00136 const BdbHandle( BdbGenericHdr ) 00137 BdbGenericHdrT::getHandle() const 00138 { 00139 return( (BdbRef( BdbGenericHdr ))(getPersistent()) ) ; 00140 } 00141 00142 size_t 00143 BdbGenericHdrT::getPersObjs( BdbRefAny*& list ) const 00144 { 00145 // If new style BdbGenericMutualHdr then run recast and use 00146 // correct access 00147 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00148 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->getPersObjs( list ) ) ; 00149 } 00150 00151 // Otherwise assume old style BdbGenericHeader 00152 return( getHandle()->getPersObjs( list ) ) ; 00153 } 00154 00155 size_t 00156 BdbGenericHdrT::getKeys( const char**& resultantKeys ) const 00157 { 00158 // If new style BdbGenericMutualHdr then run recast and use 00159 // correct access 00160 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00161 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->getKeys( resultantKeys ) ) ; 00162 } 00163 00164 // Otherwise assume old style BdbGenericHeader 00165 return( getHandle()->getKeys( resultantKeys ) ) ; 00166 } 00167 00168 size_t 00169 BdbGenericHdrT::getTypeAndStrings( const BdbTypeAndString*& typeAndStrings) const 00170 { 00171 // If new style BdbGenericMutualHdr then run recast and use 00172 // correct access 00173 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00174 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->getTypeAndStrings( typeAndStrings ) ) ; 00175 } 00176 00177 // Otherwise assume old style BdbGenericHeader 00178 return( getHandle()->getTypeAndStrings( typeAndStrings ) ) ; 00179 } 00180 00181 bool 00182 BdbGenericHdrT::ownedBy( const BdbRefAny& owner ) const 00183 { 00184 // If new style BdbGenericMutualHdr then run recast and use 00185 // correct access 00186 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00187 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->ownedBy( owner ) ) ; 00188 } 00189 00190 // Otherwise assume old style BdbGenericHeader 00191 BdbHandle( BdbPersObj ) ownerH( owner ) ; 00192 return( getHandle()->isOwner( ownerH ) ) ; 00193 } 00194 00195 BdbStatus 00196 BdbGenericHdrT::get( BdbRefAny& object , 00197 ooTypeNumber typeNum, 00198 const char* const key ) const 00199 { 00200 // If new style BdbGenericMutualHdr then run recast and use 00201 // correct access 00202 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00203 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->get( object , 00204 typeNum , 00205 key ) ) ; 00206 } 00207 00208 // Otherwise assume old style BdbGenericHeader 00209 return( getHandle()->get( object , 00210 typeNum , 00211 key ) ) ; 00212 } 00213 00214 bool 00215 BdbGenericHdrT::canBeGenericHdrT( ooTypeNumber typeN ) const 00216 { 00217 // Until we are able to use dynamic schema access this routine is 00218 // ugly as the type number are hardwired. The reason for this is 00219 // that we do not want to use the object and 'ooIsKindOf' as that 00220 // requires access to the object which may not be available. 00221 switch( typeN ) { 00222 case( 1000024 ) : // BdbGenericHdr 00223 case( 1000025 ) : // BdbTreeHdr 00224 case( 1000026 ) : // BdbMetaDataP 00225 case( 1000036 ) : // BdbEvent 00226 case( 1000645 ) : // BdbEvent_001 00227 case( 1000854 ) : // BdbGenericMutualHdr 00228 case( 1000855 ) : // BdbTreeMutualHdr 00229 { 00230 return( !false ) ; 00231 break ; 00232 } 00233 default : 00234 { 00235 return( false ) ; 00236 break ; 00237 } 00238 } 00239 00240 return( false ) ; 00241 } 00242 00243 //------------- 00244 // Modifiers -- 00245 //------------- 00246 00247 void 00248 BdbGenericHdrT::reset( ) 00249 { 00250 BdbRefAny nullRef; 00251 _bdbRef = nullRef; 00252 } 00253 00254 void 00255 BdbGenericHdrT::borrowAsNecessary( const BdbGenericHdrT& original ) 00256 { 00257 const BdbTypeAndString* typeAndStrings ( 0 ) ; 00258 size_t numberTypeAndStrings( original.getTypeAndStrings( typeAndStrings ) ) ; 00259 for( size_t index( 0 ) ; 00260 numberTypeAndStrings != index ; 00261 index++ ) { 00262 BdbRefAny dataObject ; 00263 00264 // If object not in this header, 'borrow' referencec. 00265 if( BdbcError == get( dataObject , 00266 typeAndStrings[ index ].getType() , 00267 typeAndStrings[ index ].getString() ) ) { 00268 original.get( dataObject , 00269 typeAndStrings[ index ].getType() , 00270 typeAndStrings[ index ].getString() ) ; 00271 borrow( dataObject , 00272 typeAndStrings[ index ].getType() , 00273 typeAndStrings[ index ].getString() ) ; 00274 } 00275 00276 // If object is in this header and is a header itself, be recursive 00277 else { 00278 if( canBeGenericHdrT( typeAndStrings[ index ].getType() ) ) { 00279 BdbGenericHdrT leaf( (BdbRef( BdbGenericHdr ))dataObject ) ; 00280 BdbRefAny( origObject ) ; 00281 original.get( origObject , 00282 typeAndStrings[ index ].getType() , 00283 typeAndStrings[ index ].getString() ) ; 00284 leaf.borrowAsNecessary( BdbGenericHdrT( (BdbRef( BdbGenericHdr ))origObject ) ) ; 00285 } 00286 } 00287 } 00288 if( 0 != numberTypeAndStrings ) { 00289 00290 // cast away const to allow deletion 00291 delete [] const_cast< BdbTypeAndString* >( typeAndStrings ) ; 00292 } 00293 } 00294 00295 BdbHandle( BdbGenericHdr ) 00296 BdbGenericHdrT::getHandle() 00297 { 00298 return( (BdbRef( BdbGenericHdr ))(getPersistent()) ) ; 00299 } 00300 00301 BdbStatus 00302 BdbGenericHdrT::put( const BdbRefAny& object , 00303 const ooTypeNumber typeNumber , 00304 const char* const key ) 00305 { 00306 // If new style BdbGenericMutualHdr then run recast and use 00307 // correct access 00308 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00309 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->put( object , 00310 typeNumber , 00311 key ) ) ; 00312 } 00313 00314 // Otherwise assume old style BdbGenericHeader. 00315 // cast away "const" to be compatible with old interface. 00316 return( getHandle()->put( (BdbRefAny&)object , 00317 typeNumber , 00318 key ) ) ; 00319 } 00320 00321 BdbStatus 00322 BdbGenericHdrT::put( BdbRefAny& object , 00323 const char* const key ) 00324 { 00325 return( put( object , 00326 object.typeN() , 00327 key ) ) ; 00328 } 00329 00330 BdbStatus 00331 BdbGenericHdrT::borrow( const BdbRefAny& object , 00332 const ooTypeNumber typeNumber , 00333 const char* const key ) 00334 { 00335 // If new style BdbGenericMutualHdr then run recast and use 00336 // correct access 00337 if( getHandle()->ooIsKindOf( ooTypeN( BdbGenericMutualHdr ) ) ) { 00338 return( ((BdbRef( BdbGenericMutualHdr )&)getPersistent())->borrow( object , 00339 typeNumber , 00340 key ) ) ; 00341 } 00342 00343 // Otherwise assume old style BdbGenericHeader. 00344 // cast away "const" to be compatible with old interface. 00345 return( getHandle()->borrow( (BdbRefAny&)object , 00346 typeNumber , 00347 key ) ) ; 00348 } 00349 00350 #endif // BDBGENERICHDRT_CC
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002