Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "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
50static 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
102
104 if (!result) {
105
107 return nullptr;
108 }
109
110 // We perform now a lookup
111
113
114 TypedefInfo_t *info = gInterpreter->TypedefInfo_Factory(name);
115 if (gInterpreter->TypedefInfo_IsValid(info)) {
116 result = new TDataType(info);
117 // Double check we did not get a different spelling of an
118 // already existing typedef.
119 if (strcmp(name,result->GetName()) != 0) {
120 TDataType *alt = static_cast<TDataType*>(THashTable::FindObject(result->GetName()));
121 if (!alt)
122 const_cast<TListOfTypes*>(this)->Add(result);
123 else {
124 delete result;
125 result = alt;
126 }
127 } else {
128 const_cast<TListOfTypes*>(this)->Add(result);
129 }
130 } else {
131 gInterpreter->TypedefInfo_Delete(info);
132 }
133 }
134 return result;
135}
long long Long64_t
Definition RtypesCore.h:80
#define R__COLLECTION_READ_GUARD()
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
static bool NameExistsElsewhere(const char *name)
#define gROOT
Definition TROOT.h:406
#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).
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
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.
TObject * FindObject(const char *name) const override
Find object using its name.
THashTable implements a hash table to store TObject's.
Definition THashTable.h:35
void Add(TObject *obj) override
Add object to the hash table.
TObject * FindObject(const char *name) const override
Find object using its name.
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
A collection of TDataType designed to hold the typedef information and numerical type information.
TObject * FindObject(const char *name) const override
Find object using its name.
TDataType * FindType(const char *name) const
Mother of all ROOT objects.
Definition TObject.h:41