CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ClassUtils.cc
Go to the documentation of this file.
5 #include "ClassUtils.h"
6 //
7 #include <cxxabi.h>
8 // externals
9 #include "Reflex/Object.h"
10 #include "Reflex/Base.h"
11 
13  m_type( type ){
14 }
15 
17  m_type( rhs.m_type ){
18 }
19 
21 }
22 
23 void ora::RflxDeleter::operator()( void* ptr ){
24  m_type.Destruct( ptr );
25 }
26 
28  static std::string const prefix("LCGReflex/");
29  edmplugin::PluginCapabilities::get()->load(prefix + className);
30 }
31 
33  void* ptr,
34  const Reflex::Type& castType ){
35  void* ret = 0;
36  if( type == castType ){
37  ret = ptr;
38  } else if( type.HasBase( castType )){
39  Reflex::Object theObj( type, ptr );
40  ret = theObj.CastObject( castType ).Address();
41  }
42  return ret;
43 }
44 
46  const Reflex::Type& baseType ){
47  bool ret = false;
48  if( type == baseType || type.HasBase( baseType )){
49  ret = true;
50  }
51  return ret;
52 }
53 
55  const std::string& mappedTypeName ){
56  if( isTypeString( type ) ){
57  return (mappedTypeName=="std::basic_string<char>" || mappedTypeName=="basic_string<char>" || mappedTypeName=="std::string" || mappedTypeName=="string");
58  } else if ( type.IsEnum() ){
59  return mappedTypeName=="int";
60  } else if ( isTypeOraVector( type ) ){
61  return isTypeNameOraVector( mappedTypeName );
62  } else {
63  return type.Name(Reflex::SCOPED)==mappedTypeName;
64  }
65 }
66 
67 bool ora::ClassUtils::findBaseType( Reflex::Type& type, Reflex::Type& baseType, Reflex::OffsetFunction& func ){
68  bool found = false;
69  for ( unsigned int i=0;i<type.BaseSize() && !found; i++){
70  Reflex::Base base = type.BaseAt(i);
71  Reflex::Type bt = resolvedType( base.ToType() );
72  if( bt == baseType ){
73  func = base.OffsetFP();
74  found = true;
75  } else {
76  found = findBaseType( bt, baseType, func );
77  }
78  }
79  return found;
80 }
81 
82 std::string ora::ClassUtils::demangledName( const std::type_info& typeInfo ){
83  int status = 0;
84  std::string ret("");
85  char* realname = abi::__cxa_demangle( typeInfo.name(), 0, 0, &status);
86  if( status == 0 && realname ){
87  ret = realname;
88  free(realname);
89  }
90  return ret;
91 }
92 
93 Reflex::Type ora::ClassUtils::lookupDictionary( const std::type_info& typeInfo, bool throwFlag ){
94  Reflex::Type type = Reflex::Type::ByTypeInfo( typeInfo );
95  if( typeInfo == typeid(std::string) ){
96  // ugly, but no other way with Reflex...
97  type = Reflex::Type::ByName("std::string");
98  }
99  if( !type ){
100  loadDictionary( demangledName(typeInfo) );
101  type = Reflex::Type::ByTypeInfo( typeInfo );
102  }
103  if( !type && throwFlag ){
104  throwException( "Class \""+demangledName(typeInfo)+"\" has not been found in the dictionary.",
105  "ClassUtils::lookupDictionary" );
106  }
107  return type;
108 }
109 
111  Reflex::Type type = Reflex::Type::ByName( className );
112  if( className == "std::basic_string<char>" ){
113  // ugly, but no other way with Reflex...
114  type = Reflex::Type::ByName("std::string");
115  }
116  if( !type ){
117  loadDictionary( className );
118  type = Reflex::Type::ByName( className );
119  }
120  if( !type && throwFlag ){
121  throwException( "Class \""+className+"\" has not been found in the dictionary.",
122  "ClassUtils::lookupDictionary" );
123  }
124  return type;
125 }
126 
128  void* ptr = 0;
129  if( typ.Name(Reflex::SCOPED)=="std::string"){
130  ptr = new std::string("");
131  } else {
132  ptr = typ.Construct().Address();
133  }
134  return ptr;
135 }
136 
138  std::string name = typ.Name(Reflex::SCOPED|Reflex::FINAL);
139  return ( name == "std::string" ||
140  name == "std::basic_string<char>" );
141 }
142 
144  return ( typ.IsFundamental() || typ.IsEnum() || isTypeString( typ ) );
145 }
146 
148  Reflex::TypeTemplate templ = typ.TemplateFamily();
149  if (! templ) {
150  return false;
151  } else {
152  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
153  if( contName == "std::vector" ||
154  contName == "std::list" ||
155  contName == "std::deque" ||
156  contName == "std::stack" ||
157  contName == "std::set" ||
158  contName == "std::multiset" ||
159  contName == "__gnu_cxx::hash_set" ||
160  contName == "__gnu_cxx::hash_multiset" ||
161  contName == "std::map" ||
162  contName == "std::multimap" ||
163  contName == "__gnu_cxx::hash_map" ||
164  contName == "__gnu_cxx::hash_multimap" ||
165  contName == "ora::PVector" ||
166  contName == "ora::QueryableVector" ){
167  return true;
168  }
169  }
170  return false;
171 }
172 
174  Reflex::TypeTemplate tt = typ.TemplateFamily();
175  if (! tt) {
176  return false;
177  } else {
178  std::string contName = tt.Name(Reflex::SCOPED|Reflex::FINAL);
179  if( contName == "std::map" ||
180  contName == "std::multimap" ||
181  contName == "std::set" ||
182  contName == "std::multiset" ||
183  contName == "__gnu_cxx::hash_set" ||
184  contName == "__gnu_cxx::hash_multiset" ||
185  contName == "__gnu_cxx::hash_map" ||
186  contName == "__gnu_cxx::hash_multimap" ){
187  return true;
188  }
189  }
190  return false;
191 }
192 
194  Reflex::TypeTemplate templ = typ.TemplateFamily();
195  if (! templ) {
196  return false;
197  } else {
198  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
199  if( contName == "std::vector" ||
200  contName == "std::list" ||
201  contName == "std::deque" ||
202  contName == "std::stack" ||
203  contName == "ora::PVector" ||
204  contName == "ora::QueryableVector" ){
205  return true;
206  }
207  }
208  return false;
209 }
210 
212  Reflex::TypeTemplate tt = typ.TemplateFamily();
213  if (! tt) {
214  return false;
215  } else {
216  std::string contName = tt.Name(Reflex::SCOPED|Reflex::FINAL);
217  if( contName == "std::map" ||
218  contName == "std::multimap" ||
219  contName == "__gnu_cxx::hash_map" ||
220  contName == "__gnu_cxx::hash_multimap" ){
221  return true;
222  }
223  }
224  return false;
225 }
226 
228  Reflex::TypeTemplate tt = typ.TemplateFamily();
229  if (! tt) {
230  return false;
231  } else {
232  std::string contName = tt.Name(Reflex::SCOPED|Reflex::FINAL);
233  if( contName == "std::vector" ||
234  contName == "std::list" ||
235  contName == "std::deque" ||
236  contName == "std::stack" ||
237  contName == "std::set" ||
238  contName == "std::multiset" ||
239  contName == "__gnu_cxx::hash_set" ||
240  contName == "__gnu_cxx::hash_multiset" ||
241  contName == "ora::PVector" ||
242  contName == "ora::QueryableVector"){
243  return true;
244  }
245  }
246  return false;
247 }
248 
249 
251  Reflex::TypeTemplate templ = typ.TemplateFamily();
252  if (! templ) {
253  return false;
254  } else {
255  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
256  if( contName == "ora::Ptr" ){
257  return true;
258  }
259  }
260  return false;
261 }
262 
264  return typ.HasBase(Reflex::Type::ByTypeInfo(typeid(ora::Reference)));
265 }
266 
268  return typ.HasBase(Reflex::Type::ByTypeInfo(typeid(ora::NamedReference)));
269 }
270 
272  Reflex::TypeTemplate templ = typ.TemplateFamily();
273  if (! templ) {
274  return false;
275  } else {
276  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
277  if( contName == "ora::UniqueRef" ){
278  return true;
279  }
280  }
281  return false;
282 }
283 
285  Reflex::TypeTemplate templ = typ.TemplateFamily();
286  if (! templ) {
287  return false;
288  } else {
289  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
290  if( contName == "ora::PVector" ){
291  return true;
292  }
293  }
294  return false;
295 }
296 
298  Reflex::TypeTemplate templ = typ.TemplateFamily();
299  if (! templ) {
300  return false;
301  } else {
302  std::string contName = templ.Name(Reflex::SCOPED|Reflex::FINAL);
303  if( contName == "ora::QueryableVector" ){
304  return true;
305  }
306  }
307  return false;
308 }
309 
311  if( isTypePVector( typ ) || isTypeQueryableVector( typ ) ){
312  return true;
313  }
314  return false;
315 }
316 
318  size_t idx = typeName.find('<');
319  if( idx != std::string::npos ){
320  std::string tname = typeName.substr( 0, idx );
321  return (tname == "ora::PVector" || tname == "ora::QueryableVector" || tname == "pool::PVector" );
322  }
323  return false;
324 }
325 
327  Reflex::Type resType = ClassUtils::resolvedType( typ );
328  if( isTypePrimitive( resType ) ) {
329  //if ( resType.IsFundamental() || resType.IsEnum() || isTypeString(resType) ) {
330  return false;
331  } else {
332  if( resType.IsArray() ) return false;
333  if( isTypeContainer( resType ) ) return false;
334  if( isTypeOraPointer( resType ) ) return false;
335  if( isTypeUniqueReference( resType ) ) return false;
336  if( isTypeOraVector( resType ) ) return false;
337  }
338  return true;
339 }
340 
342  Reflex::Type valueType;
343  // find the iterator return type as the member value_type of the containers
344  size_t subTypeSize = typ.SubTypeSize();
345  size_t i=0;
346  while(i<subTypeSize){
347  Reflex::Type sti = typ.SubTypeAt(i);
348  if(sti.Name()=="value_type") {
349  valueType = sti;
350  break;
351  }
352  i++;
353  }
354  return valueType;
355 }
356 
358  Reflex::Type keyType;
359  // find the iterator return type as the member value_type of the containers
360  size_t subTypeSize = typ.SubTypeSize();
361  size_t i=0;
362  while(i<subTypeSize){
363  Reflex::Type sti = typ.SubTypeAt(i);
364  if(sti.Name()=="key_type") {
365  keyType = sti;
366  break;
367  }
368  i++;
369  }
370  return keyType;
371 }
372 
375  // find the iterator return type as the member value_type of the containers
376  size_t subTypeSize = typ.SubTypeSize();
377  size_t i=0;
378  while(i<subTypeSize){
379  Reflex::Type sti = typ.SubTypeAt(i);
380  if(sti.Name()=="mapped_type") {
381  dataType = sti;
382  break;
383  }
384  i++;
385  }
386  return dataType;
387 }
388 
390  Reflex::Type subType;
391  size_t subTypeSize = typ.SubTypeSize();
392  size_t i=0;
393  while(i<subTypeSize){
394  Reflex::Type sti = typ.SubTypeAt(i);
395  if(sti.Name()==subTypeName) {
396  subType = sti;
397  break;
398  }
399  i++;
400  }
401  return resolvedType(subType);
402 }
403 
406  while(resolvedType.IsTypedef()){
407  resolvedType = resolvedType.ToType();
408  }
409  return resolvedType;
410 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
type
Definition: HCALResponse.h:21
bool isTypeOraPointer(const Reflex::Type &typ)
Definition: ClassUtils.cc:250
int i
Definition: DBlmapReader.cc:9
bool isTypeNonKeyedContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:193
bool isTypeAssociativeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:211
bool isTypeString(const Reflex::Type &typ)
Definition: ClassUtils.cc:137
void * constructObject(const Reflex::Type &typ)
Definition: ClassUtils.cc:127
bool isTypePVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:284
static char const * tname
Definition: GTSchema.h:13
bool isTypeOraReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:263
void operator()(void *ptr)
Definition: ClassUtils.cc:23
bool findBaseType(Reflex::Type &type, Reflex::Type &baseType, Reflex::OffsetFunction &func)
Definition: ClassUtils.cc:67
bool isTypeUniqueReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:271
std::string demangledName(const std::type_info &typeInfo)
Definition: ClassUtils.cc:82
Reflex::Type containerSubType(const Reflex::Type &typ, const std::string &subTypeName)
Definition: ClassUtils.cc:389
Reflex::Type containerDataType(const Reflex::Type &typ)
Definition: ClassUtils.cc:373
bool checkMappedType(const Reflex::Type &type, const std::string &mappedTypeName)
Definition: ClassUtils.cc:54
bool isTypeNameOraVector(const std::string &typeName)
Definition: ClassUtils.cc:317
void loadDictionary(const std::string &className)
Definition: ClassUtils.cc:27
RflxDeleter(const Reflex::Type &type)
Definition: ClassUtils.cc:12
bool isTypeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:147
static PluginCapabilities * get()
Reflex::Type containerKeyType(const Reflex::Type &typ)
Definition: ClassUtils.cc:357
Reflex::Type containerValueType(const Reflex::Type &typ)
Definition: ClassUtils.cc:341
Reflex::Type resolvedType(const Reflex::Type &typ)
Definition: ClassUtils.cc:404
bool isTypeKeyedContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:173
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool isTypePrimitive(const Reflex::Type &typ)
Definition: ClassUtils.cc:143
void throwException(const std::string &message, const std::string &methodName) __attribute__((noreturn))
Definition: Exception.cc:10
bool isTypeNamedReference(const Reflex::Type &typ)
Definition: ClassUtils.cc:267
void * upCast(const Reflex::Type &type, void *ptr, const Reflex::Type &asType)
Definition: ClassUtils.cc:32
void load(const std::string &iName)
tuple status
Definition: ntuplemaker.py:245
bool isTypeNonAssociativeContainer(const Reflex::Type &typ)
Definition: ClassUtils.cc:227
bool isTypeOraVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:310
Reflex::Type lookupDictionary(const std::type_info &typeInfo, bool throwFlag=true)
Definition: ClassUtils.cc:93
bool isTypeObject(const Reflex::Type &typ)
Definition: ClassUtils.cc:326
std::string className(const T &t)
Definition: ClassName.h:30
bool isType(const Reflex::Type &type, const Reflex::Type &baseType)
Definition: ClassUtils.cc:45
bool isTypeQueryableVector(const Reflex::Type &typ)
Definition: ClassUtils.cc:297