Logo ROOT  
Reference Guide
TListOfEnumsWithLock.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 TListOfEnumsWithLock
13 A collection of TEnum objects designed for fast access given a
14 DeclId_t and for keep track of TEnum that were described
15 unloaded enum.
16 */
17 
18 #include <forward_list>
19 
20 #include "TListOfEnumsWithLock.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 
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 
33 TListOfEnums(cl)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Destructor.
39 
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Add object at the beginning of the list.
46 
48 {
51 }
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 /// Add object at the beginning of the list and also store option.
55 /// Storing an option is useful when one wants to change the behaviour
56 /// of an object a little without having to create a complete new
57 /// copy of the object. This feature is used, for example, by the Draw()
58 /// method. It allows the same object to be drawn in different ways.
59 
61 {
63  TListOfEnums::AddFirst(obj, opt);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Add object at the end of the list.
68 
70 {
73 }
74 
75 ////////////////////////////////////////////////////////////////////////////////
76 /// Add object at the end of the list and also store option.
77 /// Storing an option is useful when one wants to change the behaviour
78 /// of an object a little without having to create a complete new
79 /// copy of the object. This feature is used, for example, by the Draw()
80 /// method. It allows the same object to be drawn in different ways.
81 
83 {
85  TListOfEnums::AddLast(obj, opt);
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Insert object at location idx in the list.
90 
92 {
94  TListOfEnums::AddAt(obj, idx);
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Insert object after object after in the list.
99 
101 {
103  TListOfEnums::AddAfter(after, obj);
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Insert object after object after in the list.
108 
110 {
112  TListOfEnums::AddAfter(after, obj);
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Insert object before object before in the list.
117 
119 {
121  TListOfEnums::AddBefore(before, obj);
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Insert object before object before in the list.
126 
128 {
130  TListOfEnums::AddBefore(before, obj);
131 }
132 
133 ////////////////////////////////////////////////////////////////////////////////
134 /// Remove all objects from the list. Does not delete the objects unless
135 /// the THashList is the owner (set via SetOwner()).
136 
138 {
140  TListOfEnums::Clear(option);
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Delete all TDataMember object files.
145 
146 void TListOfEnumsWithLock::Delete(Option_t *option /* ="" */)
147 {
149  TListOfEnums::Delete(option);
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Specialize FindObject to do search for the
154 /// a enum just by name or create it if its not already in the list
155 
157 {
160  if (!result) {
161 
162 
164  if (GetClass()) decl = gInterpreter->GetEnum(GetClass(), name);
165  else decl = gInterpreter->GetEnum(0, name);
166  if (decl) result = const_cast<TListOfEnumsWithLock *>(this)->Get(decl, name);
167  }
168  return result;
169 }
170 
171 
172 ////////////////////////////////////////////////////////////////////////////////
173 
175 {
177  return TListOfEnums::FindObject(obj);
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Return an object from the list of enums *if and only if* is has already
182 /// been loaded in the list. This is an internal routine.
183 
185 {
187  return (TEnum*)THashList::FindObject(name);
188 }
189 
190 ////////////////////////////////////////////////////////////////////////////////
191 /// Remove object from this collection and recursively remove the object
192 /// from all other objects (and collections).
193 /// This function overrides TCollection::RecursiveRemove that calls
194 /// the Remove function. THashList::Remove cannot be called because
195 /// it uses the hash value of the hash table. This hash value
196 /// is not available anymore when RecursiveRemove is called from
197 /// the TObject destructor.
198 
200 {
201  if (!obj) return;
202 
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Remove object from the list.
209 
211 {
213  return TListOfEnums::Remove(obj);
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Remove object via its objlink from the list.
218 
220 {
221  if (!lnk) return 0;
222 
224  return TListOfEnums::Remove(lnk);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 
230 {
232  return new TListOfEnumsWithLockIter(this,dir);
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 
238 {
240  return TListOfEnums::At(idx);
241 }
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 
246 {
248  return TListOfEnums::After(obj);
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 
254 {
256  return TListOfEnums::Before(obj);
257 }
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 
262 {
264  return TListOfEnums::First();
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 
270 {
272  return TListOfEnums::FirstLink();
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 
278 {
280  return TListOfEnums::GetObjectRef(obj);
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 
286 {
288  return TListOfEnums::Last();
289 }
290 
291 ////////////////////////////////////////////////////////////////////////////////
292 
294 {
296  return TListOfEnums::LastLink();
297 }
298 
299 
300 ////////////////////////////////////////////////////////////////////////////////
301 
303 {
305  return TListOfEnums::GetLast();
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 
311 {
313  return TListOfEnums::IndexOf(obj);
314 }
315 
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 
320 {
322  return TListOfEnums::GetSize();
323 }
324 
325 /** \class TListOfEnumsWithLockIter
326 Iterator for TListOfEnumsWithLock.
327 */
328 
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 
334 TListIter(l,dir) {}
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 
339 {
341  return TListIter::Next();
342 }
l
auto * l
Definition: textangle.C:4
TListOfEnumsWithLock::FindObject
TObject * FindObject(const TObject *obj) const override
Find object using its hash value (returned by its Hash() member).
Definition: TListOfEnumsWithLock.cxx:174
TList::LastLink
virtual TObjLink * LastLink() const
Definition: TList.h:111
TListOfEnums::AddAt
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
Definition: TListOfEnums.cxx:111
TList::GetObjectRef
virtual TObject ** GetObjectRef(const TObject *obj) const
Return address of pointer to obj.
Definition: TList.cxx:670
TListOfEnumsWithLock::After
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition: TListOfEnumsWithLock.cxx:245
TListOfEnums::AddLast
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition: TListOfEnums.cxx:89
TListOfEnumsWithLock::RecursiveRemove
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TListOfEnumsWithLock.cxx:199
TListOfEnumsWithLockIter::TListOfEnumsWithLockIter
TListOfEnumsWithLockIter(const TListOfEnumsWithLock *l, Bool_t dir=kIterForward)
Definition: TListOfEnumsWithLock.cxx:333
TListOfEnumsWithLockIter::Next
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
Definition: TListOfEnumsWithLock.cxx:338
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TListOfEnums::Get
TEnum * Get(DeclId_t id, const char *name)
Return (after creating it if necessary) the TEnum describing the enum corresponding to the Decl 'id'.
Definition: TListOfEnums.cxx:190
TListOfEnumsWithLock::FirstLink
TObjLink * FirstLink() const override
Definition: TListOfEnumsWithLock.cxx:269
TListOfEnumsWithLock::First
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition: TListOfEnumsWithLock.cxx:261
TListOfEnumsWithLock.h
TListOfEnumsWithLock::TListOfEnumsWithLock
TListOfEnumsWithLock(const TListOfEnumsWithLock &)=delete
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:560
TListOfEnumsWithLock::GetSize
Int_t GetSize() const override
Return the capacity of the collection, i.e.
Definition: TListOfEnumsWithLock.cxx:319
TListOfEnumsWithLock
Definition: TListOfEnumsWithLock.h:30
TInterpreter::DeclId_t
TDictionary::DeclId_t DeclId_t
Definition: TInterpreter.h:288
TClass.h
TList::Last
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TList.cxx:692
TListOfEnumsWithLock::Last
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition: TListOfEnumsWithLock.cxx:285
TListOfEnumsWithLock::IndexOf
Int_t IndexOf(const TObject *obj) const override
Return index of object in collection.
Definition: TListOfEnumsWithLock.cxx:310
TListOfEnumsWithLock::GetObject
TEnum * GetObject(const char *) const override
Return an object from the list of enums if and only if is has already been loaded in the list.
Definition: TListOfEnumsWithLock.cxx:184
bool
TIterator
Definition: TIterator.h:30
TListIter
Definition: TList.h:197
TListOfEnums::AddBefore
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition: TListOfEnums.cxx:138
TSeqCollection::IndexOf
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
Definition: TSeqCollection.cxx:30
TListOfEnumsWithLock::LastLink
TObjLink * LastLink() const override
Definition: TListOfEnumsWithLock.cxx:293
TListOfEnumsWithLock::GetLast
Int_t GetLast() const override
Returns index of last object in collection.
Definition: TListOfEnumsWithLock.cxx:302
TListOfEnumsWithLock::~TListOfEnumsWithLock
~TListOfEnumsWithLock() override
Destructor.
Definition: TListOfEnumsWithLock.cxx:40
TListIter::Next
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
Definition: TList.cxx:1112
TList::First
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Definition: TList.cxx:658
TListOfEnumsWithLock::Remove
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition: TListOfEnumsWithLock.cxx:210
TListOfEnums::Clear
void Clear(Option_t *option) override
Remove all objects from the list.
Definition: TListOfEnums.cxx:157
TList::At
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:356
TList::After
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Definition: TList.cxx:329
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TList::FirstLink
virtual TObjLink * FirstLink() const
Definition: TList.h:108
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:44
TEnum.h
TListOfEnumsWithLockIter
Definition: TListOfEnumsWithLock.h:91
TList::Before
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
Definition: TList.cxx:370
THashList::FindObject
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
TEnum
Definition: TEnum.h:33
TListOfEnumsWithLock::AddBefore
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
Definition: TListOfEnumsWithLock.cxx:118
TGlobal.h
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TListOfEnumsWithLock::AddLast
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition: TListOfEnumsWithLock.cxx:69
TVirtualMutex.h
TListOfEnumsWithLock::GetObjectRef
TObject ** GetObjectRef(const TObject *obj) const override
Return address of pointer to obj.
Definition: TListOfEnumsWithLock.cxx:277
TListOfEnums::Remove
TObject * Remove(TObject *obj) override
Remove object from the list.
Definition: TListOfEnums.cxx:290
TListOfEnumsWithLock::AddAfter
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
Definition: TListOfEnumsWithLock.cxx:100
TListOfEnums
Definition: TListOfEnums.h:32
TListOfEnumsWithLock::Clear
void Clear(Option_t *option) override
Remove all objects from the list.
Definition: TListOfEnumsWithLock.cxx:137
TListOfEnumsWithLock::AddFirst
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition: TListOfEnumsWithLock.cxx:47
TListOfEnums::GetClass
TClass * GetClass() const
Definition: TListOfEnums.h:62
TListOfEnums::AddFirst
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition: TListOfEnums.cxx:67
TCollection::GetSize
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TInterpreter.h
TClass
Definition: TClass.h:80
TListOfEnumsWithLock::Before
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
Definition: TListOfEnumsWithLock.cxx:253
TObject
Definition: TObject.h:37
TListOfEnumsWithLock::AddAt
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
Definition: TListOfEnumsWithLock.cxx:91
name
char name[80]
Definition: TGX11.cxx:110
TListOfEnumsWithLock::MakeIterator
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
Definition: TListOfEnumsWithLock.cxx:229
TListOfEnums::RecursiveRemove
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
Definition: TListOfEnums.cxx:278
TListOfEnums::Delete
void Delete(Option_t *option="") override
Delete all TDataMember object files.
Definition: TListOfEnums.cxx:168
TSeqCollection::GetLast
virtual Int_t GetLast() const
Returns index of last object in collection.
Definition: TSeqCollection.cxx:47
TListOfEnumsWithLock::At
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TListOfEnumsWithLock.cxx:237
TListOfEnumsWithLock::Delete
void Delete(Option_t *option="") override
Delete all TDataMember object files.
Definition: TListOfEnumsWithLock.cxx:146
TListOfEnums::AddAfter
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
Definition: TListOfEnums.cxx:120
TExMap.h
int