The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
DataTypeInfo.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12
14#include <cstring>
15#include <string>
16
17class DataObject;
18class ContainedObject;
19class IOpaqueAddress;
20
26private:
27 // This object cannot be instantiated!
29
30public:
31 // Accepted Data type definitions
56
57 static Type ID( const bool ) { return BOOL; }
59 static Type ID( const char ) { return CHAR; }
61 static Type ID( const short ) { return SHORT; }
63 static Type ID( const int ) { return INT; }
65 static Type ID( const long ) { return LONG; }
67 static Type ID( const long long ) { return LONGLONG; }
69 static Type ID( const unsigned char ) { return UCHAR; }
71 static Type ID( const unsigned short ) { return USHORT; }
73 static Type ID( const unsigned int ) { return UINT; }
75 static Type ID( const unsigned long ) { return ULONG; }
77 static Type ID( const unsigned long long ) { return ULONGLONG; }
79 static Type ID( const float ) { return FLOAT; }
81 static Type ID( const double ) { return DOUBLE; }
83 static Type ID( const std::string& ) { return STRING; }
85 static Type ID( const char* ) { return NTCHAR; }
87 static Type ID( const IOpaqueAddress* ) { return OBJECT_ADDR; }
89 static Type ID( const void* ) { return POINTER; }
91 static Type ID( const SmartRef<DataObject>& ) { return OBJECT_REF; }
93 static Type ID( const SmartRef<ContainedObject>& ) { return CONTAINED_REF; }
94
96 static Type ID( const std::type_info& typ ) {
97 if ( typ == typeid( unsigned char ) )
98 return UCHAR;
99 else if ( typ == typeid( unsigned short ) )
100 return USHORT;
101 else if ( typ == typeid( unsigned int ) )
102 return UINT;
103 else if ( typ == typeid( unsigned long ) )
104 return ULONG;
105 else if ( typ == typeid( unsigned long long ) )
106 return ULONGLONG;
107 else if ( typ == typeid( char ) )
108 return CHAR;
109 else if ( typ == typeid( short ) )
110 return SHORT;
111 else if ( typ == typeid( int ) )
112 return INT;
113 else if ( typ == typeid( long ) )
114 return LONG;
115 else if ( typ == typeid( long long ) )
116 return LONGLONG;
117 else if ( typ == typeid( bool ) )
118 return BOOL;
119 else if ( typ == typeid( float ) )
120 return FLOAT;
121 else if ( typ == typeid( double ) )
122 return DOUBLE;
123 else if ( typ == typeid( std::string ) )
124 return STRING;
125 else if ( typ == typeid( char* ) )
126 return NTCHAR;
127 else if ( typ == typeid( SmartRef<DataObject> ) )
128 return OBJECT_REF;
129 else if ( typ == typeid( SmartRef<ContainedObject> ) )
130 return CONTAINED_REF;
131 else if ( typ == typeid( IOpaqueAddress* ) )
132 return OBJECT_ADDR;
133 else if ( typ == typeid( void* ) )
134 return POINTER;
135 else
136 return UNKNOWN;
137 }
138
140 static const std::type_info& type( long typ ) {
141 switch ( typ ) {
142 case UCHAR:
143 return typeid( unsigned char );
144 case USHORT:
145 return typeid( unsigned short );
146 case UINT:
147 return typeid( unsigned int );
148 case ULONG:
149 return typeid( unsigned long );
150 case ULONGLONG:
151 return typeid( unsigned long long );
152 case CHAR:
153 return typeid( char );
154 case SHORT:
155 return typeid( short );
156 case INT:
157 return typeid( int );
158 case LONG:
159 return typeid( long );
160 case LONGLONG:
161 return typeid( long long );
162 case BOOL:
163 return typeid( bool );
164 case FLOAT:
165 return typeid( float );
166 case DOUBLE:
167 return typeid( double );
168 case LONG_STRING:
169 return typeid( std::string );
170 case STRING:
171 return typeid( std::string );
172 case NTCHAR:
173 return typeid( char* );
174 case LONG_NTCHAR:
175 return typeid( char* );
176 case OBJECT_REF:
177 return typeid( SmartRef<DataObject> );
178 case CONTAINED_REF:
179 return typeid( SmartRef<ContainedObject> );
180 case OBJECT_ADDR:
181 return typeid( IOpaqueAddress* );
182 case POINTER:
183 case UNKNOWN:
184 default:
185 return typeid( void* );
186 }
187 }
188
190 static long size( long typ ) {
191 switch ( typ ) {
192 case UCHAR:
193 return sizeof( unsigned char );
194 case USHORT:
195 return sizeof( unsigned short );
196 case UINT:
197 return sizeof( unsigned int );
198 case ULONG:
199 return sizeof( unsigned long );
200 case ULONGLONG:
201 return sizeof( unsigned long long );
202 case CHAR:
203 return sizeof( char );
204 case SHORT:
205 return sizeof( short );
206 case INT:
207 return sizeof( int );
208 case LONG:
209 return sizeof( long );
210 case LONGLONG:
211 return sizeof( long long );
212 case BOOL:
213 return sizeof( bool );
214 case FLOAT:
215 return sizeof( float );
216 case DOUBLE:
217 return sizeof( double );
218 case STRING:
219 return sizeof( std::string );
220 case LONG_STRING:
221 return sizeof( std::string );
222 case NTCHAR:
223 return sizeof( char* );
224 case LONG_NTCHAR:
225 return sizeof( char* );
226 case OBJECT_ADDR:
227 case POINTER:
228 case OBJECT_REF:
229 case CONTAINED_REF:
230 case UNKNOWN:
231 default:
232 return 0;
233 }
234 }
235
237 static long size( const std::type_info& typ ) { return size( ID( typ ) ); }
238
240 static int copy( void* tar, const void* src, long typ, int numObj ) {
241 switch ( typ ) {
242 case UCHAR:
243 numObj *= sizeof( unsigned char );
244 break;
245 case USHORT:
246 numObj *= sizeof( unsigned short );
247 break;
248 case UINT:
249 numObj *= sizeof( unsigned int );
250 break;
251 case ULONG:
252 numObj *= sizeof( unsigned long );
253 break;
254 case ULONGLONG:
255 numObj *= sizeof( unsigned long long );
256 break;
257 case CHAR:
258 numObj *= sizeof( char );
259 break;
260 case SHORT:
261 numObj *= sizeof( short );
262 break;
263 case INT:
264 numObj *= sizeof( int );
265 break;
266 case LONG:
267 numObj *= sizeof( long );
268 break;
269 case LONGLONG:
270 numObj *= sizeof( long long );
271 break;
272 case BOOL:
273 numObj *= sizeof( bool );
274 break;
275 case FLOAT:
276 numObj *= sizeof( float );
277 break;
278 case DOUBLE:
279 numObj *= sizeof( double );
280 break;
281 case UNKNOWN:
282 default:
283 numObj *= 0;
284 break;
285 }
286 memcpy( tar, src, numObj );
287 return numObj;
288 }
289
290 // Access the type name by type ID
291 static std::string name( long typ );
292 // Access the type name by type_info
293 static std::string name( const std::type_info& typ );
295 static Type idByName( const std::string& typ );
297 static const std::type_info& typeByName( const std::string& typ );
298};
#define GAUDI_API
Definition Kernel.h:49
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
static Type ID(const long long)
Access to type information: long long.
static Type ID(const std::type_info &typ)
Access to type information: the reverse way.
static Type ID(const unsigned short)
Access to type information: unsigned short.
static Type ID(const unsigned long long)
Access to type information: unsigned long long.
static Type ID(const bool)
Access to type information: bool.
static const std::type_info & type(long typ)
Access to type information: the reverse way.
static Type ID(const unsigned char)
Access to type information: unsigned char.
static long size(const std::type_info &typ)
Access to type information: the reverse way.
static Type ID(const void *)
Access to type information: Pointers.
static Type ID(const short)
Access to type information: short.
static Type ID(const char *)
Access to type information: char* (NULL terminated).
static Type ID(const long)
Access to type information: long.
static Type ID(const IOpaqueAddress *)
Access to type information: IOpaqueAddress.
static int copy(void *tar, const void *src, long typ, int numObj)
Copy data.
static Type ID(const unsigned int)
Access to type information: unsigned int.
static Type ID(const SmartRef< ContainedObject > &)
Access to type information: Contained object.
static Type ID(const SmartRef< DataObject > &)
Access to type information: DataObject.
static Type ID(const int)
Access to type information: int.
static Type ID(const unsigned long)
Access to type information: unsigned long.
static Type ID(const double)
Access to type information: float.
static Type ID(const std::string &)
Access to type information: std::string.
static long size(long typ)
Access to type information: the reverse way.
static Type ID(const float)
Access to type information: float.
static Type ID(const char)
Access to type information: char.
Opaque address interface definition.
Kernel objects: SmartRef.
Definition SmartRef.h:64