00001 #ifndef CDBBDBTABLE_NTUPLE_CONVERSION_RULES_HH 00002 #define CDBBDBTABLE_NTUPLE_CONVERSION_RULES_HH 00003 00004 // File and Version Information: 00005 // $Id: CdbBdbNTupleConversionRules.hh,v 1.3 2005/01/19 10:10:00 gapon Exp $ 00006 00007 #include "BdbUtil/Bdb.hh" // to bring in Objy data types 00008 00009 #include "CdbBase/CdbCommon.hh" 00010 00011 #include <string> 00012 00013 /// The default "persistent/transient" conversion rules for elements of tuples 00014 /** 00015 * This pseudo-converter can be applied for any types of elements. This converter 00016 * is used by default when converting tuples between the transient and persistent 00017 * forms. 00018 * 00019 * The only template parameter of the class is a transient type of elements. 00020 * 00021 * There is also a number of specializations of the facility (see below). They'll 00022 * be used for types requiering nono-trivial conversion or because of lack of 00023 * implicit conversion supplied with the compiler or user classes. 00024 */ 00025 template < class T > 00026 struct CdbBdbNTupleConversionRules_Default { 00027 00028 typedef T Transient; 00029 typedef T Persistent; 00030 00031 static const Persistent& to_persistent( const Transient& value ) { return value; } 00032 static const Transient& to_transient ( const Persistent& value ) { return value; } 00033 }; 00034 00035 /// The default "persistent/transient" conversion rules for elements of tuples (complementary) 00036 /** 00037 * This is a complementary facility whose template parameter is a persistent type of elements. 00038 * This class can be used to derive a persistent type for the specified persistent one, 00039 * when when the actual transient type is not known. 00040 * 00041 * The specializations are also available. 00042 */ 00043 template < class P > 00044 struct CdbBdbNTupleConversionReverseRules_Default { 00045 00046 typedef P Transient; 00047 typedef P Persistent; 00048 00049 static const Persistent& to_persistent( const Transient& value ) { return value; } 00050 static const Transient& to_transient ( const Persistent& value ) { return value; } 00051 }; 00052 00053 /// The specialization for platform dependent "long" type of C++ 00054 /** 00055 * Accordint to Objectivity/DDL documentation the 'long' type is 32 bit 00056 * integer on all platforms except DEC Alpha. And it's 64 bit integer 00057 * on DEC Alpha. 00058 * 00059 * In GNU C++ compiler (at least before and including 2.95.3) the 'long' is typedef-ed 00060 * as 'long int', which would confuse DDL compiler. The DDL won't be able to map 00061 * this type any any of known elementary persistent types of predefined width. 00062 * 00063 * SOLUTION: Map C++ 'long' into DDL 'long long', which is known to DDL as 64 bit type. 00064 */ 00065 template <> 00066 struct CdbBdbNTupleConversionRules_Default<long> { 00067 00068 typedef long Transient; 00069 typedef long long Persistent; 00070 00071 static const Persistent to_persistent( const Transient& value ) { return (Persistent)value; } 00072 static const Transient to_transient ( const Persistent& value ) { return (Transient)value; } 00073 }; 00074 00075 template <> 00076 struct CdbBdbNTupleConversionReverseRules_Default<long long> { 00077 00078 typedef long Transient; 00079 typedef long long Persistent; 00080 00081 static const Persistent to_persistent( const Transient& value ) { return (Persistent)value; } 00082 static const Transient to_transient ( const Persistent& value ) { return (Transient)value; } 00083 }; 00084 00085 /// The specialization for platform dependent "unsigned long" type of C++ 00086 /** 00087 * @see class CdbBdbNTupleConversionRules_Default<long> 00088 */ 00089 template <> 00090 struct CdbBdbNTupleConversionRules_Default<unsigned long> { 00091 00092 typedef unsigned long Transient; 00093 typedef unsigned long long Persistent; 00094 00095 static const Persistent to_persistent( const Transient& value ) { return (Persistent)value; } 00096 static const Transient to_transient ( const Persistent& value ) { return (Transient)value; } 00097 }; 00098 00099 template <> 00100 struct CdbBdbNTupleConversionReverseRules_Default<unsigned long long> { 00101 00102 typedef unsigned long Transient; 00103 typedef unsigned long long Persistent; 00104 00105 static const Persistent to_persistent( const Transient& value ) { return (Persistent)value; } 00106 static const Transient to_transient ( const Persistent& value ) { return (Transient)value; } 00107 }; 00108 00109 /// The specialization for std::string type of C++ 00110 /** 00111 * This class will be used to map STD strings into OO strings to avoid 00112 * any attempts to use STD strings in the persistent schema (which would be a really 00113 * terrible idea given different implementation of STD strings on various compliter/library 00114 * platforms. 00115 */ 00116 template <> 00117 struct CdbBdbNTupleConversionRules_Default< std::string > { 00118 00119 typedef std::string Transient; 00120 typedef ooVString Persistent; 00121 00122 static const ooVString to_persistent( const std::string& value ) { return ooVString ( value.c_str( )); } 00123 static const std::string to_transient ( const ooVString& value ) { return std::string( value.head( )); } 00124 }; 00125 00126 template <> 00127 struct CdbBdbNTupleConversionReverseRules_Default< ooVString > { 00128 00129 typedef std::string Transient; 00130 typedef ooVString Persistent; 00131 00132 static const ooVString to_persistent( const std::string& value ) { return ooVString ( value.c_str( )); } 00133 static const std::string to_transient ( const ooVString& value ) { return std::string( value.head( )); } 00134 }; 00135 00136 /// The non-trivial "persistent/transient" converter for elements of tuples 00137 /** 00138 * This converter will use type cast operator to convert values of elements. 00139 */ 00140 template < class T, 00141 class P > 00142 struct CdbBdbNTupleConversionRules_Explicit { 00143 00144 typedef T Transient; 00145 typedef P Persistent; 00146 00147 static Persistent to_persistent( const Transient& value ) { return (Persistent)value; } 00148 static Transient to_transient ( const Persistent& value ) { return (Transient)value; } 00149 }; 00150 00151 /// A trivial class used to turn on the default element conversion rules 00152 00153 class CdbBdbNTupleConversionRules_UseDefault { 00154 }; 00155 00156 #endif // CDBBDBTABLE_NTUPLE_CONVERSION_RULES_HH 00157
1.3-rc3