CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondCore/ORA/src/AnyData.h

Go to the documentation of this file.
00001 #ifndef CondCore_ORA_AnyData_H
00002 #define CondCore_ORA_AnyData_H
00003 #include<string>
00004 
00005 namespace ora {
00006   union AnyData {
00007     
00008     // size is 8 byte no matter which architecture
00009     char v[8];
00010     bool b;
00011     char c;
00012     unsigned char uc;
00013     short s;
00014     unsigned short us;
00015     int i;
00016     unsigned int ui;
00017     long long l;
00018     unsigned long long ul;
00019     float f;
00020     double d;
00021     void * p;
00022     char * ss;
00023     // std::string ss;
00024     void * address() { return v;}
00025     void const * address() const { return v;}
00026 
00027     // for generic type T better be the pointer to it...
00028     template<typename T> 
00029     inline T & data() { return *reinterpret_cast<T*>(address());}   
00030 
00031     template<typename T> 
00032     inline T data() const { return *reinterpret_cast<T const*>(address());}   
00033     
00034   };
00035 
00036 
00037     template<> 
00038     inline int & AnyData::data<int>() { return i;}   
00039 
00040     template<> 
00041     inline int AnyData::data<int>() const { return i;}   
00042 
00043 
00044   
00045 }
00046 
00047 #endif //  CondCore_ORA_AnyData_H