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
30
31////////////////////////////////////////////////////////////////////////////////
32/// Constructor.
33
35 THashList(listSize), fClass(cl), fIds(nullptr), fUnloaded(nullptr), fIsLoaded(kFALSE), fLastLoadMarker(0)
36{
37 fIds = new TExMap(listSize);
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Destructor.
43
45{
47 delete fIds;
49 delete fUnloaded;
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// Add pair<id, object> to the map of functions and their ids.
54
56{
57 TEnum *e = dynamic_cast<TEnum *>(obj);
58 if (e && e->GetDeclId()) {
59 fIds->Add((Long64_t)e->GetDeclId(), (Long64_t)e);
60 }
61}
62
63////////////////////////////////////////////////////////////////////////////////
64/// Add object at the beginning of the list.
65
67{
69 MapObject(obj);
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Add object at the beginning of the list and also store option.
74/// Storing an option is useful when one wants to change the behaviour
75/// of an object a little without having to create a complete new
76/// copy of the object. This feature is used, for example, by the Draw()
77/// method. It allows the same object to be drawn in different ways.
78
80{
81 THashList::AddFirst(obj, opt);
82 MapObject(obj);
83}
84
85////////////////////////////////////////////////////////////////////////////////
86/// Add object at the end of the list.
87
89{
91 MapObject(obj);
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Add object at the end of the list and also store option.
96/// Storing an option is useful when one wants to change the behaviour
97/// of an object a little without having to create a complete new
98/// copy of the object. This feature is used, for example, by the Draw()
99/// method. It allows the same object to be drawn in different ways.
100
102{
103 THashList::AddLast(obj, opt);
104 MapObject(obj);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Insert object at location idx in the list.
109
111{
112 THashList::AddAt(obj, idx);
113 MapObject(obj);
114}
115
116////////////////////////////////////////////////////////////////////////////////
117/// Insert object at location idx in the list, with options.
118
120{
121 THashList::AddAt(obj, idx, opt);
122 MapObject(obj);
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Insert object after object after in the list.
127
129{
131 MapObject(obj);
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Insert object after object after in the list.
136
142
143////////////////////////////////////////////////////////////////////////////////
144/// Insert object after object after in the list, with options.
145
147{
148 THashList::AddAfter(after, obj, opt);
149 MapObject(obj);
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// Insert object after object after in the list, with options.
154
156{
157 THashList::AddAfter(after, obj, opt);
158 MapObject(obj);
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Insert object before object before in the list.
163
165{
167 MapObject(obj);
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// Insert object before object before in the list.
172
178
179////////////////////////////////////////////////////////////////////////////////
180/// Insert object before object before in the list, with options.
181
183{
184 THashList::AddBefore(before, obj, opt);
185 MapObject(obj);
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Insert object before object before in the list, with options.
190
192{
193 THashList::AddBefore(before, obj, opt);
194 MapObject(obj);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Remove all objects from the list. Does not delete the objects unless
199/// the THashList is the owner (set via SetOwner()).
200
208
209////////////////////////////////////////////////////////////////////////////////
210/// Delete all TDataMember object files.
211
218
219////////////////////////////////////////////////////////////////////////////////
220/// Return the TEnum corresponding to the Decl 'id' or NULL if it does not
221/// exist.
222
224{
225 if (!id) return nullptr;
226
227 return (TEnum *)fIds->GetValue((Long64_t)id);
228}
229
230////////////////////////////////////////////////////////////////////////////////
231/// Specialize FindObject to do search for the
232/// a enum just by name or create it if its not already in the list
233
235{
237 if (!result) {
239 decl = gInterpreter->GetEnum(GetClass(), name);
240 if (decl) result = const_cast<TListOfEnums *>(this)->Get(decl, name);
241 }
242 return result;
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Return (after creating it if necessary) the TEnum
247/// describing the enum corresponding to the Decl 'id'.
248
250{
251 if (!id) return nullptr;
252
253 TEnum *e = Find(id);
254 if (e) return e;
255
256 // If this declID is not found as key, we look for the enum by name.
257 // Indeed it could have been generated by protoclasses.
258#if defined(R__MUST_REVISIT)
259# if R__MUST_REVISIT(6,4)
260 "This special case can be removed once PCMs are available."
261# endif
262#endif
263 e = static_cast<TEnum*>(THashList::FindObject(name));
264 if (e) {
265 // In this case, we update the declId, update its constants and add the enum to the ids map and return.
266 // At this point it is like it came from the interpreter.
267 if (nullptr == e->GetDeclId()){
268 e->Update(id);
270 gInterpreter->UpdateEnumConstants(e, fClass);
271 }
272 return e;
273 }
274
275 if (fClass) {
277 // The interpreter does not know about this class yet (or a problem
278 // occurred that prevented the proper updating of fClassInfo).
279 // So this decl can not possibly be part of this class.
280 // [In addition calling GetClassInfo would trigger a late parsing
281 // of the header which we want to avoid].
282 return nullptr;
283 }
284 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(), id)) return nullptr;
285 } else {
286 if (!gInterpreter->ClassInfo_Contains(nullptr, id)) return nullptr;
287 }
288
290
291 // Let's see if this is a reload ...
292 // can we check for reloads for enums?
294 if (e) {
295 e->Update(id);
296 gInterpreter->UpdateEnumConstants(e, fClass);
297 } else {
298 e = gInterpreter->CreateEnum((void *)id, fClass);
299 }
300 // Calling 'just' THahList::Add would turn around and call
301 // TListOfEnums::AddLast which should *also* do the fIds->Add.
303 fIds->Add((Long64_t)id, (Long64_t)e);
304
305 return e;
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Return an object from the list of enums *if and only if* is has already
310/// been loaded in the list. This is an internal routine.
311
313{
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Remove a pair<id, object> from the map of functions and their ids.
319
321{
322 TEnum *e = dynamic_cast<TEnum *>(obj);
323 if (e && e->GetDeclId()) {
324 fIds->Remove((Long64_t)e->GetDeclId());
325 }
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Remove object from this collection and recursively remove the object
330/// from all other objects (and collections).
331/// This function overrides TCollection::RecursiveRemove that calls
332/// the Remove function. THashList::Remove cannot be called because
333/// it uses the hash value of the hash table. This hash value
334/// is not available anymore when RecursiveRemove is called from
335/// the TObject destructor.
336
338{
339 if (!obj) return;
340
343 UnmapObject(obj);
344}
345
346////////////////////////////////////////////////////////////////////////////////
347/// Remove object from the list.
348
350{
351 Bool_t found;
352
353 found = THashList::Remove(obj);
354 if (!found) {
355 found = fUnloaded->Remove(obj);
356 }
357 UnmapObject(obj);
358 if (found) return obj;
359 else return nullptr;
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Remove object via its objlink from the list.
364
366{
367 if (!lnk) return nullptr;
368
369 TObject *obj = lnk->GetObject();
370
372 fUnloaded->Remove(obj);
373 UnmapObject(obj);
374 return obj;
375}
376
377////////////////////////////////////////////////////////////////////////////////
378/// Load all the DataMembers known to the interpreter for the scope 'fClass'
379/// into this collection.
380
382{
383 if (fClass && fClass->Property() & (kIsClass | kIsStruct | kIsUnion)) {
384 // Class and union are not extendable, if we already
385 // loaded all the data member there is no need to recheck
386 if (fIsLoaded) return;
387 }
388
389 // This will provoke the parsing of the headers if need be.
390 if (fClass && fClass->GetClassInfo() == nullptr) return;
391
393
394 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
396 return;
397 }
399
400 // In the case of namespace, even if we have loaded before we need to
401 // load again in case there was new data member added.
402
403 // Mark the list as loaded to avoid an infinite recursion in the case
404 // where we have a data member that is a variable size array. In that
405 // case TDataMember::Init needs to get/load the list to find the data
406 // member used as the array size.
408
409 // Respawn the unloaded enums if they come from protoclasses, i.e. they
410 // have a 0 declId.
411#if defined(R__MUST_REVISIT)
412# if R__MUST_REVISIT(6,4)
413 "This special case can be removed once PCMs are available."
414# endif
415#endif
416
417 std::forward_list<TEnum*> respownedEnums;
418 for (auto enumAsObj : *fUnloaded){
419 TEnum* en = static_cast<TEnum*>(enumAsObj);
420 if (nullptr == en->GetDeclId()){
422 respownedEnums.push_front(en);
423 }
424 }
425
426 for (auto en : respownedEnums)
428
429 // We cannot clear the whole unloaded list. It is too much.
430// fUnloaded->Clear();
431
432 gInterpreter->LoadEnums(*this);
433}
434
435////////////////////////////////////////////////////////////////////////////////
436/// Mark 'all func' as being unloaded.
437/// After the unload, the data member can no longer be found directly,
438/// until the decl can be found again in the interpreter (in which
439/// the func object will be reused.
440
442{
444 while (lnk) {
445 TEnum *data = (TEnum *)lnk->GetObject();
446
447 if (data->GetDeclId())
448 fIds->Remove((Long64_t)data->GetDeclId());
450
451 lnk = lnk->Next();
452 }
453
456}
457
458////////////////////////////////////////////////////////////////////////////////
459/// Mark enum 'e' as being unloaded.
460/// After the unload, the data member can no longer be found directly,
461/// until the decl can be found again in the interpreter (in which
462/// the func object will be reused.
463
465{
466 if (THashList::Remove(e)) {
467 // We contains the object, let remove it from the other internal
468 // list and move it to the list of unloaded objects.
469 if (e->GetDeclId())
470 fIds->Remove((Long64_t)e->GetDeclId());
471 fUnloaded->Add(e);
472 }
473}
Cppyy::TCppType_t fClass
#define e(i)
Definition RSha256.hxx:103
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
@ 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:84
Bool_t HasInterpreterInfoInMemory() const
Definition TClass.h:421
ClassInfo_t * GetClassInfo() const
Definition TClass.h:445
Long_t Property() const override
Returns the properties of the TClass as a bit field stored as a Long_t value.
Definition TClass.cxx:6128
The TEnum class implements the enum type.
Definition TEnum.h:33
void Update(DeclId_t id)
Definition TEnum.cxx:158
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:216
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:87
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition TExMap.cxx:173
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:68
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.
THashList(const THashList &)=delete
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:94
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:81
virtual TObjLink * FirstLink() const
Definition TList.h:107
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:125