DataTypeInfo.cpp
Go to the documentation of this file.
1 // ====================================================================
2 //
3 // DataTypeInfo.cpp
4 // --------------------------------------------------------------------
5 //
6 // Package : Kernel
7 // Data Object types - implementation
8 //
9 // Author : Markus Frank
10 // History:
11 // +---------+----------------------------------------------+---------+
12 // | Date | Comment | Who |
13 // +---------+----------------------------------------------+---------+
14 // | 3/07/00 | Initial version | M.Frank |
15 // +---------+----------------------------------------------+---------+
16 // ====================================================================
17 #define GAUDI_KERNEL_DATATYPEINFO_CPP 1
18 
19 #include "GaudiKernel/System.h"
20 #include "GaudiKernel/DataTypeInfo.h"
21 #include "GaudiKernel/IOpaqueAddress.h"
22 
23 // Access to type information
24 DataTypeInfo::Type DataTypeInfo::idByName( const std::string& typ ) {
25  if ( typ == "unsigned char" || typ == "const unsigned char" )
26  return UCHAR;
27  else if ( typ == "unsigned short" || typ == "const unsigned short" )
28  return USHORT;
29  else if ( typ == "unsigned int" || typ == "const unsigned int" )
30  return UINT;
31  else if ( typ == "unsigned long" || typ == "const unsigned long" )
32  return ULONG;
33  else if ( typ == "char" || typ == "const char" )
34  return CHAR;
35  else if ( typ == "short" || typ == "const short" )
36  return SHORT;
37  else if ( typ == "int" || typ == "const int" )
38  return INT;
39  else if ( typ == "long" || typ == "const long" )
40  return LONG;
41  else if ( typ == "bool" || typ == "const bool" )
42  return BOOL;
43  else if ( typ == "float" || typ == "const float" )
44  return FLOAT;
45  else if ( typ == "double" || typ == "const double" )
46  return DOUBLE;
47  else if ( typ == "std::string" || typ == "const std::string" )
48  return STRING;
49  else if ( typ == "char*" || typ == "const char*" )
50  return NTCHAR;
51  else if ( typ == "IOpaqueAddress*" || typ == "const IOpaqueAddress*" )
52  return OBJECT_ADDR;
53  else if ( typ == "SmartRef<DataObject>" || typ == "const SmartRef<DataObject>" )
54  return OBJECT_REF;
55  else if ( typ == "SmartRef<ContainedObject>" || typ == "const SmartRef<ContainedObject>" )
56  return CONTAINED_REF;
57  else if ( typ == "void*" || typ == "const void*" )
58  return POINTER;
59  else
60  return UNKNOWN;
61 }
62 
63 // Access to type information
64 const std::type_info& DataTypeInfo::typeByName( const std::string& typ ) {
65  if ( typ == "unsigned char" || typ == "const unsigned char" )
66  return typeid(unsigned char);
67  else if ( typ == "unsigned short" || typ == "const unsigned short" )
68  return typeid(unsigned short);
69  else if ( typ == "unsigned int" || typ == "const unsigned int" )
70  return typeid(unsigned int);
71  else if ( typ == "unsigned long" || typ == "const unsigned long" )
72  return typeid(unsigned long);
73  else if ( typ == "char" || typ == "const char" )
74  return typeid(char);
75  else if ( typ == "short" || typ == "const short" )
76  return typeid(short);
77  else if ( typ == "int" || typ == "const int" )
78  return typeid(int);
79  else if ( typ == "long" || typ == "const long" )
80  return typeid(long);
81  else if ( typ == "bool" || typ == "const bool" )
82  return typeid(bool);
83  else if ( typ == "float" || typ == "const float" )
84  return typeid(float);
85  else if ( typ == "double" || typ == "const double" )
86  return typeid(double);
87  else if ( typ == "std::string" || typ == "const std::string" )
88  return typeid(std::string);
89  else if ( typ == "char*" || typ == "const char*" )
90  return typeid(char*);
91  else if ( typ == "IOpaqueAddress*" || typ == "const IOpaqueAddress*" )
92  return typeid(IOpaqueAddress);
93  else if ( typ == "SmartRef<DataObject>" || typ == "const SmartRef<DataObject>" )
94  return typeid(DataObject*);
95  else if ( typ == "SmartRef<ContainedObject>" || typ == "const SmartRef<ContainedObject>" )
96  return typeid(SmartRef<ContainedObject>);
97  else if ( typ == "void*" || typ == "const void*" )
98  return typeid(void*);
99  else
100  return typeid(void*);
101 }
102 
103 // Access the type name by type ID
104 std::string DataTypeInfo::name(long typ) {
105  switch(typ) {
106  case UCHAR:
107  return System::typeinfoName(typeid(unsigned char));
108  case USHORT:
109  return System::typeinfoName(typeid(unsigned short));
110  case UINT:
111  return System::typeinfoName(typeid(unsigned int));
112  case ULONG:
113  return System::typeinfoName(typeid(unsigned long));
114  case CHAR:
115  return System::typeinfoName(typeid(char));
116  case SHORT:
117  return System::typeinfoName(typeid(short));
118  case INT:
119  return System::typeinfoName(typeid(int));
120  case LONG:
121  return System::typeinfoName(typeid(long));
122  case BOOL:
123  return System::typeinfoName(typeid(bool));
124  case FLOAT:
125  return System::typeinfoName(typeid(float));
126  case DOUBLE:
127  return System::typeinfoName(typeid(double));
128  case STRING:
129  return System::typeinfoName(typeid(std::string));
130  case LONG_STRING:
131  return System::typeinfoName(typeid(std::string));
132  case NTCHAR:
133  return System::typeinfoName(typeid(char*));
134  case LONG_NTCHAR:
135  return System::typeinfoName(typeid(char*));
136  case OBJECT_ADDR:
137  return System::typeinfoName(typeid(IOpaqueAddress*));
138  case OBJECT_REF:
140  case CONTAINED_REF:
142  case POINTER:
143  return System::typeinfoName(typeid(void*));
144  case UNKNOWN:
145  default:
146  return "";
147  }
148 }
149 
150 // Access the type name by type_info
151 std::string DataTypeInfo::name(const std::type_info& typ) {
152  if ( typ == typeid(unsigned char) )
153  return DataTypeInfo::name(UCHAR);
154  else if ( typ == typeid(unsigned short) )
155  return DataTypeInfo::name(USHORT);
156  else if ( typ == typeid(unsigned int) )
157  return DataTypeInfo::name(UINT);
158  else if ( typ == typeid(unsigned long) )
159  return DataTypeInfo::name(ULONG);
160  else if ( typ == typeid(char) )
161  return DataTypeInfo::name(CHAR);
162  else if ( typ == typeid(short) )
163  return DataTypeInfo::name(SHORT);
164  else if ( typ == typeid(int) )
165  return DataTypeInfo::name(INT);
166  else if ( typ == typeid(long) )
167  return DataTypeInfo::name(LONG);
168  else if ( typ == typeid(bool) )
169  return DataTypeInfo::name(BOOL);
170  else if ( typ == typeid(float) )
171  return DataTypeInfo::name(FLOAT);
172  else if ( typ == typeid(double) )
173  return DataTypeInfo::name(DOUBLE);
174  else if ( typ == typeid(std::string) )
175  return DataTypeInfo::name(STRING);
176  else if ( typ == typeid(char*) )
177  return DataTypeInfo::name(NTCHAR);
178  else if ( typ == typeid(IOpaqueAddress*) )
180  else if ( typ == typeid(SmartRef<DataObject>) )
182  else if ( typ == typeid(SmartRef<ContainedObject>) )
184  else if ( typ == typeid(void*) )
185  return DataTypeInfo::name(POINTER);
186  else
187  return DataTypeInfo::name(UNKNOWN);
188 }
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:299
static Type idByName(const std::string &typ)
Access to type information.
Opaque address interface definition.
static std::string name(long typ)
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
static const std::type_info & typeByName(const std::string &typ)
Access to type information.