DataTypeInfo.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_DATATYPES_H
2 #define GAUDIKERNEL_DATATYPES_H
3 
4 #include <string>
5 #include <cstring>
6 #include "GaudiKernel/SmartRef.h"
7 
8 class DataObject;
9 class ContainedObject;
10 class IOpaqueAddress;
11 
16 class GAUDI_API DataTypeInfo {
17 private:
18  // This object cannot be instantiated!
19  DataTypeInfo() {}
20 public:
21  // Accepted Data type definitions
22  enum Type {
23  UNKNOWN = 0,
24  UCHAR, USHORT, UINT, ULONG,
25  CHAR, SHORT, INT, LONG,
26  BOOL, FLOAT, DOUBLE,
27  STRING, NTCHAR,
28  OBJECT_REF, CONTAINED_REF, POINTER, OBJECT_ADDR,
29  LONG_STRING, LONG_NTCHAR, LONGLONG, ULONGLONG
30  };
32  static Type ID( const bool) { return BOOL; }
34  static Type ID( const char) { return CHAR; }
36  static Type ID( const short) { return SHORT; }
38  static Type ID( const int) { return INT; }
40  static Type ID( const long) { return LONG; }
42  static Type ID( const long long) { return LONGLONG; }
44  static Type ID( const unsigned char) { return UCHAR; }
46  static Type ID( const unsigned short) { return USHORT; }
48  static Type ID( const unsigned int) { return UINT; }
50  static Type ID( const unsigned long) { return ULONG; }
52  static Type ID( const unsigned long long) { return ULONGLONG; }
54  static Type ID( const float) { return FLOAT; }
56  static Type ID( const double) { return DOUBLE; }
58  static Type ID( const std::string&) { return STRING; }
60  static Type ID( const char*) { return NTCHAR; }
62  static Type ID( const IOpaqueAddress*) { return OBJECT_ADDR; }
64  static Type ID( const void*) { return POINTER; }
66  static Type ID( const SmartRef<DataObject>&) { return OBJECT_REF; }
68  static Type ID( const SmartRef<ContainedObject>&) { return CONTAINED_REF; }
69 
71  static Type ID( const std::type_info& typ ) {
72  if ( typ == typeid(unsigned char) )
73  return UCHAR;
74  else if ( typ == typeid(unsigned short) )
75  return USHORT;
76  else if ( typ == typeid(unsigned int) )
77  return UINT;
78  else if ( typ == typeid(unsigned long) )
79  return ULONG;
80  else if ( typ == typeid(unsigned long long) )
81  return ULONGLONG;
82  else if ( typ == typeid(char) )
83  return CHAR;
84  else if ( typ == typeid(short) )
85  return SHORT;
86  else if ( typ == typeid(int) )
87  return INT;
88  else if ( typ == typeid(long) )
89  return LONG;
90  else if ( typ == typeid(long long) )
91  return LONGLONG;
92  else if ( typ == typeid(bool) )
93  return BOOL;
94  else if ( typ == typeid(float) )
95  return FLOAT;
96  else if ( typ == typeid(double) )
97  return DOUBLE;
98  else if ( typ == typeid(std::string) )
99  return STRING;
100  else if ( typ == typeid(char*) )
101  return NTCHAR;
102  else if ( typ == typeid(SmartRef<DataObject>) )
103  return OBJECT_REF;
104  else if ( typ == typeid(SmartRef<ContainedObject>) )
105  return CONTAINED_REF;
106  else if ( typ == typeid(IOpaqueAddress*) )
107  return OBJECT_ADDR;
108  else if ( typ == typeid(void*) )
109  return POINTER;
110  else
111  return UNKNOWN;
112  }
113 
115  static const std::type_info& type( long typ ) {
116  switch(typ) {
117  case UCHAR:
118  return typeid(unsigned char);
119  case USHORT:
120  return typeid(unsigned short);
121  case UINT:
122  return typeid(unsigned int);
123  case ULONG:
124  return typeid(unsigned long);
125  case ULONGLONG:
126  return typeid(unsigned long long);
127  case CHAR:
128  return typeid(char);
129  case SHORT:
130  return typeid(short);
131  case INT:
132  return typeid(int);
133  case LONG:
134  return typeid(long);
135  case LONGLONG:
136  return typeid(long long);
137  case BOOL:
138  return typeid(bool);
139  case FLOAT:
140  return typeid(float);
141  case DOUBLE:
142  return typeid(double);
143  case LONG_STRING:
144  return typeid(std::string);
145  case STRING:
146  return typeid(std::string);
147  case NTCHAR:
148  return typeid(char*);
149  case LONG_NTCHAR:
150  return typeid(char*);
151  case OBJECT_REF:
152  return typeid(SmartRef<DataObject>);
153  case CONTAINED_REF:
154  return typeid(SmartRef<ContainedObject>);
155  case OBJECT_ADDR:
156  return typeid(IOpaqueAddress*);
157  case POINTER:
158  case UNKNOWN:
159  default:
160  return typeid(void*);
161  }
162  }
163 
165  static long size( long typ ) {
166  switch(typ) {
167  case UCHAR:
168  return sizeof(unsigned char);
169  case USHORT:
170  return sizeof(unsigned short);
171  case UINT:
172  return sizeof(unsigned int);
173  case ULONG:
174  return sizeof(unsigned long);
175  case ULONGLONG:
176  return sizeof(unsigned long long);
177  case CHAR:
178  return sizeof(char);
179  case SHORT:
180  return sizeof(short);
181  case INT:
182  return sizeof(int);
183  case LONG:
184  return sizeof(long);
185  case LONGLONG:
186  return sizeof(long long);
187  case BOOL:
188  return sizeof(bool);
189  case FLOAT:
190  return sizeof(float);
191  case DOUBLE:
192  return sizeof(double);
193  case STRING:
194  return sizeof(std::string);
195  case LONG_STRING:
196  return sizeof(std::string);
197  case NTCHAR:
198  return sizeof(char*);
199  case LONG_NTCHAR:
200  return sizeof(char*);
201  case OBJECT_ADDR:
202  case POINTER:
203  case OBJECT_REF:
204  case CONTAINED_REF:
205  case UNKNOWN:
206  default:
207  return 0;
208  }
209  }
210 
212  static long size( const std::type_info& typ ) {
213  return size( ID(typ) );
214  }
215 
217  static int copy( void* tar, const void* src, long typ, int numObj ) {
218  switch(typ) {
219  case UCHAR: numObj *= sizeof(unsigned char); break;
220  case USHORT: numObj *= sizeof(unsigned short); break;
221  case UINT: numObj *= sizeof(unsigned int); break;
222  case ULONG: numObj *= sizeof(unsigned long); break;
223  case ULONGLONG: numObj *= sizeof(unsigned long long); break;
224  case CHAR: numObj *= sizeof(char); break;
225  case SHORT: numObj *= sizeof(short); break;
226  case INT: numObj *= sizeof(int); break;
227  case LONG: numObj *= sizeof(long); break;
228  case LONGLONG: numObj *= sizeof(long long); break;
229  case BOOL: numObj *= sizeof(bool); break;
230  case FLOAT: numObj *= sizeof(float); break;
231  case DOUBLE: numObj *= sizeof(double); break;
232  case UNKNOWN:
233  default: numObj *= 0; break;
234  }
235  memcpy(tar, src, numObj);
236  return numObj;
237  }
238 
239  // Access the type name by type ID
240  static std::string name(long typ);
241  // Access the type name by type_info
242  static std::string name(const std::type_info& typ);
244  static Type idByName( const std::string& typ );
246  static const std::type_info& typeByName( const std::string& typ );
247 };
248 #endif // GAUDIKERNEL_DATATYPES_H
#define GAUDI_API
Definition: Kernel.h:107
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Opaque address interface definition.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
Type
the list of available types for ntuples
Definition: TupleObj.h:73
string type
Definition: gaudirun.py:151
Small class which allows access to internal type IDs.
Definition: DataTypeInfo.h:16