Logo ROOT   6.16/01
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\ingroup Base
14
15A collection of TDataType designed to hold the typedef information
16and numerical type information. The collection is populated on demand.
17
18Besides the built-in types (int, float) a typedef is explicitly
19added to the collection (and thus visible via ls or Print) only if
20it is requested explicitly.
21*/
22
23
24#include "TListOfTypes.h"
25
26#include "TInterpreter.h"
27#include "TDataType.h"
28#include "TVirtualMutex.h"
29
30#include "TEnum.h"
31#include "TClassTable.h"
32#include "TROOT.h"
33#include "TClass.h"
34#include "TProtoClass.h"
35#include "TListOfEnums.h"
36
38{
39 // Constructor
41}
42
44{
45 // Specialize FindObject to do search for the
46 // typedef if its not already in the list
47
48 return FindType(name);
49}
50
51static bool NameExistsElsewhere(const char* name){
52
53 // Is this a scope?
54 // We look into the list of classes available,
55 // the ones in the dictionaries and the protoclasses.
56 if (gROOT->GetListOfClasses()->FindObject(name) ||
58 TClassTable::GetProtoNorm(name)) return true;
59
60 // Is this an enum?
61 TObject* theEnum = nullptr;
62 const auto lastPos = strrchr(name, ':');
63 if (lastPos != nullptr) {
64 // We have a scope
65 const auto enName = lastPos + 1;
66 const auto scopeNameSize = ((Long64_t)lastPos - (Long64_t)name) / sizeof(decltype(*lastPos)) - 1;
67#ifdef R__WIN32
68 char *scopeName = new char[scopeNameSize + 1];
69#else
70 char scopeName[scopeNameSize + 1]; // on the stack, +1 for the terminating character '\0'
71#endif
72 strncpy(scopeName, name, scopeNameSize);
73 scopeName[scopeNameSize] = '\0';
74 // We have now an enum name and a scope name
75 // We look first in the classes
76 if(auto scope = dynamic_cast<TClass*>(gROOT->GetListOfClasses()->FindObject(scopeName))){
77 theEnum = ((TListOfEnums*)scope->GetListOfEnums(false))->THashList::FindObject(enName);
78 }
79 // And then if not found in the protoclasses
80 if (!theEnum){
81 if (auto scope = TClassTable::GetProtoNorm(scopeName)){
82 if (auto listOfEnums = (TListOfEnums*)scope->GetListOfEnums())
83 theEnum = listOfEnums->THashList::FindObject(enName);
84 }
85 }
86#ifdef R__WIN32
87 delete [] scopeName;
88#endif
89 } else { // Here we look in the global scope
90 theEnum = ((TListOfEnums*)gROOT->GetListOfEnums())->THashList::FindObject(name);
91 }
92
93 return nullptr != theEnum;
94
95}
96
98{
99 // Look for a type, first in the hast table
100 // then in the interpreter.
101
103
104 TDataType *result = static_cast<TDataType*>(THashTable::FindObject(name));
105 if (!result) {
106
108 return nullptr;
109 }
110
111 // We perform now a lookup
112
114
115 TypedefInfo_t *info = gInterpreter->TypedefInfo_Factory(name);
116 if (gInterpreter->TypedefInfo_IsValid(info)) {
117 result = new TDataType(info);
118 // Double check we did not get a different spelling of an
119 // already existing typedef.
120 if (strcmp(name,result->GetName()) != 0) {
121 TDataType *alt = static_cast<TDataType*>(THashTable::FindObject(result->GetName()));
122 if (!alt)
123 const_cast<TListOfTypes*>(this)->Add(result);
124 else {
125 delete result;
126 result = alt;
127 }
128 } else {
129 const_cast<TListOfTypes*>(this)->Add(result);
130 }
131 } else {
132 gInterpreter->TypedefInfo_Delete(info);
133 }
134 }
135 return result;
136}
long long Long64_t
Definition: RtypesCore.h:69
#define R__COLLECTION_READ_GUARD()
Definition: TCollection.h:126
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:40
#define gInterpreter
Definition: TInterpreter.h:538
static bool NameExistsElsewhere(const char *name)
#define gROOT
Definition: TROOT.h:410
#define R__LOCKGUARD(mutex)
static TProtoClass * GetProtoNorm(const char *cname)
Given the class normalized name returns the TClassProto object for the class.
static DictFuncPtr_t GetDictNorm(const char *cname)
Given the normalized class name returns the Dictionary() function of a class (uses hash of name).
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
Basic data type descriptor (datatype information is obtained from CINT).
Definition: TDataType.h:44
static void AddBuiltins(TCollection *types)
Create the TDataType objects for builtins.
Definition: TDataType.cxx:408
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
THashTable implements a hash table to store TObject's.
Definition: THashTable.h:35
void Add(TObject *obj)
Add object to the hash table.
Definition: THashTable.cxx:92
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashTable.cxx:238
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
Definition: TListOfEnums.h:33
A collection of TDataType designed to hold the typedef information and numerical type information.
Definition: TListOfTypes.h:31
TDataType * FindType(const char *name) const
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37