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

CdbBdbNTupleT2P.hh

Go to the documentation of this file.
00001 #ifndef CDBBDBTABLE_NTUPLE_T2P_HH
00002 #define CDBBDBTABLE_NTUPLE_T2P_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbBdbNTupleT2P.hh,v 1.2 2004/08/06 05:54:31 bartoldu Exp $
00006 
00007 #include "CdbBdbTable/CdbBdbNTupleConversionImpl.hh"
00008 #include "CdbBdbTable/CdbBdbNTupleConversionRules.hh"
00009 
00010 /// A front-end class for "transient-to-persistent" conversion facility
00011 /**
00012   * DESCRIPTION:
00013   *
00014   *   This class is meant to be used as a primary API for user's code who needs
00015   *   to convert a transient n-tuple into the corresponding persistent form.
00016   *   The convertor's design allows to avoid passing explicit template parameters
00017   *   of (both transient and persistent) n-tuples.
00018   *
00019   *   Note that this is a template class having template method(s). The only parameter
00020   *   of the template class is:
00021   *
00022   *     ELEMENT_CONVERSION_RULES
00023   *
00024   *   which is a policy for user defined element conversion. The policy is meant
00025   *   to help in situations when there is no straight-forward mapping between
00026   *   transient and persistent types of elements, or in cases when a user wishes
00027   *   to pack rather small transient types (bit strings, enums, etc.) into
00028   *   bigger persistent elements.
00029   *
00030   *     NOTE: this way of transient-to-persistent and vs. transformation
00031   *           of elements has its own "pros" and "cons".
00032   *
00033   *   By default the conversion facility uses default rules for elements conversion.
00034   *   See class's specialization below.
00035   *
00036   * @see class CdbNTupleConversionImpl
00037   * @see class CdbBdbNTupleConversionRules_UseDefault
00038   * @see class CdbBdbNTupleConversionRules_Default
00039   */
00040 template < class ELEMENT_CONVERSION_RULES = CdbBdbNTupleConversionRules_UseDefault >
00041 class CdbBdbNTupleT2P {
00042 
00043 public:
00044 
00045   /// Try to convert
00046   /**
00047     * @see CdbBdbNTupleConversionImpl::to_persistent()
00048     */
00049     template < class        T,
00050                unsigned int NCOL >
00051     static CdbStatus convert( ooRef(BdbObject)&                     thePersRef,
00052                               const CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00053                               const BdbRefAny&                      theHintRef )
00054     {
00055         return CdbBdbNTupleConversionImpl< T, NCOL, ELEMENT_CONVERSION_RULES >::to_persistent( thePersRef,
00056                                                                                                thePtr,
00057                                                                                                theHintRef );
00058     }
00059 };
00060 
00061 /// A specialized version of the above defined conversion class
00062 /**
00063   * This class is used when default conversion rules for alements of
00064   * the class seems to be sufficient. Here is an example of how it can
00065   * be used:
00066   *
00067   *   ooRef(BdbObject)                 pObjectRef;        // A persistent object to be created
00068   *   CdbCPtr< CdbNTuple< float, 3 > > tuplePtr = ...;    // Have a pointer pointing onto an existing tuple
00069   *   BdbRefAny                        hintRef = ...;     // Obtain a placement and clustering hint
00070   *
00071   *   if( CdbStatus::Success != CdbBdbNTupleT2P<>::convert( pObjectRef, tuplePtr, hintRef )) {
00072   *       std::cout << "error: failed to convert a transient n-tuple into a persistent." << std::endl;
00073   *       ...
00074   *   }
00075   *
00076   */
00077 template < >
00078 class CdbBdbNTupleT2P< CdbBdbNTupleConversionRules_UseDefault > {
00079 
00080 public:
00081 
00082   /// Try to convert
00083   /**
00084     * @see CdbBdbNTupleConversionImpl::to_persistent()
00085     */
00086     template < class        T,
00087                unsigned int NCOL >
00088     static CdbStatus convert( ooRef(BdbObject)&                     thePersRef,
00089                               const CdbCPtr< CdbNTuple< T,NCOL > >& thePtr,
00090                               const BdbRefAny&                      theHintRef )
00091     {
00092       // Delegate the actual work to the above defined non-specialized version
00093       // of the conversion facility.
00094 
00095         return CdbBdbNTupleT2P<  CdbBdbNTupleConversionRules_Default<T> >::convert( thePersRef,
00096                                                                                     thePtr,
00097                                                                                     theHintRef );
00098     }
00099 };
00100 
00101 #endif // CDBBDBTABLE_NTUPLE_T2P_HH
00102 

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