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

CdbTranslatorsDict.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbTranslatorsDict.cc,v 1.2 2005/10/31 23:41:40 gapon Exp $
00003 
00004 /// The implementation of the CdbTranslatorsDict class.
00005 /**
00006   * @see CdbTranslatorsDict
00007   */
00008 #include "BaBar/BaBar.hh"
00009 
00010 #include "CdbBase/CdbTranslatorsDict.hh"
00011 #include "CdbBase/CdbObjectTranslator.hh"
00012 #include "CdbBase/CdbDebugStream.hh"
00013 
00014 #include <iostream>
00015 using std::endl;
00016 
00017 CdbTranslatorsDict::CdbTranslatorsDict( ) :
00018     CdbTranslatorsDictBase( )
00019 { }
00020 
00021 CdbTranslatorsDict::~CdbTranslatorsDict( )
00022 { }
00023 
00024 CdbStatus
00025 CdbTranslatorsDict::add( const CdbCPtr< CdbObjectTranslator >& theTranslatorPtr )
00026 {
00027     const char* context =  "CdbTranslatorsDict::add()";
00028 
00029     if( theTranslatorPtr.isNull( )) return CdbStatus::IllegalParameters;
00030 
00031     CDB_DEBUG_STREAM << context << ": trying transientTypeId=" << theTranslatorPtr->transientTypeId( )
00032                      << ", persistentTypeName='" << theTranslatorPtr->persistentTypeName( )
00033                      << "', address=" << theTranslatorPtr.get( ) << endl;
00034 
00035   // Check if a translator with the same values of keys doesn't
00036   // already exist in local registries.
00037 
00038     if( !find( theTranslatorPtr->transientTypeId( ),
00039                theTranslatorPtr->persistentTypeName( )).isNull( )) {
00040         CDB_DEBUG_STREAM << context << ": refused because transient already exists." << endl;
00041         return CdbStatus::Error;
00042     }
00043 
00044   // Register the translator
00045 
00046     if( _byTransient.find( theTranslatorPtr->transientTypeId( )) == _byTransient.end( )) {
00047         _byTransient[theTranslatorPtr->transientTypeId( )] = Persistent( );
00048     }
00049     _byTransient[theTranslatorPtr->transientTypeId( )]._byPersistent[theTranslatorPtr->persistentTypeName( )] = theTranslatorPtr;
00050 
00051     CDB_DEBUG_STREAM << context << ": accepted." << endl;
00052 
00053     return CdbStatus::Success;
00054 }
00055 
00056 CdbCPtr< CdbObjectTranslator >
00057 CdbTranslatorsDict::find( unsigned int       theTranseintTypeId,
00058                          const std::string& thePersistentTypeName ) const
00059 {
00060     const char* context =  "CdbTranslatorsDict::find()";
00061 
00062     std::map< unsigned int, CdbTranslatorsDict::Persistent >::const_iterator tItr = _byTransient.find( theTranseintTypeId );
00063     if( tItr == _byTransient.end( )) return 0;
00064 
00065     std::map< std::string, CdbCPtr< CdbObjectTranslator > >::const_iterator pItr = (*tItr).second._byPersistent.find( thePersistentTypeName );
00066     if (pItr != (*tItr).second._byPersistent.end( )) {
00067          CDB_DEBUG_STREAM << context << ": found transientTypeId=" << theTranseintTypeId
00068                           << ", persistentTypeName='" << thePersistentTypeName
00069                           << "', address=" << pItr->second.get( ) << endl;
00070     }
00071     CdbCPtr< CdbObjectTranslator > resultPtr;
00072     if( pItr != (*tItr).second._byPersistent.end( )) resultPtr = (*pItr).second;
00073     return resultPtr;
00074 
00075 // WARNING: The following code seems to cause a memory corruption on SunOS58
00076 //          platform(s). Could be a compiler, optimization or CDB code itself(?) issue.
00077 //
00078 //    return ( pItr == (*tItr).second._byPersistent.end( ) ? 0 : (*pItr).second );
00079 }
00080 
00081 /////////////////
00082 // End Of File //
00083 /////////////////

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