Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TListOfEnums.cxx
Go to the documentation of this file.
1// @(#)root/cont
2// Author: Bianca-Cristina Cristescu February 2014
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 TListOfEnums
13A collection of TEnum objects designed for fast access given a
14DeclId_t and for keep track of TEnum that were described
15unloaded enum.
16*/
17
18#include <forward_list>
19
20#include "TListOfEnums.h"
21#include "TClass.h"
22#include "TExMap.h"
23#include "TEnum.h"
24#include "TGlobal.h"
25#include "TInterpreter.h"
26#include "TVirtualMutex.h"
27
28const unsigned int listSize=3;
29
31
32////////////////////////////////////////////////////////////////////////////////
33/// Constructor.
34
36 THashList(listSize), fClass(cl), fIds(nullptr), fUnloaded(nullptr), fIsLoaded(kFALSE), fLastLoadMarker(0)
37{
38 fIds = new TExMap(listSize);
40}
41
42////////////////////////////////////////////////////////////////////////////////
43/// Destructor.
44
46{
48 delete fIds;
50 delete fUnloaded;
51}
52
53////////////////////////////////////////////////////////////////////////////////
54/// Add pair<id, object> to the map of functions and their ids.
55
57{
58 TEnum *e = dynamic_cast<TEnum *>(obj);
59 if (e && e->GetDeclId()) {
60 fIds->Add((Long64_t)e->GetDeclId(), (Long64_t)e);
61 }
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Add object at the beginning of the list.
66
68{
70 MapObject(obj);
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Add object at the beginning of the list and also store option.
75/// Storing an option is useful when one wants to change the behaviour
76/// of an object a little without having to create a complete new
77/// copy of the object. This feature is used, for example, by the Draw()
78/// method. It allows the same object to be drawn in different ways.
79
81{
82 THashList::AddFirst(obj, opt);
83 MapObject(obj);
84}
85
86////////////////////////////////////////////////////////////////////////////////
87/// Add object at the end of the list.
88
90{
92 MapObject(obj);
93}
94
95////////////////////////////////////////////////////////////////////////////////
96/// Add object at the end of the list and also store option.
97/// Storing an option is useful when one wants to change the behaviour
98/// of an object a little without having to create a complete new
99/// copy of the object. This feature is used, for example, by the Draw()
100/// method. It allows the same object to be drawn in different ways.
101
103{
104 THashList::AddLast(obj, opt);
105 MapObject(obj);
106}
107
108////////////////////////////////////////////////////////////////////////////////
109/// Insert object at location idx in the list.
110
112{
113 THashList::AddAt(obj, idx);
114 MapObject(obj);
115}
116
117////////////////////////////////////////////////////////////////////////////////
118/// Insert object after object after in the list.
119
120void TListOfEnums::AddAfter(const TObject *after, TObject *obj)
121{
122 THashList::AddAfter(after, obj);
123 MapObject(obj);
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// Insert object after object after in the list.
128
130{
131 THashList::AddAfter(after, obj);
132 MapObject(obj);
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// Insert object before object before in the list.
137
138void TListOfEnums::AddBefore(const TObject *before, TObject *obj)
139{
140 THashList::AddBefore(before, obj);
141 MapObject(obj);
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Insert object before object before in the list.
146
148{
149 THashList::AddBefore(before, obj);
150 MapObject(obj);
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Remove all objects from the list. Does not delete the objects unless
155/// the THashList is the owner (set via SetOwner()).
156
158{
160 fIds->Clear();
163}
164
165////////////////////////////////////////////////////////////////////////////////
166/// Delete all TDataMember object files.
167
169{
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Return the TEnum corresponding to the Decl 'id' or NULL if it does not
177/// exist.
178
180{
181 if (!id) return nullptr;
182
183 return (TEnum *)fIds->GetValue((Long64_t)id);
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// Specialize FindObject to do search for the
188/// a enum just by name or create it if its not already in the list
189
191{
193 if (!result) {
195 decl = gInterpreter->GetEnum(GetClass(), name);
196 if (decl) result = const_cast<TListOfEnums *>(this)->Get(decl, name);
197 }
198 return result;
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Return (after creating it if necessary) the TEnum
203/// describing the enum corresponding to the Decl 'id'.
204
206{
207 if (!id) return nullptr;
208
209 TEnum *e = Find(id);
210 if (e) return e;
211
212 // If this declID is not found as key, we look for the enum by name.
213 // Indeed it could have been generated by protoclasses.
214#if defined(R__MUST_REVISIT)
215# if R__MUST_REVISIT(6,4)
216 "This special case can be removed once PCMs are available."
217# endif
218#endif
219 e = static_cast<TEnum*>(THashList::FindObject(name));
220 if (e) {
221 // In this case, we update the declId, update its constants and add the enum to the ids map and return.
222 // At this point it is like it came from the interpreter.
223 if (nullptr == e->GetDeclId()){
224 e->Update(id);
226 gInterpreter->UpdateEnumConstants(e, fClass);
227 }
228 return e;
229 }
230
231 if (fClass) {
233 // The interpreter does not know about this class yet (or a problem
234 // occurred that prevented the proper updating of fClassInfo).
235 // So this decl can not possibly be part of this class.
236 // [In addition calling GetClassInfo would trigger a late parsing
237 // of the header which we want to avoid].
238 return nullptr;
239 }
240 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(), id)) return nullptr;
241 } else {
242 if (!gInterpreter->ClassInfo_Contains(nullptr, id)) return nullptr;
243 }
244
246
247 // Let's see if this is a reload ...
248 // can we check for reloads for enums?
250 if (e) {
251 e->Update(id);
252 gInterpreter->UpdateEnumConstants(e, fClass);
253 } else {
254 e = gInterpreter->CreateEnum((void *)id, fClass);
255 }
256 // Calling 'just' THahList::Add would turn around and call
257 // TListOfEnums::AddLast which should *also* do the fIds->Add.
259 fIds->Add((Long64_t)id, (Long64_t)e);
260
261 return e;
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Return an object from the list of enums *if and only if* is has already
266/// been loaded in the list. This is an internal routine.
267
269{
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Remove a pair<id, object> from the map of functions and their ids.
275
277{
278 TEnum *e = dynamic_cast<TEnum *>(obj);
279 if (e && e->GetDeclId()) {
280 fIds->Remove((Long64_t)e->GetDeclId());
281 }
282}
283
284////////////////////////////////////////////////////////////////////////////////
285/// Remove object from this collection and recursively remove the object
286/// from all other objects (and collections).
287/// This function overrides TCollection::RecursiveRemove that calls
288/// the Remove function. THashList::Remove cannot be called because
289/// it uses the hash value of the hash table. This hash value
290/// is not available anymore when RecursiveRemove is called from
291/// the TObject destructor.
292
294{
295 if (!obj) return;
296
299 UnmapObject(obj);
300}
301
302////////////////////////////////////////////////////////////////////////////////
303/// Remove object from the list.
304
306{
307 Bool_t found;
308
309 found = THashList::Remove(obj);
310 if (!found) {
311 found = fUnloaded->Remove(obj);
312 }
313 UnmapObject(obj);
314 if (found) return obj;
315 else return nullptr;
316}
317
318////////////////////////////////////////////////////////////////////////////////
319/// Remove object via its objlink from the list.
320
322{
323 if (!lnk) return nullptr;
324
325 TObject *obj = lnk->GetObject();
326
328 fUnloaded->Remove(obj);
329 UnmapObject(obj);
330 return obj;
331}
332
333////////////////////////////////////////////////////////////////////////////////
334/// Load all the DataMembers known to the interpreter for the scope 'fClass'
335/// into this collection.
336
338{
339 if (fClass && fClass->Property() & (kIsClass | kIsStruct | kIsUnion)) {
340 // Class and union are not extendable, if we already
341 // loaded all the data member there is no need to recheck
342 if (fIsLoaded) return;
343 }
344
345 // This will provoke the parsing of the headers if need be.
346 if (fClass && fClass->GetClassInfo() == nullptr) return;
347
349
350 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
351 if (currentTransaction == fLastLoadMarker) {
352 return;
353 }
354 fLastLoadMarker = currentTransaction;
355
356 // In the case of namespace, even if we have loaded before we need to
357 // load again in case there was new data member added.
358
359 // Mark the list as loaded to avoid an infinite recursion in the case
360 // where we have a data member that is a variable size array. In that
361 // case TDataMember::Init needs to get/load the list to find the data
362 // member used as the array size.
364
365 // Respawn the unloaded enums if they come from protoclasses, i.e. they
366 // have a 0 declId.
367#if defined(R__MUST_REVISIT)
368# if R__MUST_REVISIT(6,4)
369 "This special case can be removed once PCMs are available."
370# endif
371#endif
372
373 std::forward_list<TEnum*> respownedEnums;
374 for (auto enumAsObj : *fUnloaded){
375 TEnum* en = static_cast<TEnum*>(enumAsObj);
376 if (nullptr == en->GetDeclId()){
378 respownedEnums.push_front(en);
379 }
380 }
381
382 for (auto en : respownedEnums)
383 fUnloaded->Remove(en);
384
385 // We cannot clear the whole unloaded list. It is too much.
386// fUnloaded->Clear();
387
388 gInterpreter->LoadEnums(*this);
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Mark 'all func' as being unloaded.
393/// After the unload, the data member can no longer be found directly,
394/// until the decl can be found again in the interpreter (in which
395/// the func object will be reused.
396
398{
399 TObjLink *lnk = FirstLink();
400 while (lnk) {
401 TEnum *data = (TEnum *)lnk->GetObject();
402
403 if (data->GetDeclId())
404 fIds->Remove((Long64_t)data->GetDeclId());
406
407 lnk = lnk->Next();
408 }
409
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Mark enum 'e' as being unloaded.
416/// After the unload, the data member can no longer be found directly,
417/// until the decl can be found again in the interpreter (in which
418/// the func object will be reused.
419
421{
422 if (THashList::Remove(e)) {
423 // We contains the object, let remove it from the other internal
424 // list and move it to the list of unloaded objects.
425 if (e->GetDeclId())
426 fIds->Remove((Long64_t)e->GetDeclId());
427 fUnloaded->Add(e);
428 }
429}
Cppyy::TCppType_t fClass
#define e(i)
Definition RSha256.hxx:103
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
unsigned long long ULong64_t
Definition RtypesCore.h:81
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
@ kIsClass
Definition TDictionary.h:65
@ kIsStruct
Definition TDictionary.h:66
@ kIsUnion
Definition TDictionary.h:67
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
const unsigned int listSize
#define R__LOCKGUARD(mutex)
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Bool_t HasInterpreterInfoInMemory() const
Definition TClass.h:409
ClassInfo_t * GetClassInfo() const
Definition TClass.h:433
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6086
The TEnum class implements the enum type.
Definition TEnum.h:33
void Update(DeclId_t id)
Definition TEnum.cxx:156
DeclId_t GetDeclId() const
Definition TEnum.cxx:146
This class stores a (key,value) pair using an external hash.
Definition TExMap.h:33
void Remove(ULong64_t hash, Long64_t key)
Remove entry with specified key from the TExMap.
Definition TExMap.cxx:217
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
Definition TExMap.cxx:88
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition TExMap.cxx:174
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
void Clear(Option_t *option="") override
Remove all objects from the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition THashList.cxx:69
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * FindObject(const char *name) const override
Find object using its name.
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition THashList.cxx:95
TDictionary::DeclId_t DeclId_t
A collection of TEnum objects designed for fast access given a DeclId_t and for keep track of TEnum t...
TEnum * Find(DeclId_t id) const
Return the TEnum corresponding to the Decl 'id' or NULL if it does not exist.
~TListOfEnums() override
Destructor.
TExMap * fIds
Context of this list. Not owned.
TClass * fClass
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
TDictionary::DeclId_t DeclId_t
TEnum * Get(DeclId_t id, const char *name)
Return (after creating it if necessary) the TEnum describing the enum corresponding to the Decl 'id'.
void Delete(Option_t *option="") override
Delete all TDataMember object files.
TListOfEnums(const TListOfEnums &)=delete
Represent interpreter state when we last did a full load.
Bool_t fIsLoaded
Holder of TEnum for unloaded Enums.
ULong64_t fLastLoadMarker
Mark whether Load was executed.
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
TObject * FindObject(const char *) const override
Specialize FindObject to do search for the a enum just by name or create it if its not already in the...
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
TClass * GetClass() const
virtual TEnum * GetObject(const char *) const
Return an object from the list of enums if and only if is has already been loaded in the list.
void Load()
Load all the DataMembers known to the interpreter for the scope 'fClass' into this collection.
TObject * Remove(TObject *obj) override
Remove object from the list.
THashList * fUnloaded
Map from DeclId_t to TEnum*.
void MapObject(TObject *obj)
Add pair<id, object> to the map of functions and their ids.
void AddLast(TObject *obj) override
Add object at the end of the list.
void UnmapObject(TObject *obj)
Remove a pair<id, object> from the map of functions and their ids.
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
void Clear(Option_t *option) override
Remove all objects from the list.
void Unload()
Mark 'all func' as being unloaded.
void Add(TObject *obj) override
Definition TList.h:83
virtual TObjLink * FirstLink() const
Definition TList.h:104
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:119