Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
28 ClassImp(TListOfEnumsWithLock);
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 
32 TListOfEnumsWithLock::TListOfEnumsWithLock(TClass *cl /*=0*/) :
33 TListOfEnums(cl)
34 {
35 }
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Destructor.
39 
40 TListOfEnumsWithLock::~TListOfEnumsWithLock()
41 {
42 }
43 
44 ////////////////////////////////////////////////////////////////////////////////
45 /// Add object at the beginning of the list.
46 
47 void TListOfEnumsWithLock::AddFirst(TObject *obj)
48 {
49  R__LOCKGUARD(gInterpreterMutex);
50  TListOfEnums::AddFirst(obj);
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 
60 void TListOfEnumsWithLock::AddFirst(TObject *obj, Option_t *opt)
61 {
62  R__LOCKGUARD(gInterpreterMutex);
63  TListOfEnums::AddFirst(obj, opt);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Add object at the end of the list.
68 
69 void TListOfEnumsWithLock::AddLast(TObject *obj)
70 {
71  R__LOCKGUARD(gInterpreterMutex);
72  TListOfEnums::AddLast(obj);
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 
82 void TListOfEnumsWithLock::AddLast(TObject *obj, Option_t *opt)
83 {
84  R__LOCKGUARD(gInterpreterMutex);
85  TListOfEnums::AddLast(obj, opt);
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Insert object at location idx in the list.
90 
91 void TListOfEnumsWithLock::AddAt(TObject *obj, Int_t idx)
92 {
93  R__LOCKGUARD(gInterpreterMutex);
94  TListOfEnums::AddAt(obj, idx);
95 }
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// Insert object after object after in the list.
99 
100 void TListOfEnumsWithLock::AddAfter(const TObject *after, TObject *obj)
101 {
102  R__LOCKGUARD(gInterpreterMutex);
103  TListOfEnums::AddAfter(after, obj);
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Insert object after object after in the list.
108 
109 void TListOfEnumsWithLock::AddAfter(TObjLink *after, TObject *obj)
110 {
111  R__LOCKGUARD(gInterpreterMutex);
112  TListOfEnums::AddAfter(after, obj);
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Insert object before object before in the list.
117 
118 void TListOfEnumsWithLock::AddBefore(const TObject *before, TObject *obj)
119 {
120  R__LOCKGUARD(gInterpreterMutex);
121  TListOfEnums::AddBefore(before, obj);
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Insert object before object before in the list.
126 
127 void TListOfEnumsWithLock::AddBefore(TObjLink *before, TObject *obj)
128 {
129  R__LOCKGUARD(gInterpreterMutex);
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 
137 void TListOfEnumsWithLock::Clear(Option_t *option)
138 {
139  R__LOCKGUARD(gInterpreterMutex);
140  TListOfEnums::Clear(option);
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// Delete all TDataMember object files.
145 
146 void TListOfEnumsWithLock::Delete(Option_t *option /* ="" */)
147 {
148  R__LOCKGUARD(gInterpreterMutex);
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 
156 TObject *TListOfEnumsWithLock::FindObject(const char *name) const
157 {
158  R__LOCKGUARD(gInterpreterMutex);
159  TObject *result = TListOfEnums::FindObject(name);
160  if (!result) {
161 
162 
163  TInterpreter::DeclId_t decl;
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 
174 TObject* TListOfEnumsWithLock::FindObject(const TObject* obj) const
175 {
176  R__LOCKGUARD(gInterpreterMutex);
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 
184 TEnum *TListOfEnumsWithLock::GetObject(const char *name) const
185 {
186  R__LOCKGUARD(gInterpreterMutex);
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 
199 void TListOfEnumsWithLock::RecursiveRemove(TObject *obj)
200 {
201  if (!obj) return;
202 
203  R__LOCKGUARD(gInterpreterMutex);
204  TListOfEnums::RecursiveRemove(obj);
205 }
206 
207 ////////////////////////////////////////////////////////////////////////////////
208 /// Remove object from the list.
209 
210 TObject *TListOfEnumsWithLock::Remove(TObject *obj)
211 {
212  R__LOCKGUARD(gInterpreterMutex);
213  return TListOfEnums::Remove(obj);
214 }
215 
216 ////////////////////////////////////////////////////////////////////////////////
217 /// Remove object via its objlink from the list.
218 
219 TObject *TListOfEnumsWithLock::Remove(TObjLink *lnk)
220 {
221  if (!lnk) return 0;
222 
223  R__LOCKGUARD(gInterpreterMutex);
224  return TListOfEnums::Remove(lnk);
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 
229 TIterator* TListOfEnumsWithLock::MakeIterator(Bool_t dir ) const
230 {
231  R__LOCKGUARD(gInterpreterMutex);
232  return new TListOfEnumsWithLockIter(this,dir);
233 }
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 
237 TObject* TListOfEnumsWithLock::At(Int_t idx) const
238 {
239  R__LOCKGUARD(gInterpreterMutex);
240  return TListOfEnums::At(idx);
241 }
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 
245 TObject* TListOfEnumsWithLock::After(const TObject *obj) const
246 {
247  R__LOCKGUARD(gInterpreterMutex);
248  return TListOfEnums::After(obj);
249 }
250 
251 ////////////////////////////////////////////////////////////////////////////////
252 
253 TObject* TListOfEnumsWithLock::Before(const TObject *obj) const
254 {
255  R__LOCKGUARD(gInterpreterMutex);
256  return TListOfEnums::Before(obj);
257 }
258 
259 ////////////////////////////////////////////////////////////////////////////////
260 
261 TObject* TListOfEnumsWithLock::First() const
262 {
263  R__LOCKGUARD(gInterpreterMutex);
264  return TListOfEnums::First();
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 
269 TObjLink* TListOfEnumsWithLock::FirstLink() const
270 {
271  R__LOCKGUARD(gInterpreterMutex);
272  return TListOfEnums::FirstLink();
273 }
274 
275 ////////////////////////////////////////////////////////////////////////////////
276 
277 TObject** TListOfEnumsWithLock::GetObjectRef(const TObject *obj) const
278 {
279  R__LOCKGUARD(gInterpreterMutex);
280  return TListOfEnums::GetObjectRef(obj);
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 
285 TObject* TListOfEnumsWithLock::Last() const
286 {
287  R__LOCKGUARD(gInterpreterMutex);
288  return TListOfEnums::Last();
289 }
290 
291 ////////////////////////////////////////////////////////////////////////////////
292 
293 TObjLink* TListOfEnumsWithLock::LastLink() const
294 {
295  R__LOCKGUARD(gInterpreterMutex);
296  return TListOfEnums::LastLink();
297 }
298 
299 
300 ////////////////////////////////////////////////////////////////////////////////
301 
302 Int_t TListOfEnumsWithLock::GetLast() const
303 {
304  R__LOCKGUARD(gInterpreterMutex);
305  return TListOfEnums::GetLast();
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 
310 Int_t TListOfEnumsWithLock::IndexOf(const TObject *obj) const
311 {
312  R__LOCKGUARD(gInterpreterMutex);
313  return TListOfEnums::IndexOf(obj);
314 }
315 
316 
317 ////////////////////////////////////////////////////////////////////////////////
318 
319 Int_t TListOfEnumsWithLock::GetSize() const
320 {
321  R__LOCKGUARD(gInterpreterMutex);
322  return TListOfEnums::GetSize();
323 }
324 
325 /** \class TListOfEnumsWithLockIter
326 Iterator for TListOfEnumsWithLock.
327 */
328 
329 ClassImp(TListOfEnumsWithLockIter);
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 
333 TListOfEnumsWithLockIter::TListOfEnumsWithLockIter(const TListOfEnumsWithLock *l, Bool_t dir ):
334 TListIter(l,dir) {}
335 
336 ////////////////////////////////////////////////////////////////////////////////
337 
338 TObject *TListOfEnumsWithLockIter::Next()
339 {
340  R__LOCKGUARD(gInterpreterMutex);
341  return TListIter::Next();
342 }