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  

/BdbEventStore/BdbVectorCollectionT.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: BdbVectorCollectionT.cc,v 1.3 2002/06/10 23:33:55 becla Exp $
00004 //
00005 // Description:
00006 //      Class BdbVectorCollectionT interface (.cc) file. This file declares the 
00007 //      templated collection (implemented as a vector) class.
00008 //
00009 // Environment:
00010 //      Software developed for the BaBar Detector at the SLAC B-Factory
00011 //
00012 // Author List:
00013 //       David R. Quarrie       Original Author (source in BdbVectorCollection)
00014 //      Jacek Becla             Modified to break dependency between Event Store
00015 //                              and BdbEvent
00016 //
00017 // Copyright Information:
00018 //      Copyright (C) 2002      Stanford Linear Accelerator Center
00019 //
00020 //------------------------------------------------------------------------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "BdbEventStore/BdbEventStore.hh"
00026 #include "BdbEventStore/BdbVectorCollTIterator.hh"
00027 #include "BdbEventStore/BdbVectorCollTItemIterator.hh"
00028 #include "BdbEventStore/BdbCollTItemIterator.hh"
00029 #include "BdbTrees/BdbTreeNode.hh"
00030 
00031 //-------------
00032 // C Headers --
00033 //-------------
00034 extern "C" {
00035 #include <assert.h>
00036 }
00037 
00038 //              ----------------------------------------
00039 //              -- Public Function Member Definitions --
00040 //              ----------------------------------------
00041 
00042 //--------------
00043 // Destructor --
00044 //--------------
00045 
00046 template < class T > 
00047 BdbVectorCollectionT<T>::~BdbVectorCollectionT( )
00048 {
00049 }
00050 
00051 template < class T > 
00052 BdbCollectionTIterator< T >*
00053 BdbVectorCollectionT<T>::getIterator( d_ULong initialIndex ) const
00054 {
00055    return( new BdbVectorCollTIterator< T >( *this ,
00056                                            initialIndex ) ) ;
00057 }
00058 template < class T > 
00059 BdbCollTItemIterator< T >*
00060 BdbVectorCollectionT<T>::getCollItemIterator( d_ULong initialIndex ) const
00061 {
00062    return( new BdbVectorCollTItemIterator< T >( *this ,
00063                                            initialIndex ) ) ;
00064 }
00065 
00066 template < class T > 
00067 BdbStatus 
00068 BdbVectorCollectionT<T>::addCollection( BdbAbsCollectionT<T>& theOther ) 
00069 {
00070     BdbStatus result = BdbcError;
00071 
00072     if ( isCompatible( theOther ) ) {
00073         BdbCollectionTIterator<T>* iter( theOther.getIterator() );
00074         typename T::ObjyRef nullRef;
00075         T item(nullRef, d_True);
00076         while ( BdbcSuccess == ( result = iter->next( item )) ) {
00077             add( item );
00078         }
00079         delete iter;
00080         result = BdbcSuccess;
00081     } else {
00082         BdbSignal( BdbcUserError, BdbEventStoreErrIncompatibleAuthLevels, 0, 
00083             "BdbVectorCollectionT<T>::addCollection" ); 
00084     }
00085     return result;
00086 }
00087 
00088 template < class T > 
00089 BdbStatus 
00090 BdbVectorCollectionT<T>::removeCollection( BdbAbsCollectionT<T>& theOther ) 
00091 {
00092     BdbCollectionTIterator<T>* iter( theOther.getIterator() );
00093     typename T::ObjyRef nullRef;
00094     T item(nullRef, d_True);
00095     BdbStatus status; 
00096     while ( BdbcSuccess == ( status = iter->next( item )) ) {
00097         remove( item );
00098     }
00099     delete iter ;
00100     return BdbcSuccess;
00101 }
00102 
00103 template < class T > 
00104 BdbAbsCollectionT<T>* 
00105 BdbVectorCollectionT<T>::collItem( d_ULong index ) const
00106 {
00107     BdbAbsCollectionT<T>* result = 0;
00108     return result;
00109 }
00110 
00111 template < class T >
00112 BdbHandle(BdbCollectionP) 
00113 BdbVectorCollectionT<T>::component( ) const
00114 {
00115     return persistent( );
00116 }
00117 
00118 template < class T > 
00119 void 
00120 BdbVectorCollectionT<T>::deleteObject( )
00121 {
00122     BdbHandle(BdbCollectionP) theCollP = persistent( );
00123     BdbHandle(BdbVectorCollectionP) self = 
00124             (BdbHandle(BdbVectorCollectionP)&)theCollP;
00125     self->clearAndDestroy( );
00126     BdbAbsWrapper::deleteObject( );
00127 }
00128 
00129 //      -------------------------------------------
00130 //      -- Protected Function Member Definitions --
00131 //      -------------------------------------------
00132 
00133 //----------------
00134 // Constructors --
00135 //----------------
00136 
00137 //----------------
00138 // Constructors --
00139 //----------------
00140 
00141 template < class T > 
00142 BdbVectorCollectionT<T>::BdbVectorCollectionT( 
00143     BdbHandleAny& theHint, BdbHandle(BdbTreeNodeP)& theNode, 
00144     const char* const theName, d_ULong theSize )
00145 // Note that theNode and theHint are already locked for update mode access
00146 {
00147     BdbStatus status = BdbcSuccess;
00148     BdbHandle(BdbCollectionP) theColl;
00149     theColl = new( theHint ) BdbVectorCollectionP( theName, theSize );
00150     if ( ! BdbIsNull( theColl ) ) {
00151         setObject( theColl );
00152 
00153         // Collection successfully created - bind it to the node if
00154         // specified
00155         if( ! theNode.isNull() ) {
00156            status = theColl->bind( theNode );
00157            if ( BdbcSuccess != status ) {
00158               BdbSignal( BdbcUserError, BdbEventStoreErrUnableToAddCollection, 0, 
00159                          "BdbVectorCollectionT<T>::BdbVectorCollectionT", theName ); 
00160            }
00161         }
00162     } else {
00163         BdbSignal( BdbcUserError, BdbEventStoreErrCantCreateCollection, 0, 
00164           "BdbVectorCollectionT<T>::BdbVectorCollectionT", theName ) ; 
00165     }
00166 }
00167 
00168 template < class T > 
00169 BdbVectorCollectionT<T>::BdbVectorCollectionT( BdbHandle(BdbVectorCollectionP)& theColl )
00170 : BdbBaseCollectionT<T>( theColl )
00171 {
00172 }

 


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

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