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 after object after in the list.
118
120{
122 MapObject(obj);
123}
124
125////////////////////////////////////////////////////////////////////////////////
126/// Insert object after object after in the list.
127
133
134////////////////////////////////////////////////////////////////////////////////
135/// Insert object before object before in the list.
136
138{
140 MapObject(obj);
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Insert object before object before in the list.
145
151
152////////////////////////////////////////////////////////////////////////////////
153/// Remove all objects from the list. Does not delete the objects unless
154/// the THashList is the owner (set via SetOwner()).
155
163
164////////////////////////////////////////////////////////////////////////////////
165/// Delete all TDataMember object files.
166
173
174////////////////////////////////////////////////////////////////////////////////
175/// Return the TEnum corresponding to the Decl 'id' or NULL if it does not
176/// exist.
177
179{
180 if (!id) return nullptr;
181
182 return (TEnum *)fIds->GetValue((Long64_t)id);
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Specialize FindObject to do search for the
187/// a enum just by name or create it if its not already in the list
188
190{
192 if (!result) {
194 decl = gInterpreter->GetEnum(GetClass(), name);
195 if (decl) result = const_cast<TListOfEnums *>(this)->Get(decl, name);
196 }
197 return result;
198}
199
200////////////////////////////////////////////////////////////////////////////////
201/// Return (after creating it if necessary) the TEnum
202/// describing the enum corresponding to the Decl 'id'.
203
205{
206 if (!id) return nullptr;
207
208 TEnum *e = Find(id);
209 if (e) return e;
210
211 // If this declID is not found as key, we look for the enum by name.
212 // Indeed it could have been generated by protoclasses.
213#if defined(R__MUST_REVISIT)
214# if R__MUST_REVISIT(6,4)
215 "This special case can be removed once PCMs are available."
216# endif
217#endif
218 e = static_cast<TEnum*>(THashList::FindObject(name));
219 if (e) {
220 // In this case, we update the declId, update its constants and add the enum to the ids map and return.
221 // At this point it is like it came from the interpreter.
222 if (nullptr == e->GetDeclId()){
223 e->Update(id);
225 gInterpreter->UpdateEnumConstants(e, fClass);
226 }
227 return e;
228 }
229
230 if (fClass) {
232 // The interpreter does not know about this class yet (or a problem
233 // occurred that prevented the proper updating of fClassInfo).
234 // So this decl can not possibly be part of this class.
235 // [In addition calling GetClassInfo would trigger a late parsing
236 // of the header which we want to avoid].
237 return nullptr;
238 }
239 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(), id)) return nullptr;
240 } else {
241 if (!gInterpreter->ClassInfo_Contains(nullptr, id)) return nullptr;
242 }
243
245
246 // Let's see if this is a reload ...
247 // can we check for reloads for enums?
249 if (e) {
250 e->Update(id);
251 gInterpreter->UpdateEnumConstants(e, fClass);
252 } else {
253 e = gInterpreter->CreateEnum((void *)id, fClass);
254 }
255 // Calling 'just' THahList::Add would turn around and call
256 // TListOfEnums::AddLast which should *also* do the fIds->Add.
258 fIds->Add((Long64_t)id, (Long64_t)e);
259
260 return e;
261}
262
263////////////////////////////////////////////////////////////////////////////////
264/// Return an object from the list of enums *if and only if* is has already
265/// been loaded in the list. This is an internal routine.
266
268{
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Remove a pair<id, object> from the map of functions and their ids.
274
276{
277 TEnum *e = dynamic_cast<TEnum *>(obj);
278 if (e && e->GetDeclId()) {
279 fIds->Remove((Long64_t)e->GetDeclId());
280 }
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Remove object from this collection and recursively remove the object
285/// from all other objects (and collections).
286/// This function overrides TCollection::RecursiveRemove that calls
287/// the Remove function. THashList::Remove cannot be called because
288/// it uses the hash value of the hash table. This hash value
289/// is not available anymore when RecursiveRemove is called from
290/// the TObject destructor.
291
293{
294 if (!obj) return;
295
298 UnmapObject(obj);
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// Remove object from the list.
303
305{
306 Bool_t found;
307
308 found = THashList::Remove(obj);
309 if (!found) {
310 found = fUnloaded->Remove(obj);
311 }
312 UnmapObject(obj);
313 if (found) return obj;
314 else return nullptr;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Remove object via its objlink from the list.
319
321{
322 if (!lnk) return nullptr;
323
324 TObject *obj = lnk->GetObject();
325
327 fUnloaded->Remove(obj);
328 UnmapObject(obj);
329 return obj;
330}
331
332////////////////////////////////////////////////////////////////////////////////
333/// Load all the DataMembers known to the interpreter for the scope 'fClass'
334/// into this collection.
335
337{
338 if (fClass && fClass->Property() & (kIsClass | kIsStruct | kIsUnion)) {
339 // Class and union are not extendable, if we already
340 // loaded all the data member there is no need to recheck
341 if (fIsLoaded) return;
342 }
343
344 // This will provoke the parsing of the headers if need be.
345 if (fClass && fClass->GetClassInfo() == nullptr) return;
346
348
349 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
351 return;
352 }
354
355 // In the case of namespace, even if we have loaded before we need to
356 // load again in case there was new data member added.
357
358 // Mark the list as loaded to avoid an infinite recursion in the case
359 // where we have a data member that is a variable size array. In that
360 // case TDataMember::Init needs to get/load the list to find the data
361 // member used as the array size.
363
364 // Respawn the unloaded enums if they come from protoclasses, i.e. they
365 // have a 0 declId.
366#if defined(R__MUST_REVISIT)
367# if R__MUST_REVISIT(6,4)
368 "This special case can be removed once PCMs are available."
369# endif
370#endif
371
372 std::forward_list<TEnum*> respownedEnums;
373 for (auto enumAsObj : *fUnloaded){
374 TEnum* en = static_cast<TEnum*>(enumAsObj);
375 if (nullptr == en->GetDeclId()){
377 respownedEnums.push_front(en);
378 }
379 }
380
381 for (auto en : respownedEnums)
383
384 // We cannot clear the whole unloaded list. It is too much.
385// fUnloaded->Clear();
386
387 gInterpreter->LoadEnums(*this);
388}
389
390////////////////////////////////////////////////////////////////////////////////
391/// Mark 'all func' as being unloaded.
392/// After the unload, the data member can no longer be found directly,
393/// until the decl can be found again in the interpreter (in which
394/// the func object will be reused.
395
397{
399 while (lnk) {
400 TEnum *data = (TEnum *)lnk->GetObject();
401
402 if (data->GetDeclId())
403 fIds->Remove((Long64_t)data->GetDeclId());
405
406 lnk = lnk->Next();
407 }
408
411}
412
413////////////////////////////////////////////////////////////////////////////////
414/// Mark enum 'e' as being unloaded.
415/// After the unload, the data member can no longer be found directly,
416/// until the decl can be found again in the interpreter (in which
417/// the func object will be reused.
418
420{
421 if (THashList::Remove(e)) {
422 // We contains the object, let remove it from the other internal
423 // list and move it to the list of unloaded objects.
424 if (e->GetDeclId())
425 fIds->Remove((Long64_t)e->GetDeclId());
426 fUnloaded->Add(e);
427 }
428}
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:102
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:125