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 size_t scopeNameSize = (lastPos - name) / sizeof(decltype(*lastPos)) - 1;
66 std::string scopeName{name, scopeNameSize};
67 // We have now an enum name and a scope name
68 // We look first in the classes
69 if (auto scope = dynamic_cast<TClass *>(gROOT->GetListOfClasses()->FindObject(scopeName.c_str()))) {
70 theEnum = ((TListOfEnums*)scope->GetListOfEnums(false))->THashList::FindObject(enName);
71 }
72 // And then if not found in the protoclasses
73 if (!theEnum){
74 if (auto scope = TClassTable::GetProtoNorm(scopeName.c_str())) {
75 if (auto listOfEnums = (TListOfEnums*)scope->GetListOfEnums())
76 theEnum = listOfEnums->THashList::FindObject(enName);
77 }
78 }
79 } else { // Here we look in the global scope
80 theEnum = ((TListOfEnums*)gROOT->GetListOfEnums())->THashList::FindObject(name);
81 }
82
83 return nullptr != theEnum;
84
85}
86
88{
89 // Look for a type, first in the hast table
90 // then in the interpreter.
91
93
95 if (!result) {
96
98 return nullptr;
99 }
100
101 // We perform now a lookup
102
104
105 TypedefInfo_t *info = gInterpreter->TypedefInfo_Factory(name);
106 if (gInterpreter->TypedefInfo_IsValid(info)) {
107 result = new TDataType(info);
108 // Double check we did not get a different spelling of an
109 // already existing typedef.
110 if (strcmp(name,result->GetName()) != 0) {
111 TDataType *alt = static_cast<TDataType*>(THashTable::FindObject(result->GetName()));
112 if (!alt)
113 const_cast<TListOfTypes*>(this)->Add(result);
114 else {
115 delete result;
116 result = alt;
117 }
118 } else {
119 const_cast<TListOfTypes*>(this)->Add(result);
120 }
121 } else {
122 gInterpreter->TypedefInfo_Delete(info);
123 }
124 }
125 return result;
126}
#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