File indexing completed on 2025-01-30 10:07:12
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_DATATYPES_H
0012 #define GAUDIKERNEL_DATATYPES_H
0013
0014 #include "GaudiKernel/SmartRef.h"
0015 #include <cstring>
0016 #include <string>
0017
0018 class DataObject;
0019 class ContainedObject;
0020 class IOpaqueAddress;
0021
0022
0023
0024
0025
0026 class GAUDI_API DataTypeInfo {
0027 private:
0028
0029 DataTypeInfo() {}
0030
0031 public:
0032
0033 enum Type {
0034 UNKNOWN = 0,
0035 UCHAR,
0036 USHORT,
0037 UINT,
0038 ULONG,
0039 CHAR,
0040 SHORT,
0041 INT,
0042 LONG,
0043 BOOL,
0044 FLOAT,
0045 DOUBLE,
0046 STRING,
0047 NTCHAR,
0048 OBJECT_REF,
0049 CONTAINED_REF,
0050 POINTER,
0051 OBJECT_ADDR,
0052 LONG_STRING,
0053 LONG_NTCHAR,
0054 LONGLONG,
0055 ULONGLONG
0056 };
0057
0058 static Type ID( const bool ) { return BOOL; }
0059
0060 static Type ID( const char ) { return CHAR; }
0061
0062 static Type ID( const short ) { return SHORT; }
0063
0064 static Type ID( const int ) { return INT; }
0065
0066 static Type ID( const long ) { return LONG; }
0067
0068 static Type ID( const long long ) { return LONGLONG; }
0069
0070 static Type ID( const unsigned char ) { return UCHAR; }
0071
0072 static Type ID( const unsigned short ) { return USHORT; }
0073
0074 static Type ID( const unsigned int ) { return UINT; }
0075
0076 static Type ID( const unsigned long ) { return ULONG; }
0077
0078 static Type ID( const unsigned long long ) { return ULONGLONG; }
0079
0080 static Type ID( const float ) { return FLOAT; }
0081
0082 static Type ID( const double ) { return DOUBLE; }
0083
0084 static Type ID( const std::string& ) { return STRING; }
0085
0086 static Type ID( const char* ) { return NTCHAR; }
0087
0088 static Type ID( const IOpaqueAddress* ) { return OBJECT_ADDR; }
0089
0090 static Type ID( const void* ) { return POINTER; }
0091
0092 static Type ID( const SmartRef<DataObject>& ) { return OBJECT_REF; }
0093
0094 static Type ID( const SmartRef<ContainedObject>& ) { return CONTAINED_REF; }
0095
0096
0097 static Type ID( const std::type_info& typ ) {
0098 if ( typ == typeid( unsigned char ) )
0099 return UCHAR;
0100 else if ( typ == typeid( unsigned short ) )
0101 return USHORT;
0102 else if ( typ == typeid( unsigned int ) )
0103 return UINT;
0104 else if ( typ == typeid( unsigned long ) )
0105 return ULONG;
0106 else if ( typ == typeid( unsigned long long ) )
0107 return ULONGLONG;
0108 else if ( typ == typeid( char ) )
0109 return CHAR;
0110 else if ( typ == typeid( short ) )
0111 return SHORT;
0112 else if ( typ == typeid( int ) )
0113 return INT;
0114 else if ( typ == typeid( long ) )
0115 return LONG;
0116 else if ( typ == typeid( long long ) )
0117 return LONGLONG;
0118 else if ( typ == typeid( bool ) )
0119 return BOOL;
0120 else if ( typ == typeid( float ) )
0121 return FLOAT;
0122 else if ( typ == typeid( double ) )
0123 return DOUBLE;
0124 else if ( typ == typeid( std::string ) )
0125 return STRING;
0126 else if ( typ == typeid( char* ) )
0127 return NTCHAR;
0128 else if ( typ == typeid( SmartRef<DataObject> ) )
0129 return OBJECT_REF;
0130 else if ( typ == typeid( SmartRef<ContainedObject> ) )
0131 return CONTAINED_REF;
0132 else if ( typ == typeid( IOpaqueAddress* ) )
0133 return OBJECT_ADDR;
0134 else if ( typ == typeid( void* ) )
0135 return POINTER;
0136 else
0137 return UNKNOWN;
0138 }
0139
0140
0141 static const std::type_info& type( long typ ) {
0142 switch ( typ ) {
0143 case UCHAR:
0144 return typeid( unsigned char );
0145 case USHORT:
0146 return typeid( unsigned short );
0147 case UINT:
0148 return typeid( unsigned int );
0149 case ULONG:
0150 return typeid( unsigned long );
0151 case ULONGLONG:
0152 return typeid( unsigned long long );
0153 case CHAR:
0154 return typeid( char );
0155 case SHORT:
0156 return typeid( short );
0157 case INT:
0158 return typeid( int );
0159 case LONG:
0160 return typeid( long );
0161 case LONGLONG:
0162 return typeid( long long );
0163 case BOOL:
0164 return typeid( bool );
0165 case FLOAT:
0166 return typeid( float );
0167 case DOUBLE:
0168 return typeid( double );
0169 case LONG_STRING:
0170 return typeid( std::string );
0171 case STRING:
0172 return typeid( std::string );
0173 case NTCHAR:
0174 return typeid( char* );
0175 case LONG_NTCHAR:
0176 return typeid( char* );
0177 case OBJECT_REF:
0178 return typeid( SmartRef<DataObject> );
0179 case CONTAINED_REF:
0180 return typeid( SmartRef<ContainedObject> );
0181 case OBJECT_ADDR:
0182 return typeid( IOpaqueAddress* );
0183 case POINTER:
0184 case UNKNOWN:
0185 default:
0186 return typeid( void* );
0187 }
0188 }
0189
0190
0191 static long size( long typ ) {
0192 switch ( typ ) {
0193 case UCHAR:
0194 return sizeof( unsigned char );
0195 case USHORT:
0196 return sizeof( unsigned short );
0197 case UINT:
0198 return sizeof( unsigned int );
0199 case ULONG:
0200 return sizeof( unsigned long );
0201 case ULONGLONG:
0202 return sizeof( unsigned long long );
0203 case CHAR:
0204 return sizeof( char );
0205 case SHORT:
0206 return sizeof( short );
0207 case INT:
0208 return sizeof( int );
0209 case LONG:
0210 return sizeof( long );
0211 case LONGLONG:
0212 return sizeof( long long );
0213 case BOOL:
0214 return sizeof( bool );
0215 case FLOAT:
0216 return sizeof( float );
0217 case DOUBLE:
0218 return sizeof( double );
0219 case STRING:
0220 return sizeof( std::string );
0221 case LONG_STRING:
0222 return sizeof( std::string );
0223 case NTCHAR:
0224 return sizeof( char* );
0225 case LONG_NTCHAR:
0226 return sizeof( char* );
0227 case OBJECT_ADDR:
0228 case POINTER:
0229 case OBJECT_REF:
0230 case CONTAINED_REF:
0231 case UNKNOWN:
0232 default:
0233 return 0;
0234 }
0235 }
0236
0237
0238 static long size( const std::type_info& typ ) { return size( ID( typ ) ); }
0239
0240
0241 static int copy( void* tar, const void* src, long typ, int numObj ) {
0242 switch ( typ ) {
0243 case UCHAR:
0244 numObj *= sizeof( unsigned char );
0245 break;
0246 case USHORT:
0247 numObj *= sizeof( unsigned short );
0248 break;
0249 case UINT:
0250 numObj *= sizeof( unsigned int );
0251 break;
0252 case ULONG:
0253 numObj *= sizeof( unsigned long );
0254 break;
0255 case ULONGLONG:
0256 numObj *= sizeof( unsigned long long );
0257 break;
0258 case CHAR:
0259 numObj *= sizeof( char );
0260 break;
0261 case SHORT:
0262 numObj *= sizeof( short );
0263 break;
0264 case INT:
0265 numObj *= sizeof( int );
0266 break;
0267 case LONG:
0268 numObj *= sizeof( long );
0269 break;
0270 case LONGLONG:
0271 numObj *= sizeof( long long );
0272 break;
0273 case BOOL:
0274 numObj *= sizeof( bool );
0275 break;
0276 case FLOAT:
0277 numObj *= sizeof( float );
0278 break;
0279 case DOUBLE:
0280 numObj *= sizeof( double );
0281 break;
0282 case UNKNOWN:
0283 default:
0284 numObj *= 0;
0285 break;
0286 }
0287 memcpy( tar, src, numObj );
0288 return numObj;
0289 }
0290
0291
0292 static std::string name( long typ );
0293
0294 static std::string name( const std::type_info& typ );
0295
0296 static Type idByName( const std::string& typ );
0297
0298 static const std::type_info& typeByName( const std::string& typ );
0299 };
0300 #endif