ROOT  6.06/09
Reference Guide
TListOfTypes.cxx
Go to the documentation of this file.
1 // @(#)root/cont
2 // Author: Philippe Canal Aug 2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TListOfTypes
13 
14 A collection of TDataType designed to hold the typedef information
15 and numerical type information. The collection is populated on demand.
16 
17 Besides the built-in types (int, float) a typedef is explicitly
18 added to the collection (and thus visible via ls or Print) only if
19 it is requested explicitly.
20 */
21 
22 
23 #include "TListOfTypes.h"
24 
25 #include "TInterpreter.h"
26 #include "TDataType.h"
27 #include "TVirtualMutex.h"
28 
29 #include "TEnum.h"
30 #include "TClassTable.h"
31 #include "TROOT.h"
32 #include "TClass.h"
33 #include "TProtoClass.h"
34 #include "TListOfEnums.h"
35 
37 {
38  // Constructor
40 }
41 
43 {
44  // Specialize FindObject to do search for the
45  // typedef if its not already in the list
46 
47  return FindType(name);
48 }
49 
50 static bool NameExistsElsewhere(const char* name){
51 
52  // Is this a scope?
53  // We look into the list of classes available,
54  // the ones in the dictionaries and the protoclasses.
55  if (gROOT->GetListOfClasses()->FindObject(name) ||
57  TClassTable::GetProtoNorm(name)) return true;
58 
59  // Is this an enum?
60  TObject* theEnum = nullptr;
61  const auto lastPos = strrchr(name, ':');
62  if (lastPos != nullptr) {
63  // We have a scope
64  const auto enName = lastPos + 1;
65  const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)name) / sizeof(decltype(*lastPos)) - 1;
66 #ifdef R__WIN32
67  char *scopeName = new char[scopeNameSize + 1];
68 #else
69  char scopeName[scopeNameSize + 1]; // on the stack, +1 for the terminating character '\0'
70 #endif
71  strncpy(scopeName, name, scopeNameSize);
72  scopeName[scopeNameSize] = '\0';
73  // We have now an enum name and a scope name
74  // We look first in the classes
75  if(auto scope = dynamic_cast<TClass*>(gROOT->GetListOfClasses()->FindObject(scopeName))){
76  theEnum = ((TListOfEnums*)scope->GetListOfEnums(false))->THashList::FindObject(enName);
77  }
78  // And then if not found in the protoclasses
79  if (!theEnum){
80  if (auto scope = TClassTable::GetProtoNorm(scopeName)){
81  if (auto listOfEnums = (TListOfEnums*)scope->GetListOfEnums())
82  theEnum = listOfEnums->THashList::FindObject(enName);
83  }
84  }
85 #ifdef R__WIN32
86  delete [] scopeName;
87 #endif
88  } else { // Here we look in the global scope
89  theEnum = ((TListOfEnums*)gROOT->GetListOfEnums())->THashList::FindObject(name);
90  }
91 
92  return nullptr != theEnum;
93 
94 }
95 
97 {
98  // Look for a type, first in the hast table
99  // then in the interpreter.
100 
101  TDataType *result = static_cast<TDataType*>(THashTable::FindObject(name));
102  if (!result) {
103 
104  if (NameExistsElsewhere(name)) {
105  return nullptr;
106  }
107 
108  // We perform now a lookup
109 
111 
112  TypedefInfo_t *info = gInterpreter->TypedefInfo_Factory(name);
113  if (gInterpreter->TypedefInfo_IsValid(info)) {
114  result = new TDataType(info);
115  // Double check we did not get a different spelling of an
116  // already existing typedef.
117  if (strcmp(name,result->GetName()) != 0) {
118  TDataType *alt = static_cast<TDataType*>(THashTable::FindObject(result->GetName()));
119  if (!alt)
120  const_cast<TListOfTypes*>(this)->Add(result);
121  else {
122  delete result;
123  result = alt;
124  }
125  } else {
126  const_cast<TListOfTypes*>(this)->Add(result);
127  }
128  } else {
129  gInterpreter->TypedefInfo_Delete(info);
130  }
131  }
132  return result;
133 }
TDataType * FindType(const char *name) const
long long Long64_t
Definition: RtypesCore.h:69
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:46
#define gROOT
Definition: TROOT.h:340
#define gInterpreter
Definition: TInterpreter.h:502
THashTable implements a hash table to store TObject's.
Definition: THashTable.h:39
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:46
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
A collection of TDataType designed to hold the typedef information and numerical type information...
Definition: TListOfTypes.h:32
void Add(TObject *obj)
Add object to the hash table.
Definition: THashTable.cxx:75
static void AddBuiltins(TCollection *types)
Create the TDataType objects for builtins.
Definition: TDataType.cxx:408
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
Definition: TListOfEnums.h:36
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashTable.cxx:209
double result[121]
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name)...
static bool NameExistsElsewhere(const char *name)