| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# DataTypeInfo.h

Go to the documentation of this file.

    00001 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/DataTypeInfo.h,v 1.6 2008/10/27 19:22:20 marcocle Exp $
    00002 #ifndef GAUDIKERNEL_DATATYPES_H
    00003 #define GAUDIKERNEL_DATATYPES_H
    00004
    00005 #include <string>
    00006 #include <cstring>
    00007 #include "GaudiKernel/SmartRef.h"
    00008
    00009 class DataObject;
    00010 class ContainedObject;
    00011 class IOpaqueAddress;
    00012
    00017 class GAUDI_API DataTypeInfo {
    00018 private:
    00019   // This object cannot be instantiated!
    00020   DataTypeInfo() {}
    00021 public:
    00022   // Accepted Data type definitions
    00023   enum Type  {
    00024         UNKNOWN = 0,
    00025         UCHAR,        USHORT,        UINT,        ULONG,
    00026         CHAR,         SHORT,         INT,         LONG,
    00027         BOOL,         FLOAT,         DOUBLE,
    00028         STRING,       NTCHAR,
    00029         OBJECT_REF, CONTAINED_REF, POINTER, OBJECT_ADDR,
    00030         LONG_STRING,  LONG_NTCHAR
    00031   };
    00033   static Type ID( const bool)             { return BOOL;          }
    00035   static Type ID( const char)             { return CHAR;          }
    00037   static Type ID( const short)            { return SHORT;         }
    00039   static Type ID( const int)              { return INT;           }
    00041   static Type ID( const long)             { return LONG;          }
    00043   static Type ID( const unsigned char)    { return UCHAR;         }
    00045   static Type ID( const unsigned short)   { return USHORT;        }
    00047   static Type ID( const unsigned int)     { return UINT;          }
    00049   static Type ID( const unsigned long)    { return ULONG;         }
    00051   static Type ID( const float)            { return FLOAT;         }
    00053   static Type ID( const double)           { return DOUBLE;        }
    00055   static Type ID( const std::string&)     { return STRING;        }
    00057   static Type ID( const char*)            { return NTCHAR;        }
    00059   static Type ID( const IOpaqueAddress*)  { return OBJECT_ADDR;   }
    00061   static Type ID( const void*)            { return POINTER;       }
    00063   static Type ID( const SmartRef<DataObject>&)      { return OBJECT_REF;    }
    00065   static Type ID( const SmartRef<ContainedObject>&) { return CONTAINED_REF; }
    00066
    00068   static Type ID( const std::type_info& typ )   {
    00069     if ( typ == typeid(unsigned char) )
    00070       return UCHAR;
    00071     else if ( typ == typeid(unsigned short) )
    00072       return USHORT;
    00073     else if ( typ == typeid(unsigned int) )
    00074       return UINT;
    00075     else if ( typ == typeid(unsigned long) )
    00076       return ULONG;
    00077     else if ( typ == typeid(char) )
    00078       return CHAR;
    00079     else if ( typ == typeid(short) )
    00080       return SHORT;
    00081     else if ( typ == typeid(int) )
    00082       return INT;
    00083     else if ( typ == typeid(long) )
    00084       return LONG;
    00085     else if ( typ == typeid(bool) )
    00086       return BOOL;
    00087     else if ( typ == typeid(float) )
    00088       return FLOAT;
    00089     else if ( typ == typeid(double) )
    00090       return DOUBLE;
    00091     else if ( typ == typeid(std::string) )
    00092       return STRING;
    00093     else if ( typ == typeid(char*) )
    00094       return NTCHAR;
    00095     else if ( typ == typeid(SmartRef<DataObject>) )
    00096       return OBJECT_REF;
    00097     else if ( typ == typeid(SmartRef<ContainedObject>) )
    00098       return CONTAINED_REF;
    00099     else if ( typ == typeid(IOpaqueAddress*) )
    00100       return OBJECT_ADDR;
    00101     else if ( typ == typeid(void*) )
    00102       return POINTER;
    00103     else
    00104       return UNKNOWN;
    00105   }
    00106
    00108   static const std::type_info& type( long typ )   {
    00109     switch(typ)   {
    00110     case UCHAR:
    00111       return typeid(unsigned char);
    00112     case USHORT:
    00113       return typeid(unsigned short);
    00114     case UINT:
    00115       return typeid(unsigned int);
    00116     case ULONG:
    00117       return typeid(unsigned long);
    00118     case CHAR:
    00119       return typeid(char);
    00120     case SHORT:
    00121       return typeid(short);
    00122     case INT:
    00123       return typeid(int);
    00124     case LONG:
    00125       return typeid(long);
    00126     case BOOL:
    00127       return typeid(bool);
    00128     case FLOAT:
    00129       return typeid(float);
    00130     case DOUBLE:
    00131       return typeid(double);
    00132     case LONG_STRING:
    00133       return typeid(std::string);
    00134     case STRING:
    00135       return typeid(std::string);
    00136     case NTCHAR:
    00137       return typeid(char*);
    00138     case LONG_NTCHAR:
    00139       return typeid(char*);
    00140     case OBJECT_REF:
    00141       return typeid(SmartRef<DataObject>);
    00142     case CONTAINED_REF:
    00143       return typeid(SmartRef<ContainedObject>);
    00144     case OBJECT_ADDR:
    00145       return typeid(IOpaqueAddress*);
    00146     case POINTER:
    00147     case UNKNOWN:
    00148     default:
    00149       return typeid(void*);
    00150     }
    00151   }
    00152
    00154   static long size( long typ )   {
    00155     switch(typ)   {
    00156     case UCHAR:
    00157       return sizeof(unsigned char);
    00158     case USHORT:
    00159       return sizeof(unsigned short);
    00160     case UINT:
    00161       return sizeof(unsigned int);
    00162     case ULONG:
    00163       return sizeof(unsigned long);
    00164     case CHAR:
    00165       return sizeof(char);
    00166     case SHORT:
    00167       return sizeof(short);
    00168     case INT:
    00169       return sizeof(int);
    00170     case LONG:
    00171       return sizeof(long);
    00172     case BOOL:
    00173       return sizeof(bool);
    00174     case FLOAT:
    00175       return sizeof(float);
    00176     case DOUBLE:
    00177       return sizeof(double);
    00178     case STRING:
    00179       return sizeof(std::string);
    00180     case LONG_STRING:
    00181       return sizeof(std::string);
    00182     case NTCHAR:
    00183       return sizeof(char*);
    00184     case LONG_NTCHAR:
    00185       return sizeof(char*);
    00186     case OBJECT_ADDR:
    00187     case POINTER:
    00188     case OBJECT_REF:
    00189     case CONTAINED_REF:
    00190     case UNKNOWN:
    00191     default:
    00192       return 0;
    00193     }
    00194   }
    00195
    00197   static long size( const std::type_info& typ )   {
    00198     return size( ID(typ) );
    00199   }
    00200
    00202   static int copy( void* tar, const void* src, long typ, int numObj )   {
    00203     switch(typ)   {
    00204     case UCHAR:      numObj *= sizeof(unsigned char);       break;
    00205     case USHORT:     numObj *= sizeof(unsigned short);      break;
    00206     case UINT:       numObj *= sizeof(unsigned int);        break;
    00207     case ULONG:      numObj *= sizeof(unsigned long);       break;
    00208     case CHAR:       numObj *= sizeof(char);                break;
    00209     case SHORT:      numObj *= sizeof(short);               break;
    00210     case INT:        numObj *= sizeof(int);                 break;
    00211     case LONG:       numObj *= sizeof(long);                break;
    00212     case BOOL:       numObj *= sizeof(bool);                break;
    00213     case FLOAT:      numObj *= sizeof(float);               break;
    00214     case DOUBLE:     numObj *= sizeof(double);              break;
    00215     case UNKNOWN:
    00216     default:         numObj *= 0;                           break;
    00217     }
    00218     memcpy(tar, src, numObj);
    00219     return numObj;
    00220   }
    00221
    00222   // Access the type name by type ID
    00223   static std::string name(long typ);
    00224   // Access the type name by type_info
    00225   static std::string name(const std::type_info& typ);
    00227   static Type idByName( const std::string& typ );
    00229   static const std::type_info& typeByName( const std::string& typ );
    00230 };
    00231 #endif // GAUDIKERNEL_DATATYPES_H