it_bus/reflect/traits.h

00001 #ifndef _IT_REFLECT_REFLECT_TRAITS_H_
00002 #define _IT_REFLECT_REFLECT_TRAITS_H_
00003 
00004 // @Copyright 2004 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 #include <it_bus/reflect/value_ref.h>
00007 #include <it_bus/reflect/complex_value_ref.h>
00008 #include <it_bus/any_simple_type_t.h>
00009 #include <it_bus/types.h>
00010 #include <it_bus/binary_type.h>
00011 #include <it_bus/any_holder.h>
00012 #include <it_bus/any_uri.h>
00013 
00014 namespace IT_Reflect
00015 {
00016     template <class T>
00017     struct Traits
00018     {
00019         typedef typename T::IT_ReflectionType ReflectionType;
00020         
00021         static Reflection*
00022         get_reflection(const T& data)
00023         {
00024             T& non_const = IT_CONST_CAST(T&, data);
00025             return non_const.get_reflection();
00026         }
00027 
00028         static Reflection*
00029         get_reflection(const T* data)
00030         {
00031             if (data == 0)
00032             {
00033                 throw IT_Reflect::ReflectException("Cannot reflect on nil pointer");
00034             }
00035             return get_reflection(*data);
00036         }
00037 
00038         static IT_Bus::AnyType*
00039         clone(const T& data)
00040         {
00041             return new T(data);
00042         }
00043     };
00044 
00045     template<>
00046     struct Traits<IT_Bus::Boolean>
00047     {
00048         typedef IT_Reflect::ValueRef<IT_Bus::Boolean> ReflectionType;
00049 
00050         static Reflection*
00051         get_reflection(const IT_Bus::Boolean& data)
00052         {
00053             return new ReflectionType(data);
00054         }
00055 
00056         static IT_Bus::AnyType*
00057         clone(const IT_Bus::Boolean& data)
00058         {
00059             return new IT_Bus::AnySimpleTypeT<IT_Bus::Boolean>(data);
00060         }
00061     };
00062     
00063     template<>
00064     struct Traits<IT_Bus::Float>
00065     {
00066         typedef IT_Reflect::ValueRef<IT_Bus::Float> ReflectionType;
00067 
00068         static Reflection*
00069         get_reflection(const IT_Bus::Float& data)
00070         {
00071             return new ReflectionType(data);
00072         }
00073 
00074         static IT_Bus::AnyType*
00075         clone(const IT_Bus::Float& data)
00076         {
00077             return new IT_Bus::AnySimpleTypeT<IT_Bus::Float>(data);
00078         }
00079     };
00080 
00081     template<>
00082     struct Traits<IT_Bus::Double>
00083     {
00084         typedef IT_Reflect::ValueRef<IT_Bus::Double> ReflectionType;
00085 
00086         static Reflection*
00087         get_reflection(const IT_Bus::Double& data)
00088         {
00089             return new ReflectionType(data);
00090         }
00091 
00092         static IT_Bus::AnyType*
00093         clone(const IT_Bus::Double& data)
00094         {
00095             return new IT_Bus::AnySimpleTypeT<IT_Bus::Double>(data);
00096         }
00097     };
00098 
00099     template<>
00100     struct Traits<IT_Bus::Int>
00101     {
00102         typedef IT_Reflect::ValueRef<IT_Bus::Int> ReflectionType;
00103 
00104         static Reflection*
00105         get_reflection(const IT_Bus::Int& data)
00106         {
00107             return new ReflectionType(data);
00108         }
00109 
00110         static IT_Bus::AnyType*
00111         clone(const IT_Bus::Int& data)
00112         {
00113             return new IT_Bus::AnySimpleTypeT<IT_Bus::Int>(data);
00114         }
00115     };
00116 
00117     template<>
00118     struct Traits<IT_Bus::UInt>
00119     {
00120         typedef IT_Reflect::ValueRef<IT_Bus::UInt> ReflectionType;
00121 
00122         static Reflection*
00123         get_reflection(const IT_Bus::UInt& data)
00124         {
00125             return new ReflectionType(data);
00126         }
00127 
00128         static IT_Bus::AnyType*
00129         clone(const IT_Bus::UInt& data)
00130         {
00131             return new IT_Bus::AnySimpleTypeT<IT_Bus::UInt>(data);
00132         }
00133     };
00134 
00135     template<>
00136     struct Traits<IT_Bus::Long>
00137     {
00138         typedef IT_Reflect::ValueRef<IT_Bus::Long> ReflectionType;
00139 
00140         static Reflection*
00141         get_reflection(const IT_Bus::Long& data)
00142         {
00143             return new ReflectionType(data);
00144         }
00145 
00146         static IT_Bus::AnyType*
00147         clone(const IT_Bus::Long& data)
00148         {
00149             return new IT_Bus::AnySimpleTypeT<IT_Bus::Long>(data);
00150         }
00151     };
00152 
00153     template<>
00154     struct Traits<IT_Bus::Short>
00155     {
00156         typedef IT_Reflect::ValueRef<IT_Bus::Short> ReflectionType;
00157 
00158         static Reflection*
00159         get_reflection(const IT_Bus::Short& data)
00160         {
00161             return new ReflectionType(data);
00162         }
00163 
00164         static IT_Bus::AnyType*
00165         clone(const IT_Bus::Short& data)
00166         {
00167             return new IT_Bus::AnySimpleTypeT<IT_Bus::Short>(data);
00168         }
00169     };
00170 
00171     template<>
00172     struct Traits<IT_Bus::ULong>
00173     {
00174         typedef IT_Reflect::ValueRef<IT_Bus::ULong> ReflectionType;
00175 
00176         static Reflection*
00177         get_reflection(const IT_Bus::ULong& data)
00178         {
00179             return new ReflectionType(data);
00180         }
00181 
00182         static IT_Bus::AnyType*
00183         clone(const IT_Bus::ULong& data)
00184         {
00185             return new IT_Bus::AnySimpleTypeT<IT_Bus::ULong>(data);
00186         }
00187     };
00188 
00189     template<>
00190     struct Traits<IT_Bus::UShort>
00191     {
00192         typedef IT_Reflect::ValueRef<IT_Bus::UShort> ReflectionType;
00193 
00194         static Reflection*
00195         get_reflection(const IT_Bus::UShort& data)
00196         {
00197             return new ReflectionType(data);
00198         }
00199 
00200         static IT_Bus::AnyType*
00201         clone(const IT_Bus::UShort& data)
00202         {
00203             return new IT_Bus::AnySimpleTypeT<IT_Bus::UShort>(data);
00204         }
00205     };
00206 
00207     template<>
00208     struct Traits<IT_Bus::Byte>
00209     {
00210         typedef IT_Reflect::ValueRef<IT_Bus::Byte> ReflectionType;
00211 
00212         static Reflection*
00213         get_reflection(const IT_Bus::Byte& data)
00214         {
00215             return new ReflectionType(data);
00216         }
00217 
00218         static IT_Bus::AnyType*
00219         clone(const IT_Bus::Byte& data)
00220         {
00221             return new IT_Bus::AnySimpleTypeT<IT_Bus::Byte>(data);
00222         }
00223     };
00224 
00225     template<>
00226     struct Traits<IT_Bus::UByte>
00227     {
00228         typedef IT_Reflect::ValueRef<IT_Bus::UByte> ReflectionType;
00229 
00230         static Reflection*
00231         get_reflection(const IT_Bus::UByte& data)
00232         {
00233             return new ReflectionType(data);
00234         }
00235 
00236         static IT_Bus::AnyType*
00237         clone(const IT_Bus::UByte& data)
00238         {
00239             return new IT_Bus::AnySimpleTypeT<IT_Bus::UByte>(data);
00240         }
00241     };
00242 
00243     template<>
00244     struct Traits<IT_Bus::String>
00245     {
00246         typedef IT_Reflect::ValueRef<IT_Bus::String> ReflectionType;
00247 
00248         static Reflection*
00249         get_reflection(const IT_Bus::String& data)
00250         {
00251             return new ReflectionType(data);
00252         }
00253 
00254         static IT_Bus::AnyType*
00255         clone(const IT_Bus::String& data)
00256         {
00257             return new IT_Bus::AnySimpleTypeT<IT_Bus::String>(data);
00258         }
00259     };
00260 
00261     template<>
00262     struct Traits<IT_Bus::DateTime>
00263     {
00264         typedef IT_Reflect::ValueRef<IT_Bus::DateTime> ReflectionType;
00265 
00266         static Reflection*
00267         get_reflection(const IT_Bus::DateTime& data)
00268         {
00269             return new ReflectionType(data);
00270         }
00271 
00272         static IT_Bus::AnyType*
00273         clone(const IT_Bus::DateTime& data)
00274         {
00275             return new IT_Bus::AnySimpleTypeT<IT_Bus::DateTime>(data);
00276         }
00277     };
00278 
00279     template <>
00280     struct Traits<IT_Bus::Decimal>
00281     {
00282         typedef IT_Reflect::ValueRef<IT_Bus::Decimal> ReflectionType;
00283 
00284         static Reflection*
00285         get_reflection(const IT_Bus::Decimal& data)
00286         {
00287             return new ReflectionType(data);
00288         }
00289 
00290         static IT_Bus::AnyType*
00291         clone(const IT_Bus::Decimal& data)
00292         {
00293             return new IT_Bus::AnySimpleTypeT<IT_Bus::Decimal>(data);
00294         }
00295     };
00296 
00297     template <>
00298     struct Traits<IT_Bus::Base64Binary>
00299     {
00300         typedef IT_Reflect::ValueRef<IT_Bus::Base64Binary> ReflectionType;
00301 
00302         static Reflection*
00303         get_reflection(const IT_Bus::Base64Binary& data)
00304         {
00305             return new ReflectionType(data);
00306         }
00307 
00308         static Reflection*
00309         get_reflection(const IT_Bus::Base64Binary* data)
00310         {
00311             return new ReflectionType(*data);
00312         }
00313 
00314         static IT_Bus::AnyType*
00315         clone(const IT_Bus::Base64Binary& data)
00316         {
00317             return new IT_Bus::AnySimpleTypeT<IT_Bus::Base64Binary>(data);
00318         }
00319     };
00320 
00321     template<>
00322     struct Traits<IT_Bus::HexBinary>
00323     {
00324         typedef IT_Reflect::ValueRef<IT_Bus::HexBinary> ReflectionType;
00325 
00326         static Reflection*
00327         get_reflection(const IT_Bus::HexBinary& data)
00328         {
00329             return new ReflectionType(data);
00330         }
00331 
00332         static Reflection*
00333         get_reflection(const IT_Bus::HexBinary* data)
00334         {
00335             return new ReflectionType(*data);
00336         }
00337 
00338         static IT_Bus::AnyType*
00339         clone(const IT_Bus::HexBinary& data)
00340         {
00341             return new IT_Bus::AnySimpleTypeT<IT_Bus::HexBinary>(data);
00342         }
00343     };
00344 
00345     template<>
00346     struct Traits<IT_Bus::QName>
00347     {
00348         typedef IT_Reflect::ValueRef<IT_Bus::QName> ReflectionType;
00349 
00350         static Reflection*
00351         get_reflection(const IT_Bus::QName& data)
00352         {
00353             return new ReflectionType(data);
00354         }
00355 
00356         static IT_Bus::AnyType*
00357         clone(const IT_Bus::QName& data)
00358         {
00359             return new IT_Bus::AnySimpleTypeT<IT_Bus::QName>(data);
00360         }
00361     };
00362 
00363     template<>
00364     struct Traits<IT_Bus::AnyHolder>
00365     {
00366         typedef IT_Reflect::ComplexValueRef<IT_Bus::AnyHolder> ReflectionType;
00367 
00368         static Reflection*
00369         get_reflection(const IT_Bus::AnyHolder& data)
00370         {
00371             return new ReflectionType(data);
00372         }
00373 
00374         static IT_Bus::AnyType*
00375         clone(const IT_Bus::AnyHolder& data)
00376         {
00377             return new IT_Bus::AnyHolder(data);
00378         }
00379     };
00380 }
00381 
00382 #endif  

Generated on Tue Mar 20 15:27:43 2007 for Artix by  doxygen 1.5.1-p1