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

CdbBdbNTupleP2T.hh

Go to the documentation of this file.
00001 #ifndef CDBBDBTABLE_NTUPLE_P2T_HH
00002 #define CDBBDBTABLE_NTUPLE_P2T_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbNTupleP2T.hh,v 1.3 2004/08/06 05:54:31 bartoldu Exp $
00006 
00007 #include "CdbBase/CdbObject.hh"
00008 
00009 #include "CdbBdb/CdbBdbObjectConvertor.hh"
00010 
00011 #include "CdbBdbTable/CdbBdbNTupleConversionImpl.hh"
00012 #include "CdbBdbTable/CdbBdbNTupleConversionRules.hh"
00013 
00014 /// A front-end class for "persistent-to-transient" conversion facility
00015 /**
00016   * DESCRIPTION:
00017   *
00018   *   This class is meant to be used as a primary API for user's code who needs
00019   *   to convert a persistent n-tuple into the corresponding transient form.
00020   *   The convertor's design allows to avoid passing explicit template parameters
00021   *   of (both transient and persistent) n-tuples.
00022   *
00023   *   Note that this is a template class having template method(s). The only parameter
00024   *   of the template class is:
00025   *
00026   *     ELEMENT_CONVERSION_RULES
00027   *
00028   *   which is a policy for user defined element conversion. The policy is meant
00029   *   to help in situations when there is no straight-forward mapping between
00030   *   transient and persistent types of elements, or in cases when a user wishes
00031   *   to pack rather small transient types (bit strings, enums, etc.) into
00032   *   bigger persistent elements.
00033   *
00034   *     NOTE: this way of transient-to-persistent and vs. transformation
00035   *           of elements has its own "pros" and "cons".
00036   *
00037   *   By default the conversion facility uses default rules for elements conversion.
00038   *   See class's specialization below.
00039   *
00040   * @see class CdbNTupleConversionImpl
00041   * @see class CdbBdbNTupleConversionRules_UseDefault
00042   * @see class CdbBdbNTupleConversionRules_Default
00043   */
00044 template < class ELEMENT_CONVERSION_RULES = CdbBdbNTupleConversionRules_UseDefault >
00045 class CdbBdbNTupleP2T {
00046 
00047 public:
00048 
00049   /// Try to convert (from a persistent reference)
00050   /**
00051     * @see CdbBdbNTupleConversionImpl::to_transient()
00052     */
00053     template < class        T,
00054                unsigned int NCOL >
00055     static CdbStatus convert( CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00056                               const ooRef(BdbObject)&         thePersRef )
00057     {
00058         return CdbBdbNTupleConversionImpl< T, NCOL, ELEMENT_CONVERSION_RULES >::to_transient( thePtr,
00059                                                                                               thePersRef );
00060     }
00061 
00062   /// Try to convert (from a persistent reference) (regular pointer version)
00063 
00064     template < class        T,
00065                unsigned int NCOL >
00066     static CdbStatus convert( CdbNTuple< T,NCOL >*&   thePtr,
00067                               const ooRef(BdbObject)& thePersRef )
00068     {
00069         return CdbBdbNTupleConversionImpl< T, NCOL, ELEMENT_CONVERSION_RULES >::to_transient( thePtr,
00070                                                                                               thePersRef );
00071     }
00072 
00073   /// Try to convert (from a generic CdbObject)
00074   /**
00075     * Unlike the above defined method this one accepts a smart pointer onto
00076     * a "generic" metadata object representing a persistent object at the level of
00077     * the transient CDB API.
00078     *
00079     * @see CdbBdbNTupleConversionImpl::to_transient()
00080     * @see class CdbBdbObjectConvertor
00081     */
00082     template < class        T,
00083                unsigned int NCOL >
00084     static CdbStatus convert( CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00085                               const CdbObjectPtr&             theObjectPtr )
00086     {
00087         BdbHandle(BdbObject) objectH;
00088         CdbStatus status = CdbBdbObjectConvertor::narrow( objectH,
00089                                                           theObjectPtr );
00090         if( CdbStatus::Success != status ) return status;
00091 
00092         return convert( thePtr,
00093                         objectH );
00094     }
00095 
00096   /// Try to convert (from a generic CdbObject) (regular pointer version)
00097 
00098     template < class        T,
00099                unsigned int NCOL >
00100     static CdbStatus convert( CdbNTuple< T,NCOL >*& thePtr,
00101                               const CdbObjectPtr&   theObjectPtr )
00102     {
00103         BdbHandle(BdbObject) objectH;
00104         CdbStatus status = CdbBdbObjectConvertor::narrow( objectH,
00105                                                           theObjectPtr );
00106         if( CdbStatus::Success != status ) return status;
00107 
00108         return convert( thePtr,
00109                         objectH );
00110     }
00111 };
00112 
00113 /// A specialized version of the above defined conversion class
00114 /**
00115   * This class is used when default conversion rules for alements of
00116   * the class seems to be sufficient. Here is an example of how it can
00117   * be used:
00118   *
00119   *   ooRef(BdbObject)                 pObjectRef;        // A persistent object to be created
00120   *   CdbCPtr< CdbNTuple< float, 3 > > tuplePtr = ...;    // Have a pointer pointing onto an existing tuple
00121   *   BdbRefAny                        hintRef = ...;     // Obtain a placement and clustering hint
00122   *
00123   *   if( CdbStatus::Success != CdbBdbNTupleP2T<>::convert( pObjectRef, tuplePtr, hintRef )) {
00124   *       std::cout << "error: failed to convert a transient n-tuple into a persistent." << std::endl;
00125   *       ...
00126   *   }
00127   *
00128   */
00129 template < >
00130 class CdbBdbNTupleP2T< CdbBdbNTupleConversionRules_UseDefault > {
00131 
00132 public:
00133 
00134 
00135   /// Try to convert (from a persistent reference)
00136  
00137     template < class        T,
00138                unsigned int NCOL >
00139     static CdbStatus convert( CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00140                               const ooRef(BdbObject)&         thePersRef )
00141     {
00142       // Delegate the actual work to the above defined non-specialized version
00143       // of the conversion facility.
00144 
00145         return CdbBdbNTupleP2T< CdbBdbNTupleConversionRules_Default<T> >::convert( thePtr,
00146                                                                                    thePersRef );
00147     }
00148 
00149   /// Try to convert (from a persistent reference) (regular pointer version)
00150  
00151     template < class        T,
00152                unsigned int NCOL >
00153     static CdbStatus convert( CdbNTuple< T,NCOL >*&   thePtr,
00154                               const ooRef(BdbObject)& thePersRef )
00155     {
00156         return CdbBdbNTupleP2T< CdbBdbNTupleConversionRules_Default<T> >::convert( thePtr,
00157                                                                                    thePersRef );
00158     }
00159 
00160   /// Try to convert (from a generic CdbObject)
00161 
00162     template < class        T,
00163                unsigned int NCOL >
00164     static CdbStatus convert( CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00165                               const CdbObjectPtr&             theObjectPtr )
00166     {
00167       // Delegate the actual work to the above defined non-specialized version
00168       // of the conversion facility.
00169 
00170         return CdbBdbNTupleP2T< CdbBdbNTupleConversionRules_Default<T> >::convert( thePtr,
00171                                                                                    theObjectPtr );
00172     }
00173 
00174   /// Try to convert (from a generic CdbObject) (regular pointer version)
00175 
00176     template < class        T,
00177                unsigned int NCOL >
00178     static CdbStatus convert( CdbNTuple< T,NCOL >*& thePtr,
00179                               const CdbObjectPtr&   theObjectPtr )
00180     {
00181         return CdbBdbNTupleP2T< CdbBdbNTupleConversionRules_Default<T> >::convert( thePtr,
00182                                                                                    theObjectPtr );
00183     }
00184 };
00185 
00186 #endif // CDBBDBTABLE_NTUPLE_P2T_HH
00187 

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