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

CdbBdbSViewItr.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbSViewItr.cc,v 1.3 2002/09/23 22:41:13 gapon Exp $
00003 
00004 /// The implementation of the CdbBdbSViewItr class.
00005 /**
00006   * @see CdbBdbSViewItr
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbShared/CdbBdbSViewItr.hh"
00012 #include "CdbBdbShared/CdbBdbSOriginP.hh"
00013 #include "CdbBdbShared/CdbBdbSViewP.hh"
00014 
00015 #include "CdbBase/CdbDatabase.hh"
00016 #include "CdbBase/CdbCompositeName.hh"
00017 
00018 #include <assert.h>
00019 
00020 CdbBdbSViewItr::CdbBdbSViewItr( const BdbHandle(CdbBdbSRegistryP)& theMasterRegistryH ) :
00021     _masterRegistryH(theMasterRegistryH),
00022     _isValid(false),
00023     _hasEverBeenAdvanced(false)
00024 {
00025     assert( !theMasterRegistryH.isNull( ));
00026 }
00027 
00028 CdbBdbSViewItr::CdbBdbSViewItr( const CdbBdbSViewItr& theItr ) :
00029     _masterRegistryH    (theItr._masterRegistryH),
00030     _isValid            (theItr._isValid),
00031     _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced),
00032     _originNameItr      (theItr._originNameItr),
00033     _viewNameItr        (theItr._viewNameItr),
00034     _originName         (theItr._originName),
00035     _viewName           (theItr._viewName),
00036     _currentValue       (theItr._currentValue)
00037 { }
00038 
00039 CdbBdbSViewItr::~CdbBdbSViewItr( )
00040 { }
00041 
00042 CdbStatus
00043 CdbBdbSViewItr::reset( )
00044 {
00045     _isValid             = false;
00046     _hasEverBeenAdvanced = false;
00047 
00048     return CdbStatus::Success;
00049 }
00050 
00051 bool
00052 CdbBdbSViewItr::tryNextView( )
00053 {
00054     if( _viewNameItr.next( )) {
00055         _viewName = _viewNameItr.value( );
00056 
00057         CdbCompositeName compositeViewName( _originName.c_str( ),
00058                                             _viewName.c_str( ));
00059         assert( compositeViewName.isValid( ));
00060 
00061         _currentValue = compositeViewName.getName( );
00062 
00063         return true;
00064     }
00065     return tryNextOrigin( );
00066 }
00067 
00068 bool
00069 CdbBdbSViewItr::tryNextOrigin( )
00070 {
00071     while( _originNameItr.next( )) {
00072 
00073         _originName = _originNameItr.value( );
00074 
00075         BdbHandle(CdbBdbSRegistryP) rH;
00076         if( CdbStatus::Success == CdbBdbSRegistryP::findByOrigin( rH,
00077                                                                   _originName.c_str( ))) {
00078 
00079             BdbRef(CdbBdbSViewCollectionP) vCollRef = rH->viewCollection( );
00080             assert( !BdbIsNull(vCollRef));
00081 
00082             _viewNameItr = vCollRef->iterator_names( );
00083 
00084             return tryNextView( );
00085         }
00086     }
00087     return false;
00088 }
00089  
00090 bool
00091 CdbBdbSViewItr::next( )
00092 {
00093     if( _hasEverBeenAdvanced ) {
00094         if( _isValid ) {
00095             _isValid = tryNextView( );
00096         }
00097 
00098     } else {
00099 
00100         BdbRef(CdbBdbSOriginCollectionP) oCollRef = _masterRegistryH->originCollection( );
00101         assert( !BdbIsNull(oCollRef));
00102 
00103         _originNameItr = oCollRef->iterator_names( );
00104 
00105         _isValid             = tryNextOrigin( );
00106         _hasEverBeenAdvanced = true;
00107     }
00108     return _isValid;
00109 }
00110 
00111 CdbBdbSViewItr::ValueType
00112 CdbBdbSViewItr::value( )
00113 {
00114     if( _isValid ) return _currentValue.c_str( );
00115     return 0;
00116 }
00117 
00118 bool
00119 CdbBdbSViewItr::isValid( )
00120 {
00121     return _isValid;
00122 }
00123 
00124 CdbBdbSViewItr::InterfaceType*
00125 CdbBdbSViewItr::clone( ) const
00126 {
00127     return new CdbBdbSViewItr( *this );
00128 }
00129 
00130 /////////////////
00131 // End Of File //
00132 /////////////////

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