| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataTypeInfo.h
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/GaudiKernel/DataTypeInfo.h,v 1.6 2008/10/27 19:22:20 marcocle Exp $
2 #ifndef GAUDIKERNEL_DATATYPES_H
3 #define GAUDIKERNEL_DATATYPES_H
4
5 #include <string>
6 #include <cstring>
7 #include "GaudiKernel/SmartRef.h"
8
9 class DataObject;
10 class ContainedObject;
11 class IOpaqueAddress;
12
17 class GAUDI_API DataTypeInfo {
18 private:
19 // This object cannot be instantiated!
20 DataTypeInfo() {}
21 public:
22 // Accepted Data type definitions
23 enum Type {
24 UNKNOWN = 0,
25 UCHAR, USHORT, UINT, ULONG,
26 CHAR, SHORT, INT, LONG,
27 BOOL, FLOAT, DOUBLE,
28 STRING, NTCHAR,
29 OBJECT_REF, CONTAINED_REF, POINTER, OBJECT_ADDR,
30 LONG_STRING, LONG_NTCHAR, LONGLONG, ULONGLONG
31 };
33 static Type ID( const bool) { return BOOL; }
35 static Type ID( const char) { return CHAR; }
37 static Type ID( const short) { return SHORT; }
39 static Type ID( const int) { return INT; }
41 static Type ID( const long) { return LONG; }
43 static Type ID( const long long) { return LONGLONG; }
45 static Type ID( const unsigned char) { return UCHAR; }
47 static Type ID( const unsigned short) { return USHORT; }
49 static Type ID( const unsigned int) { return UINT; }
51 static Type ID( const unsigned long) { return ULONG; }
53 static Type ID( const unsigned long long) { return ULONGLONG; }
55 static Type ID( const float) { return FLOAT; }
57 static Type ID( const double) { return DOUBLE; }
59 static Type ID( const std::string&) { return STRING; }
61 static Type ID( const char*) { return NTCHAR; }
63 static Type ID( const IOpaqueAddress*) { return OBJECT_ADDR; }
65 static Type ID( const void*) { return POINTER; }
67 static Type ID( const SmartRef<DataObject>&) { return OBJECT_REF; }
69 static Type ID( const SmartRef<ContainedObject>&) { return CONTAINED_REF; }
70
72 static Type ID( const std::type_info& typ ) {
73 if ( typ == typeid(unsigned char) )
74 return UCHAR;
75 else if ( typ == typeid(unsigned short) )
76 return USHORT;
77 else if ( typ == typeid(unsigned int) )
78 return UINT;
79 else if ( typ == typeid(unsigned long) )
80 return ULONG;
81 else if ( typ == typeid(unsigned long long) )
82 return ULONGLONG;
83 else if ( typ == typeid(char) )
84 return CHAR;
85 else if ( typ == typeid(short) )
86 return SHORT;
87 else if ( typ == typeid(int) )
88 return INT;
89 else if ( typ == typeid(long) )
90 return LONG;
91 else if ( typ == typeid(long long) )
92 return LONGLONG;
93 else if ( typ == typeid(bool) )
94 return BOOL;
95 else if ( typ == typeid(float) )
96 return FLOAT;
97 else if ( typ == typeid(double) )
98 return DOUBLE;
99 else if ( typ == typeid(std::string) )
100 return STRING;
101 else if ( typ == typeid(char*) )
102 return NTCHAR;
103 else if ( typ == typeid(SmartRef<DataObject>) )
104 return OBJECT_REF;
105 else if ( typ == typeid(SmartRef<ContainedObject>) )
106 return CONTAINED_REF;
107 else if ( typ == typeid(IOpaqueAddress*) )
108 return OBJECT_ADDR;
109 else if ( typ == typeid(void*) )
110 return POINTER;
111 else
112 return UNKNOWN;
113 }
114
116 static const std::type_info& type( long typ ) {
117 switch(typ) {
118 case UCHAR:
119 return typeid(unsigned char);
120 case USHORT:
121 return typeid(unsigned short);
122 case UINT:
123 return typeid(unsigned int);
124 case ULONG:
125 return typeid(unsigned long);
126 case ULONGLONG:
127 return typeid(unsigned long long);
128 case CHAR:
129 return typeid(char);
130 case SHORT:
131 return typeid(short);
132 case INT:
133 return typeid(int);
134 case LONG:
135 return typeid(long);
136 case LONGLONG:
137 return typeid(long long);
138 case BOOL:
139 return typeid(bool);
140 case FLOAT:
141 return typeid(float);
142 case DOUBLE:
143 return typeid(double);
144 case LONG_STRING:
145 return typeid(std::string);
146 case STRING:
147 return typeid(std::string);
148 case NTCHAR:
149 return typeid(char*);
150 case LONG_NTCHAR:
151 return typeid(char*);
152 case OBJECT_REF:
153 return typeid(SmartRef<DataObject>);
154 case CONTAINED_REF:
155 return typeid(SmartRef<ContainedObject>);
156 case OBJECT_ADDR:
157 return typeid(IOpaqueAddress*);
158 case POINTER:
159 case UNKNOWN:
160 default:
161 return typeid(void*);
162 }
163 }
164
166 static long size( long typ ) {
167 switch(typ) {
168 case UCHAR:
169 return sizeof(unsigned char);
170 case USHORT:
171 return sizeof(unsigned short);
172 case UINT:
173 return sizeof(unsigned int);
174 case ULONG:
175 return sizeof(unsigned long);
176 case ULONGLONG:
177 return sizeof(unsigned long long);
178 case CHAR:
179 return sizeof(char);
180 case SHORT:
181 return sizeof(short);
182 case INT:
183 return sizeof(int);
184 case LONG:
185 return sizeof(long);
186 case LONGLONG:
187 return sizeof(long long);
188 case BOOL:
189 return sizeof(bool);
190 case FLOAT:
191 return sizeof(float);
192 case DOUBLE:
193 return sizeof(double);
194 case STRING:
195 return sizeof(std::string);
196 case LONG_STRING:
197 return sizeof(std::string);
198 case NTCHAR:
199 return sizeof(char*);
200 case LONG_NTCHAR:
201 return sizeof(char*);
202 case OBJECT_ADDR:
203 case POINTER:
204 case OBJECT_REF:
205 case CONTAINED_REF:
206 case UNKNOWN:
207 default:
208 return 0;
209 }
210 }
211
213 static long size( const std::type_info& typ ) {
214 return size( ID(typ) );
215 }
216
218 static int copy( void* tar, const void* src, long typ, int numObj ) {
219 switch(typ) {
220 case UCHAR: numObj *= sizeof(unsigned char); break;
221 case USHORT: numObj *= sizeof(unsigned short); break;
222 case UINT: numObj *= sizeof(unsigned int); break;
223 case ULONG: numObj *= sizeof(unsigned long); break;
224 case ULONGLONG: numObj *= sizeof(unsigned long long); break;
225 case CHAR: numObj *= sizeof(char); break;
226 case SHORT: numObj *= sizeof(short); break;
227 case INT: numObj *= sizeof(int); break;
228 case LONG: numObj *= sizeof(long); break;
229 case LONGLONG: numObj *= sizeof(long long); break;
230 case BOOL: numObj *= sizeof(bool); break;
231 case FLOAT: numObj *= sizeof(float); break;
232 case DOUBLE: numObj *= sizeof(double); break;
233 case UNKNOWN:
234 default: numObj *= 0; break;
235 }
236 memcpy(tar, src, numObj);
237 return numObj;
238 }
239
240 // Access the type name by type ID
241 static std::string name(long typ);
242 // Access the type name by type_info
243 static std::string name(const std::type_info& typ);
245 static Type idByName( const std::string& typ );
247 static const std::type_info& typeByName( const std::string& typ );
248 };
249 #endif // GAUDIKERNEL_DATATYPES_H