00001 #ifndef CDB_OBJECT_TRANSLATOR_HH 00002 #define CDB_OBJECT_TRANSLATOR_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbObjectTranslator.hh,v 1.1 2005/05/03 20:59:51 gapon Exp $ 00006 00007 #include "CdbBase/CdbType2Id.hh" 00008 #include "CdbBase/CdbObjectPtrFwd.hh" 00009 00010 #include <string> 00011 00012 /// The very base class for persistent-to-transient translators of payload objects 00013 /** 00014 * This class is an element of the "persistent-to-transient" translation facility 00015 * extending the core CDB API and allowing a better (and more confined) controll 00016 * over persistency in client applications. 00017 * 00018 * Roles of this class are: 00019 * 00020 * 1. to represent translators in a dictionary of ones 00021 * 2. to handle the type-independednt context of translators 00022 * 3. to force its subclasses to implement an actual translation procedure 00023 * 4. to provide a type-safe wrapper to the translation procedure 00024 */ 00025 class CdbObjectTranslator { 00026 00027 private: 00028 00029 /// Default constructor (NOT IMPLEMENTED) 00030 00031 CdbObjectTranslator( ); 00032 00033 /// Copy constructor (NOT IMPLEMENTED) 00034 00035 CdbObjectTranslator( const CdbObjectTranslator& ); 00036 00037 /// Assignment operator (NOT IMPLEMENTED) 00038 00039 CdbObjectTranslator& operator=( const CdbObjectTranslator& ); 00040 00041 protected: 00042 00043 /// Normal constructor 00044 00045 CdbObjectTranslator( unsigned int theTransientTypeId, 00046 const std::string& thePersistentTypeName ) : 00047 _transientTypeId (theTransientTypeId), 00048 _persistentTypeName(thePersistentTypeName) 00049 { } 00050 00051 /// Translate into a transient object 00052 /** 00053 * This method is supposed to be implemented by subclasses. In case of its successful 00054 * completion (CdbStatus::Success) it's supposed to set up the supplied reference to 00055 * point onto a new transinet object. The ownership of this object is also returned with 00056 * the object. 00057 * 00058 * DESIGN NOTE: 00059 * 00060 * It's up to the caller of this method to interprete the actual type of 00061 * the returned object. That type is the one corresponding to a value of 00062 * the "transient type identifier" passed to the class's constructor. 00063 * Normally, this method shouldn't be used by users directly. It has to be 00064 * wrrapped into a type-safe ionterface. 00065 * 00066 * @see CdbObjectTranslator::transient() 00067 * 00068 * If the operation, for some, reason should fail then the corresponding error status 00069 * (other than CdbStatus::Success) has to be returned. 00070 */ 00071 virtual CdbStatus toTransient( void*& theTransientPtr, /**< the pointer to be initialized with the result */ 00072 const CdbObjectPtr& theObjectPtr /**< the input metadata object */ 00073 ) const = 0; 00074 public: 00075 00076 /// Destructor 00077 00078 virtual ~CdbObjectTranslator( ) { } 00079 00080 /// Returns a transient type number 00081 00082 unsigned int transientTypeId( ) const { return _transientTypeId; } 00083 00084 /// Returns a transient type number 00085 00086 std::string persistentTypeName( ) const { return _persistentTypeName; } 00087 00088 /// Translate into a transient object (type-safe wrapper) 00089 /** 00090 * The only role of this wrapper is to make sure that 00091 */ 00092 template< class T > 00093 CdbStatus transient( T*& theTransientPtr, /**< the pointer to be initialized with the result */ 00094 const CdbObjectPtr& theObjectPtr /**< the input metadata object */ 00095 ) const 00096 { 00097 if( transientTypeId( ) != CdbType2Id<T>::id( )) return CdbStatus::IllegalParameters; 00098 if( theObjectPtr.isNull( )) return CdbStatus::IllegalParameters; 00099 return toTransient( (void*&)theTransientPtr, 00100 theObjectPtr ); 00101 } 00102 00103 private: 00104 00105 unsigned int _transientTypeId; 00106 std::string _persistentTypeName; 00107 }; 00108 00109 #endif // CDB_OBJECT_TRANSLATOR_HH
1.3-rc3