00001 // File and Version Information: 00002 // $Id: CdbBdbSViewCollectionP.cc,v 1.8 2004/08/06 05:54:25 bartoldu Exp $ 00003 00004 /// The implementation file for the CdbBdbSViewCollectionP class 00005 /** 00006 * @see CdbBdbSViewCollectionP 00007 */ 00008 00009 #include "BaBar/BaBar.hh" 00010 00011 #include "CdbBdbShared/CdbBdbSViewCollectionP.hh" 00012 #include "CdbBdbShared/CdbBdbSViewP.hh" 00013 00014 #include <iostream> 00015 #include <assert.h> 00016 using std::cout; 00017 using std::endl; 00018 00019 CdbBdbSViewCollectionP::CdbBdbSViewCollectionP( ) : 00020 CdbBdbSCollectionP( ), 00021 _newestRef(0) 00022 { } 00023 00024 CdbBdbSViewCollectionP::~CdbBdbSViewCollectionP( ) 00025 { } 00026 00027 CdbStatus 00028 CdbBdbSViewCollectionP::insert( const BdbRef( CdbBdbSCollectionElementP )& theRef ) 00029 { 00030 const char* errorStr = "CdbBdbSViewCollectionP::insert() -- ERROR"; 00031 00032 CdbStatus result = CdbStatus::Error; 00033 do { 00034 00035 // Verify parameters 00036 00037 if( BdbIsNull(theRef)) { 00038 cout << errorStr << endl 00039 << " 0-0-0-0 reference passed to the collection." << endl; 00040 break; 00041 } 00042 00043 // Get back to the original class. 00044 00045 BdbRef(CdbBdbSViewP) vRef = (const BdbRef(CdbBdbSViewP)&) theRef; 00046 00047 // Update the "newest" element if the passed one qualifies for this criteria. 00048 // 00049 // NOTE: The update of the "newest" is revertable in case if something wrong 00050 // happens during the insertion into the collection. 00051 00052 BdbRef( CdbBdbSCollectionElementP ) oldNewestRef = _newestRef; 00053 00054 if( BdbIsNull(_newestRef)) { 00055 _newestRef = theRef; 00056 } else { 00057 BdbRef(CdbBdbSViewP) vNewestRef = (const BdbRef(CdbBdbSViewP)&) _newestRef; 00058 if( vRef->created( ) > vNewestRef->created( )) { 00059 _newestRef = theRef; 00060 } 00061 } 00062 00063 // Do the rest at the base class's method. 00064 00065 result = CdbBdbSCollectionP::insert( theRef ); 00066 if( CdbStatus::Success != result ) { 00067 _newestRef = oldNewestRef; 00068 } 00069 00070 } while( false ); 00071 00072 return result; 00073 } 00074 00075 CdbStatus 00076 CdbBdbSViewCollectionP::newest( BdbRef( CdbBdbSCollectionElementP )& theRef ) 00077 { 00078 if( BdbIsNull(_newestRef)) { 00079 theRef = 0; 00080 return CdbStatus::NotFound; 00081 } 00082 theRef = _newestRef; 00083 return CdbStatus::Success; 00084 } 00085 00086 00087 ///////////////// 00088 // End Of File // 00089 /////////////////
1.3-rc3