Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

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

/BdbTrees/BdbTreeNodeP.cc

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //  $Id: BdbTreeNodeP.cc,v 1.32 2000/12/03 21:18:10 patton Exp $
00004 //
00005 // Description:
00006 //  Class BdbTreeNodeP implementation file. This class represents a node in a 
00007 //  tree. A node may have a parent, and multiple children, which themselves may 
00008 //  be tree nodes, or leaf objects.
00009 //
00010 // Environment:
00011 //  Software developed for the BaBar Detector at the SLAC B-Factory.
00012 //
00013 // Author List:
00014 //  David R. Quarrie                Original Author
00015 //
00016 // Copyright Information:
00017 //  Copyright (C) 1998              Lawrence Berkeley Laboratory
00018 //
00019 //------------------------------------------------------------------------
00020 
00021 //-----------------------
00022 // This Class's Header --
00023 //-----------------------
00024 #include "BdbTrees/BdbTreeNodeP.hh"
00025 
00026 //-------------
00027 // C Headers --
00028 //-------------
00029 extern "C" {
00030 #include <assert.h>
00031 #include <stddef.h>
00032 #include <string.h>
00033 #include <unistd.h>
00034 }
00035 
00036 //---------------
00037 // C++ Headers --
00038 //---------------
00039 #include <iostream.h>
00040 
00041 //-------------------------------
00042 // Collaborating Class Headers --
00043 //-------------------------------
00044 #include "BdbTrees/BdbTreesErrors.hh"
00045 #include "BdbTrees/BdbTreeNodeItemP.hh"
00046 #include "BdbTrees/BdbMetaData.hh"
00047 #include "BdbUtil/BdbTString.hh"
00048 
00049 //-----------------------------------------------------------------------
00050 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00051 //-----------------------------------------------------------------------
00052 
00053 static const char rcsid[] = "$Id: BdbTreeNodeP.cc,v 1.32 2000/12/03 21:18:10 patton Exp $";
00054 
00055 // Note that returnedName is file static since it has ownership of the
00056 // returned character string for the name( ) and pathName( ) function members. 
00057 // In principle it also should have function scope, but for some reason
00058 // this causes problems with the Solaris optimizer, hence the use of
00059 // file scope. Clients should be aware of this ownership
00060 // since the return value might change between the call to this
00061 // function and the usage of the return string if calls to 
00062 // functions from other classes are made, where these operate on
00063 // other BdbCollectionP instances. Not ideal...
00064 static BdbTString returnedName;
00065 
00066 //      -----------------------------------------------
00067 //      -- Static Data & Function Member Definitions --
00068 //      -----------------------------------------------
00069 
00070 BdbHintInit(BdbTreeNodeP);
00071 
00072 d_Boolean
00073 BdbTreeNodeP::isTreeNode( BdbHandle(BdbPersObj)& theItem )
00074 {
00075     d_Boolean result = d_False;
00076     ooId theID = theItem;
00077     if ( 0 != theID.get_OC( ) ) {
00078         ooTypeNumber theType = ooTypeN( BdbTreeNodeP );
00079         if ( ( theItem.typeN( ) == theType ) || theItem->ooIsKindOf( theType ) ) {
00080             result = d_True;
00081         }
00082     }
00083     return result;
00084 }
00085 
00086 d_Boolean
00087 BdbTreeNodeP::isTreeNode( BdbRef(BdbPersObj)& theItem )
00088 {
00089     d_Boolean result = d_False;
00090     if ( 0 != theItem.get_OC( ) ) {
00091         ooTypeNumber theType = ooTypeN( BdbTreeNodeP );
00092         if ( ( theItem.typeN( ) == theType ) || theItem->ooIsKindOf( theType ) ) {
00093             result = d_True;
00094         }
00095     }
00096     return result;
00097 }
00098 
00099 d_Boolean
00100 BdbTreeNodeP::isValid( const char* const theName )
00101 {
00102     d_Boolean result = d_False;
00103     if ( 0 != theName ) {
00104         const char* slash = strchr( theName, '/' );
00105         if ( 0 == slash ) {
00106             result = d_True;
00107         }
00108     }
00109     return result;
00110 }
00111 
00112 //      ----------------------------------------
00113 //      -- Public Function Member Definitions --
00114 //      ----------------------------------------
00115 
00116 //--------------
00117 // Destructor --
00118 //--------------
00119 
00120 BdbTreeNodeP::~BdbTreeNodeP( )
00121 {
00122     if ( ! BdbIsNull( _children ) ) {
00123         clear( );
00124         BdbDelete( _children );
00125     }
00126     if ( ! BdbIsNull( _metadata ) ) {
00127         BdbDelete( _metadata );
00128     }
00129 }
00130 
00131 //-------------
00132 // Selectors --
00133 //-------------
00134  
00135 d_ULong 
00136 BdbTreeNodeP::count( ) const
00137 {
00138     return (d_ULong)_children->nElement( );
00139 }
00140 
00141 const char*
00142 BdbTreeNodeP::pathName( ) const
00143 {
00144     // Determine the format of the name. If it contains 
00145     // embedded "/" characters then it is the full name,
00146     // and can be directly returned. This is the new 
00147     // implementation. If it doesn't contain any "/" 
00148     // characters it is assumed to be the old implementation 
00149     // and the full name is optained by walking up the node
00150     // tree, prefixing their names to what is returned. This
00151     // old implementation has the bad side effect of putting
00152     // read locks on those nodes.
00153     const char* result = (const char*)_name;
00154     const char* theFragment = strrchr( result, '/' );
00155     if ( 0 == theFragment ) {
00156 
00157         // Old implementation
00158         BdbHandle(BdbTreeNodeP) theNode = ooThis( );
00159         BdbTString aFragment; 
00160         BdbTString theName = "/";
00161         while ( ! BdbIsNull( theNode ) ) {
00162             BdbHandle(BdbTreeNodeP) theParent;
00163             BdbStatus status = theNode->parent( theParent );
00164             if ( ! BdbIsNull( theParent ) ) {
00165                 aFragment  = "/";
00166                 aFragment += theNode->name( );
00167                 aFragment += theName;
00168                 theName    = aFragment;
00169              }
00170             theNode = theParent;
00171         }
00172         returnedName = theName;
00173     } else {
00174 
00175         // New implementation
00176         returnedName  = result;
00177         returnedName += "/";
00178     }
00179     result = returnedName.chars( );
00180     return result;
00181 }
00182 
00183 const char*
00184 BdbTreeNodeP::fullName( ) const
00185 {
00186     // Determine the format of the name. If it contains 
00187     // embedded "/" characters then it is the full name,
00188     // and can be directly returned. This is the new 
00189     // implementation. If it doesn't contain any "/" 
00190     // characters it is assumed to be the old implementation 
00191     // and the full name is optained by walking up the node
00192     // tree, prefixing their names to what is returned. This
00193     // old implementation has the bad side effect of putting
00194     // read locks on those nodes.
00195     const char* result = (const char*)_name;
00196     const char* theFragment = strrchr( result, '/' );
00197     if ( 0 == theFragment ) {
00198 
00199         // Old implementation
00200         BdbHandle(BdbTreeNodeP) theNode = ooThis( );
00201         BdbTString aFragment; 
00202         BdbTString theName = "";
00203         while ( ! BdbIsNull( theNode ) ) {
00204             BdbHandle(BdbTreeNodeP) theParent;
00205             BdbStatus status = theNode->parent( theParent );
00206             if ( ! BdbIsNull( theParent ) ) {
00207                 aFragment  = "/";
00208                 aFragment += theNode->name( );
00209                 aFragment += theName;
00210                 theName    = aFragment;
00211              }
00212             theNode = theParent;
00213         }
00214         returnedName = theName;
00215     } else {
00216 
00217         // New implementation
00218         returnedName = result;
00219     }
00220     result = returnedName.chars( );
00221     return result;
00222 }
00223 
00224 const char*
00225 BdbTreeNodeP::name( ) const
00226 {
00227     // Determine the format of the name. If it contains 
00228     // embedded "/" characters then it is the full name,
00229     // and only the last fragment should be returned as 
00230     // the node name. This is the new implementation. 
00231     // If it doesn't contain any "/" characters it is 
00232     // assumed to be the old implementation and is returned 
00233     // directly. The new implementation avoids walking up 
00234     // the node tree in fullName( ) and pathName( ), since this 
00235     // puts unnecessary read locks on those.
00236     const char* result = (const char*)_name;
00237     if ( 0 != result ) {
00238         const char* theFragment = strrchr( result, '/' );
00239         if ( 0 == theFragment ) {
00240 
00241             // Old implementation
00242             returnedName = result;
00243         } else {
00244 
00245             // New implementation - return the last fragment, but
00246             // ignoring the final trailing "/" character.
00247             theFragment++;
00248             returnedName = theFragment;
00249         }
00250         result = returnedName.chars( );
00251     }
00252     return result;
00253 }
00254 
00255 //-------------
00256 // Modifiers --
00257 //-------------
00258 
00259 //--------------
00260 // Operations --
00261 //--------------
00262     
00263 BdbStatus
00264 BdbTreeNodeP::add( BdbHandle(BdbPersObj)& aChild, const char* const theName ) 
00265 {
00266     BdbStatus result = BdbcError;
00267 
00268     if ( isValid( theName ) ) {
00269         if (! _children->isMember( theName ) ) {
00270             BdbHandle(BdbTreeNodeItemP) anItem;
00271             anItem = new ( ooThis( ) ) BdbTreeNodeItemP( aChild );
00272             result = _children->add( theName, anItem );
00273         }
00274     } else {
00275         BdbSignal( BdbcUserError, BdbTreesErrNodeNameNotValid, 0, 
00276                    "BdbTreeNodeP::add", theName ); 
00277     }
00278     return result;
00279 }
00280 
00281 BdbStatus
00282 BdbTreeNodeP::child( BdbHandle(BdbPersObj)& aChild, 
00283                      const char* const theName ) const
00284 {
00285     BdbStatus result = BdbcError;
00286     ooTypeNumber theType;
00287     BdbHandle(BdbTreeNodeItemP) theItem;
00288     aChild = 0;
00289     if ( 0 != theName ) {
00290         _children->lookup( theName, theItem, BdbcRead );
00291         if ( ! BdbIsNull( theItem ) ) {
00292             result = theItem->item( aChild, theType );
00293         }
00294     }
00295     return result;
00296 }
00297 
00298 BdbStatus
00299 BdbTreeNodeP::child( BdbHandle(BdbPersObj)& aChild, 
00300                      const char* const theName,
00301                      ooTypeNumber theType ) const
00302 {
00303     BdbStatus result = BdbcError;
00304     ooTypeNumber itemType;
00305     BdbHandle(BdbTreeNodeItemP) theItem;
00306     aChild = 0;
00307     if ( 0 != theName ) {
00308         _children->lookup( theName, theItem, BdbcRead );
00309         if ( ! BdbIsNull( theItem ) ) {
00310             result = theItem->item( aChild, itemType );
00311             if ( itemType != theType ) {
00312                 aChild = 0;
00313                 result = BdbcError;
00314             }
00315         }
00316     }
00317     return result;
00318 }
00319 
00320 BdbStatus
00321 BdbTreeNodeP::child( BdbHandle(BdbPersObj)& aChild, 
00322                      const char* const theName,
00323                     ooTypeNumber theTypes[], d_ULong numTypes ) const 
00324 {
00325     BdbStatus result = BdbcError;
00326     ooTypeNumber itemType;
00327     BdbHandle(BdbTreeNodeItemP) theItem;
00328     BdbHandle(BdbPersObj) theChild;
00329     aChild = 0;
00330     if ( 0 != theName ) {
00331         _children->lookup( theName, theItem, BdbcRead );
00332         if ( ! BdbIsNull( theItem ) ) {
00333             theItem->item( theChild, itemType );
00334             d_ULong i = 0;
00335             while ( result != BdbcSuccess && i < numTypes ) {
00336                 if ( itemType == theTypes[i] ) {
00337                     aChild = theChild;
00338                     result = BdbcSuccess;
00339                 }
00340                 i++;
00341             }
00342         }
00343     }
00344     return result;
00345 }
00346 
00347 d_Boolean
00348 BdbTreeNodeP::childIsTreeNode( const char* const theName ) const
00349 {
00350     d_Boolean result = d_False;
00351     BdbHandle(BdbTreeNodeItemP) theItem;
00352     if ( 0 != theName ) {
00353         _children->lookup( theName, theItem, BdbcRead );
00354         if ( ! BdbIsNull( theItem ) ) {
00355             result = theItem->isTreeNode( );
00356         }
00357     }
00358     return result;
00359 }
00360 
00361 BdbStatus
00362 BdbTreeNodeP::clear( )
00363 {
00364     BdbStatus status;
00365     BdbRef(BdbTreeNodeItemP) theItem;
00366     ooHandle(BdbMap) theMap = _children;
00367     BdbStatus result = BdbcSuccess;
00368 
00369     while ( theMap->nElement( ) > 0 ) {
00370         ooMapItr childIter( theMap );
00371         status = childIter.next( );
00372         if ( BdbcSuccess == status ) {
00373             theItem  = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00374             BdbDelete( theItem );
00375         }
00376     }
00377     return result;
00378 }
00379 
00380 BdbStatus
00381 BdbTreeNodeP::clearAndDestroy( )
00382 {
00383     BdbStatus status;
00384     BdbRef(BdbTreeNodeItemP) theItem;
00385     BdbHandle(BdbPersObj) theChild;
00386     BdbHandle(BdbTreeNodeP) theNodeP;
00387     ooHandle(BdbMap) theMap = _children;
00388     BdbStatus result = BdbcSuccess;
00389 
00390     while ( theMap->nElement( ) > 0 ) {
00391         ooMapItr childIter( theMap );
00392         status = childIter.next( );
00393         if ( BdbcSuccess == status ) {
00394             theItem  = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00395             theChild = theItem->item( );
00396             if ( theItem->isTreeNode( ) ) {
00397                 theNodeP = (BdbHandle(BdbTreeNodeP)&)theChild;
00398                 theNodeP->clearAndDestroy( );
00399             }
00400             BdbDelete( theItem  );
00401             BdbDelete( theChild );
00402         }
00403     }
00404     return result;
00405 }
00406 
00407 d_Boolean
00408 BdbTreeNodeP::hasChild( const char* const theName ) const
00409 {
00410     d_Boolean result = d_False;
00411     if ( 0 != theName ) {
00412         result = _children->isMember( theName );
00413     }
00414     return result;
00415 }
00416 
00417 d_Boolean
00418 BdbTreeNodeP::hasChild( BdbHandle(BdbPersObj)& aChild, d_Boolean descend ) const 
00419 {
00420     assert( ! BdbIsNull( aChild ) );
00421     BdbStatus result = BdbcError;
00422     BdbRef(BdbTreeNodeItemP) theItem;
00423     BdbHandle(BdbPersObj) theChild;
00424     BdbHandle(BdbTreeNodeP) theNode;
00425     BdbRef(ooMap) theMap = _children;
00426 
00427     ooMapItr childIter( theMap );
00428     while ( ( BdbcSuccess != result ) && childIter.next( ) ) {
00429         theItem = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00430         theChild = theItem->item( );
00431         if ( theChild == aChild ) {
00432             result = BdbcSuccess;
00433         }
00434     }
00435     if ( ( BdbcSuccess != result ) && descend ) {
00436         ooMapItr nodeIter( theMap );
00437         while ( ( BdbcSuccess != result ) && nodeIter.next( ) ) {
00438             theItem = (const BdbRef(BdbTreeNodeItemP)&) nodeIter->oid( );
00439             if ( theItem->isTreeNode( ) ) {
00440                 theChild = theItem->item( );
00441                 theNode  = (BdbHandle(BdbTreeNodeP)&) theChild;
00442                 result   = theNode->hasChild( aChild, descend );
00443             }
00444         }
00445     }
00446     return result;
00447 }
00448 
00449 BdbStatus
00450 BdbTreeNodeP::makeChild( BdbHandle(BdbTreeNodeP)& aNode, 
00451                          const char* const theName )
00452 {
00453     BdbHandle(BdbTreeNodeItemP) anItem;
00454     BdbStatus result = item( anItem, theName );
00455     if ( BdbcSuccess == result ) {
00456         if ( anItem->isTreeNode( ) ) {
00457             aNode = (const BdbHandle(BdbTreeNodeP)&) anItem->item( );
00458         } else {
00459             aNode  = 0;
00460             result = BdbcError;
00461         }
00462     } else {
00463         BdbHandle(BdbTreeNodeP) self = ooThis( );
00464         BdbHandle(BdbTreeNodeP) aNodeP;
00465         BdbHandleAny theHint = BdbTreeNodeP::clustering.updatedHint( );
00466            aNodeP = new( theHint ) BdbTreeNodeP( self, theName );
00467         if ( ! BdbIsNull( aNodeP ) ) {
00468             result = add( aNodeP, theName );
00469         }
00470         aNode = aNodeP;
00471     }
00472     return result;
00473 }
00474 
00475 BdbStatus 
00476 BdbTreeNodeP::parent( BdbHandle(BdbTreeNodeP)& theParent ) const
00477 {
00478     BdbStatus result = BdbcSuccess;
00479     BdbRef(BdbTreeNodeP) aParent;
00480     aParent   = _parent;
00481     theParent = aParent;
00482     if ( BdbIsNull( aParent ) ) {
00483         result = BdbcError;
00484     }
00485     return result;
00486 }
00487 
00488 BdbStatus
00489 BdbTreeNodeP::remove( const char* const theName ) 
00490 {
00491     BdbHandle(BdbTreeNodeItemP) anItem;
00492     BdbStatus result = item( anItem, theName );
00493     if ( BdbcSuccess == result ) {
00494         BdbDelete( anItem );
00495     }
00496     return result;
00497 }
00498 
00499 BdbStatus
00500 BdbTreeNodeP::remove( BdbHandle(BdbPersObj)& aChild ) 
00501 {
00502     BdbStatus result = BdbcError;
00503     BdbStatus status = BdbcSuccess;
00504     BdbRef(BdbTreeNodeItemP) theItem;
00505     BdbHandle(BdbPersObj) theChild;
00506 
00507     ooMapItr childIter( _children );
00508     while ( BdbcSuccess == status ) {
00509         status = childIter.next( );
00510         if ( BdbcSuccess == status ) {
00511             theItem = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00512             if ( theItem->item( ) == aChild ) {
00513                 result = remove( childIter->name( ) );
00514                 status = BdbcError;
00515             }
00516         }
00517     }
00518     return result;
00519 }
00520 
00521 BdbStatus
00522 BdbTreeNodeP::removeAndDestroy( const char* const theName ) 
00523 {
00524     BdbHandle(BdbPersObj) theChild; 
00525     BdbHandle(BdbTreeNodeItemP) theItem; 
00526     BdbHandle(BdbTreeNodeP) theNodeP; 
00527     BdbStatus result = item( theItem, theName );
00528     if ( BdbcSuccess == result ) {
00529         theChild = theItem->item( );
00530         if ( theItem->isTreeNode( ) ) {
00531             theNodeP = (BdbHandle(BdbTreeNodeP)&)theChild;
00532             theNodeP->clearAndDestroy( );
00533         }
00534         BdbDelete( theItem  );
00535         BdbDelete( theChild );
00536     }
00537     return result;
00538 }
00539 
00540 BdbStatus
00541 BdbTreeNodeP::removeAndDestroy( BdbHandle(BdbPersObj)& aChild ) 
00542 {
00543     BdbRef(BdbTreeNodeItemP) theItem;
00544     BdbStatus result = BdbcError;
00545     BdbStatus status = BdbcSuccess;
00546 
00547     ooMapItr childIter( _children );
00548     while ( BdbcSuccess == status ) {
00549         status = childIter.next( );
00550         if ( BdbcSuccess == status ) {
00551             theItem = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00552             if ( theItem->item( ) == aChild ) {
00553                 result = removeAndDestroy( childIter->name( ) );
00554                 status = BdbcError;
00555             }
00556         }
00557     }
00558     return result;
00559 }
00560 
00561 BdbStatus
00562 BdbTreeNodeP::replace( BdbHandle(BdbPersObj)& aChild, const char* const theName ) 
00563 {
00564     BdbStatus result = remove( theName );
00565     result = add( aChild, theName );
00566     return result;
00567 }
00568 
00569 BdbStatus 
00570 BdbTreeNodeP::root( BdbHandle(BdbTreeNodeP)& theRoot ) const
00571 {
00572     BdbHandle(BdbTreeNodeP) theParent = ooThis( );
00573     BdbStatus status;
00574     while ( ! BdbIsNull( theParent ) ) {
00575         theRoot = theParent;
00576         status  = theRoot->parent( theParent );
00577     }
00578     return BdbcSuccess;
00579 }
00580 
00581 BdbStatus
00582 BdbTreeNodeP::cloneChildren( BdbHandle(BdbTreeNodeP)& theOther )
00583 {
00584     BdbStatus result = BdbcSuccess;
00585     BdbStatus status = BdbcSuccess;
00586     BdbRef(BdbMap) otherChildren = theOther->children( );
00587     ooMapItr childIter( otherChildren );
00588     BdbRef(BdbTreeNodeItemP) theItem;
00589     while ( BdbcSuccess == status ) {
00590         status = childIter.next( );
00591         if ( BdbcSuccess == status ) {
00592             theItem = (const BdbRef(BdbTreeNodeItemP)&) childIter->oid( );
00593             BdbHandleAny newItemP = theItem->item( );
00594             if ( newItemP.isValid( ) ) {
00595                 BdbHandle(BdbTreeNodeItemP) newItem;
00596                 newItem = new( ooThis( ) ) BdbTreeNodeItemP( newItemP );
00597                 status = _children->add( childIter->name( ), newItem );
00598                 if ( theItem->isTreeNode( ) ) {
00599                     BdbHandle(BdbTreeNodeP) newNodeP = (BdbHandle(BdbTreeNodeP)&) newItemP;
00600                     static BdbHandle( BdbTreeNodeP ) tmp ;
00601                     status = newNodeP->setParent( ooThis( tmp ), newNodeP->name( ) );
00602                 }
00603             } else {
00604                 BdbSignal( BdbcUserError, BdbTreesErrItemNotValid, 0, 
00605                            "BdbTreeNodeP::cloneChildren" ); 
00606             }
00607         }
00608     }
00609 
00610     // Now clone any metadata associated with this node
00611     BdbHandle(BdbMetaDataP) otherData;
00612     status = theOther->metaData( otherData );
00613     if ( ! BdbIsNull(otherData) ) {
00614         BdbHandle(BdbMetaDataP) theData;
00615         status = fetchMetaData( theData );
00616         if ( BdbcSuccess == status ) {
00617             status = theData->clone( otherData );
00618         }
00619     }
00620     return result;
00621 }
00622 
00623 BdbStatus
00624 BdbTreeNodeP::upgradeName( )
00625 {
00626     // Upgrade the tree node name to the new format (full path name)
00627     // if necessary
00628     BdbStatus result = BdbcError;
00629     const char* theName = (const char*)_name;
00630     const char* theFragment = strrchr( theName, '/' );
00631     if ( 0 == theFragment ) {
00632 
00633         // Old format - upgrade to new format
00634         ooUpdate( );
00635         theName = fullName( );
00636         _name   = theName;
00637         result  = BdbcSuccess;
00638     }
00639     return result;
00640 }
00641 
00642 //              ------------------------
00643 //              --MetaData Operations --
00644 //              ------------------------
00645 
00646 BdbStatus 
00647 BdbTreeNodeP::fetchMetaData( BdbHandle(BdbMetaDataP)& theData )
00648 {
00649     BdbHandle(BdbTreeNodeP) self = ooThis( );
00650     BdbHandle(BdbMetaDataP) theDataP = _metadata;
00651     BdbStatus result = BdbcSuccess;
00652     if ( BdbIsNull( theDataP ) ) {
00653         theDataP = new (self) BdbMetaDataP( self, name( ) );
00654         if ( ! BdbIsNull( theDataP ) ) {
00655             _metadata = theDataP;
00656         } else {
00657             result = BdbcError;
00658         }
00659     }
00660     theData = theDataP;
00661     return result;
00662 }
00663 
00664 BdbStatus 
00665 BdbTreeNodeP::metaData( BdbHandle(BdbMetaDataP)& theData ) const
00666 {
00667     theData = _metadata;
00668     return BdbcSuccess;
00669 }
00670 
00671 //      -------------------------------------------
00672 //      -- Protected Function Member Definitions --
00673 //      -------------------------------------------
00674 
00675 //----------------
00676 // Constructors --
00677 //----------------
00678 
00679 BdbTreeNodeP::BdbTreeNodeP( const char* const theName )
00680 {
00681     initialize( theName );
00682 }
00683 
00684 BdbTreeNodeP::BdbTreeNodeP( BdbHandle(BdbTreeNodeP)& theParent, 
00685                             const char* const theName )
00686 {
00687     _parent = theParent;
00688     initialize( theName );
00689     setParent( theParent, theName );
00690 }
00691 
00692 BdbStatus
00693 BdbTreeNodeP::item( BdbHandle(BdbTreeNodeItemP)& anItem, 
00694                     const char* const theName ) const
00695 {
00696     BdbStatus result = BdbcError;
00697     if ( 0 != theName ) {
00698         _children->lookup( theName, anItem, BdbcRead );
00699         if ( ! BdbIsNull( anItem ) ) {
00700             result = BdbcSuccess;
00701         }
00702     }
00703     return result;
00704 }
00705 
00706 BdbStatus
00707 BdbTreeNodeP::setParent( BdbHandle(BdbTreeNodeP)& theParent, 
00708                          const char* const theName )
00709 {
00710     BdbStatus result = BdbcError;
00711     if ( isValid( theName ) ) {
00712         ooUpdate( );
00713         _name   = theName;
00714         _parent = theParent;
00715 
00716         // Disable the conversion to the full name until after the
00717         // migration has been adopted. The following code needs to be
00718         // uncommented at that point.
00719         //// const char* newName = fullName( );
00720         //// _name = newName;
00721         result = BdbcSuccess;
00722     } else {
00723         BdbSignal( BdbcUserError, BdbTreesErrNodeNameNotValid, 0, 
00724                    "BdbTreeNodeP::setParent", theName ); 
00725     }
00726     return result;
00727 }
00728 
00729 BdbRef(BdbMap) 
00730 BdbTreeNodeP::children( ) const
00731 {
00732     return _children;
00733 }
00734 
00735 void
00736 BdbTreeNodeP::initialize( const char* const theName )
00737 {
00738     _name = theName;
00739     BdbHandle(BdbMap) theMap;
00740     theMap = new( ooThis( ) ) BdbMap;
00741     if ( ! BdbIsNull( theMap ) ) {
00742         _children = theMap;
00743     } else {
00744         BdbSignal( BdbcUserError, BdbTreesErrTreeNotInitialized, 0, 
00745                    "BdbTreeNodeP::initialize", theName ); 
00746     }
00747 }

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002