ROOT  6.06/09
Reference Guide
TViewPubDataMembers.cxx
Go to the documentation of this file.
1 // @(#)root/cont:$Id$
2 // Author: Philippe Canal October 2013
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, 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 TViewPubDataMembers
13 View implementing the TList interface and giving access all the
14 TDictionary describing public data members in a class and all its
15 base classes without caching any of the TDictionary pointers.
16 
17 Adding to this collection directly is prohibited.
18 Iteration can only be done via the TIterator interfaces.
19 */
20 
21 #include "TViewPubDataMembers.h"
22 
23 #include "TClass.h"
24 #include "TBaseClass.h"
25 #include "TError.h"
26 #include "TDictionary.h"
27 #include "THashList.h"
28 
29 // ClassImp(TViewPubDataMembers)
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// loop over all base classes and add them to the container.
33 
34 static void AddBasesClasses(TList &bases, TClass *cl)
35 {
36  TIter nextBaseClass(cl->GetListOfBases());
37  TBaseClass *base;
38  while ((base = (TBaseClass*) nextBaseClass())) {
39  if (!base->GetClassPointer()) continue;
40  if (!(base->Property() & kIsPublic)) continue;
41 
42  bases.Add(base->GetClassPointer());
43  AddBasesClasses(bases,base->GetClassPointer());
44  }
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// Usual constructor
49 
51 {
52  if (cl) {
53  fClasses.Add(cl);
55  }
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Default destructor.
60 
62 {
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// Clear is not allowed in this class.
67 /// See TList::Clear for the intended behavior.
68 
69 void TViewPubDataMembers::Clear(Option_t * /* option="" */)
70 {
71  ::Error("TViewPubDataMembers::Clear","Operation not allowed on a view.");
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Delete is not allowed in this class.
76 /// See TList::Delete for the intended behavior.
77 
78 void TViewPubDataMembers::Delete(Option_t * /*option="" */)
79 {
80  ::Error("TViewPubDataMembers::Delete","Operation not allowed on a view.");
81 }
82 
83 ////////////////////////////////////////////////////////////////////////////////
84 /// Find an object in this list using its name. Requires a sequential
85 /// scan till the object has been found. Returns 0 if object with specified
86 /// name is not found.
87 
89 {
91  while (TClass *cl = (TClass*)next()) {
92  THashList *hl = dynamic_cast<THashList*>(cl->GetListOfDataMembers(kFALSE));
93  TIter content_next(hl->GetListForObject(name));
94  while (TDictionary *p = (TDictionary*) content_next())
95  if (p->Property() & kIsPublic) return p;
96  }
97  return 0;
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Find an object in this list using the object's IsEqual()
102 /// member function. Requires a sequential scan till the object has
103 /// been found. Returns 0 if object is not found.
104 
106 {
107  TIter next(&fClasses);
108  while (TClass *cl = (TClass*)next()) {
109  TObject *result = cl->GetListOfDataMembers(kFALSE)->FindObject(obj);
110  if (result) return result;
111  }
112  return 0;
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// Return a list iterator.
117 
118 TIterator *TViewPubDataMembers::MakeIterator(Bool_t dir /* = kIterForward*/) const
119 {
120  return new TViewPubDataMembersIter(this, dir);
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 /// AddFirst is not allowed in this class.
125 /// See TList::AddFirst for the intended behavior.
126 
128 {
129  ::Error("TViewPubDataMembers::AddFirst","Operation not allowed on a view.");
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// AddFirst is not allowed in this class.
134 /// See TList::AddFirst for the intended behavior.
135 
136 void TViewPubDataMembers::AddFirst(TObject * /* obj */, Option_t * /* opt */)
137 {
138  ::Error("TViewPubDataMembers::AddFirst","Operation not allowed on a view.");
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 /// AddLast is not allowed in this class.
143 /// See TList::AddLast for the intended behavior.
144 
146 {
147  ::Error("TViewPubDataMembers::AddLast","Operation not allowed on a view.");
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// AddLast is not allowed in this class.
152 /// See TList::AddLast for the intended behavior.
153 
154 void TViewPubDataMembers::AddLast(TObject * /* obj */, Option_t * /* opt */)
155 {
156  ::Error("TViewPubDataMembers::AddLast","Operation not allowed on a view.");
157 }
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 /// AddAt is not allowed in this class.
161 /// See TList::AddAt for the intended behavior.
162 
163 void TViewPubDataMembers::AddAt(TObject * /* obj */, Int_t /* idx */)
164 {
165  ::Error("TViewPubDataMembers::AddAt","Operation not allowed on a view.");
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// AddAfter is not allowed in this class.
170 /// See TList::AddAfter for the intended behavior.
171 
172 void TViewPubDataMembers::AddAfter(const TObject * /* after */, TObject * /* obj */)
173 {
174  ::Error("TViewPubDataMembers::RemAddLastove","Operation not allowed on a view.");
175 }
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// AddAfter is not allowed in this class.
179 /// See TList::AddAfter for the intended behavior.
180 
181 void TViewPubDataMembers::AddAfter(TObjLink * /* after */, TObject * /* obj */)
182 {
183  ::Error("TViewPubDataMembers::AddAfter","Operation not allowed on a view.");
184 }
185 
186 ////////////////////////////////////////////////////////////////////////////////
187 /// AddBefore is not allowed in this class.
188 /// See TList::AddBefore for the intended behavior.
189 
190 void TViewPubDataMembers::AddBefore(const TObject * /* before */, TObject * /* obj */)
191 {
192  ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
193 }
194 
195 ////////////////////////////////////////////////////////////////////////////////
196 /// AddBefore is not allowed in this class.
197 /// See TList::AddBefore for the intended behavior.
198 
199 void TViewPubDataMembers::AddBefore(TObjLink * /* before */, TObject * /* obj */)
200 {
201  ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
202 }
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 /// Returns the object at position idx. Returns 0 if idx is out of range.
206 
208 {
209  Int_t i = 0;
210  TIter next(&fClasses);
211  while (TClass *cl = (TClass*)next()) {
212  TIter content_next(cl->GetListOfDataMembers(kFALSE));
213  while (TDictionary *p = (TDictionary*) content_next()) {
214  if (p->Property() & kIsPublic) {
215  if (i == idx) return p;
216  ++i;
217  }
218  }
219  }
220  return 0;
221 }
222 
223 ////////////////////////////////////////////////////////////////////////////////
224 /// After is not allowed in this class.
225 /// See TList::After for the intended behavior.
226 
227 TObject *TViewPubDataMembers::After(const TObject * /* obj */) const
228 {
229  ::Error("TViewPubDataMembers::After","Operation not allowed on a view.");
230  return 0;
231 }
232 
233 ////////////////////////////////////////////////////////////////////////////////
234 /// Before is not allowed in this class.
235 /// See TList::Before for the intended behavior.
236 
237 TObject *TViewPubDataMembers::Before(const TObject * /* obj */) const
238 {
239  ::Error("TViewPubDataMembers::Before","Operation not allowed on a view.");
240  return 0;
241 }
242 
243 ////////////////////////////////////////////////////////////////////////////////
244 /// First is not allowed in this class.
245 /// See TList::First for the intended behavior.
246 
248 {
249  ::Error("TViewPubDataMembers::First","Operation not allowed on a view.");
250  return 0;
251 }
252 
253 ////////////////////////////////////////////////////////////////////////////////
254 /// FirstLink is not allowed in this class.
255 /// See TList::FirstLink for the intended behavior.
256 
258 {
259  ::Error("TViewPubDataMembers::FirstLink","Operation not allowed on a view.");
260  return 0;
261 }
262 
263 ////////////////////////////////////////////////////////////////////////////////
264 /// GetObjectRef is not allowed in this class.
265 /// See TList::GetObjectRef for the intended behavior.
266 
268 {
269  ::Error("TViewPubDataMembers::GetObjectRef","Operation not yet allowed on a view.");
270  return 0;
271 }
272 
273 ////////////////////////////////////////////////////////////////////////////////
274 /// Return the total number of public data members(currently loaded in the list
275 /// of DataMembers) in this class and all its base classes.
276 
278 {
279  Int_t size = 0;
280  TIter next(&fClasses);
281  while (TClass *cl = (TClass*)next()) {
282  TIter content_next(cl->GetListOfDataMembers(kFALSE));
283  while (TDictionary *p = (TDictionary*) content_next())
284  if (p->Property() & kIsPublic) ++size;
285  }
286  return size;
287 
288 }
289 
290 ////////////////////////////////////////////////////////////////////////////////
291 /// Load all the DataMembers known to the interpreter for the scope 'fClass'
292 /// and all its bases classes.
293 
295 {
296  TIter next(&fClasses);
297  while (TClass *cl = (TClass*)next()) {
298  cl->GetListOfDataMembers(kTRUE);
299  }
300 }
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 /// Last is not allowed in this class.
304 /// See TList::Last for the intended behavior.
305 
307 {
308  ::Error("TViewPubDataMembers::Last","Operation not allowed on a view.");
309  return 0;
310 }
311 
312 ////////////////////////////////////////////////////////////////////////////////
313 /// LastLink is not allowed in this class.
314 /// See TList::LastLink for the intended behavior.
315 
317 {
318  ::Error("TViewPubDataMembers::LastLink","Operation not allowed on a view.");
319  return 0;
320 }
321 
322 ////////////////////////////////////////////////////////////////////////////////
323 /// RecursiveRemove is not allowed in this class.
324 /// See TList::RecursiveRemove for the intended behavior.
325 
327 {
328  ::Error("TViewPubDataMembers::RecursiveRemove","Operation not allowed on a view.");
329 }
330 
331 ////////////////////////////////////////////////////////////////////////////////
332 /// Remove is not allowed in this class.
333 /// See TList::Remove for the intended behavior.
334 
336 {
337  ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
338  return 0;
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Remove is not allowed in this class.
343 /// See TList::Remove for the intended behavior.
344 
346 {
347  ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
348  return 0;
349 }
350 
351 /** \class TViewPubDataMembersIter
352 Iterator of over the view's content.
353 */
354 
355 // ClassImp(TViewPubDataMembersIter)
356 
357 ////////////////////////////////////////////////////////////////////////////////
358 /// Create a new list iterator. By default the iteration direction
359 /// is kIterForward. To go backward use kIterBackward.
360 
362 : fView(l),fClassIter(l->GetListOfClasses(),dir), fIter((TCollection *)0),
363 fStarted(kFALSE), fDirection(dir)
364 {
365 }
366 
367 ////////////////////////////////////////////////////////////////////////////////
368 /// Copy ctor.
369 
371 TIterator(iter), fView(iter.fView),
372 fClassIter(iter.fClassIter), fIter(iter.fIter),
373 fStarted(iter.fStarted), fDirection(iter.fDirection)
374 {
375 }
376 
377 ////////////////////////////////////////////////////////////////////////////////
378 /// Overridden assignment operator.
379 
381 {
382  const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&rhs);
383  if (this != &rhs && iter) {
384  fView = iter->fView;
385  fClassIter = iter->fClassIter;
386  fIter = iter->fIter;
387  fStarted = iter->fStarted;
388  fDirection = iter->fDirection;
389  }
390  return *this;
391 }
392 
393 ////////////////////////////////////////////////////////////////////////////////
394 /// Overloaded assignment operator.
395 
397 {
398  if (this != &rhs) {
399  fView = rhs.fView;
400  fClassIter = rhs.fClassIter;
401  fIter = rhs.fIter;
402  fStarted = rhs.fStarted;
403  fDirection = rhs.fDirection;
404  }
405  return *this;
406 }
407 
408 ////////////////////////////////////////////////////////////////////////////////
409 /// Return next object in the list. Returns 0 when no more objects in list.
410 
412 {
413  if (!fView) return 0;
414 
415  if (!fStarted) {
416  TClass *current = (TClass*)fClassIter();
417  fStarted = kTRUE;
418  if (current) {
419  fIter.~TIter();
420  new (&(fIter)) TIter(current->GetListOfDataMembers(kFALSE),fDirection);
421  } else {
422  return 0;
423  }
424  }
425 
426  while (1) {
427 
429  if (!obj) {
430  // End of list of DataMembers, move to the next;
431  TClass *current = (TClass*)fClassIter();
432  if (current) {
433  fIter.~TIter();
434  new (&(fIter)) TIter(current->GetListOfDataMembers(kFALSE),fDirection);
435  continue;
436  } else {
437  return 0;
438  }
439  } else if (obj->Property() & kIsPublic) {
440  // If it is public we found the next one.
441  return obj;
442  }
443 
444  }
445  // Not reachable.
446  return 0;
447 }
448 
449 ////////////////////////////////////////////////////////////////////////////////
450 /// Reset list iterator.
451 
453 {
454  fStarted = kFALSE;
455  fClassIter.Reset();
456 }
457 
458 ////////////////////////////////////////////////////////////////////////////////
459 /// This operator compares two TIterator objects.
460 
462 {
463  const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&aIter);
464  if (iter) {
465  return (fClassIter != iter->fClassIter || fIter != iter->fIter);
466  }
467  return false; // for base class we don't implement a comparison
468 }
469 
470 ////////////////////////////////////////////////////////////////////////////////
471 /// This operator compares two TViewPubDataMembersIter objects.
472 
474 {
475  return (fClassIter != aIter.fClassIter || fIter != aIter.fIter);
476 }
477 
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
virtual TObjLink * FirstLink() const
FirstLink is not allowed in this class.
virtual TObject * Before(const TObject *obj) const
Before is not allowed in this class.
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition: TClass.cxx:3448
void AddLast(TObject *obj)
AddLast is not allowed in this class.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
virtual TObject ** GetObjectRef(const TObject *obj) const
GetObjectRef is not allowed in this class.
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
const char Option_t
Definition: RtypesCore.h:62
virtual TObject * First() const
First is not allowed in this class.
virtual ~TViewPubDataMembers()
Default destructor.
static void AddBasesClasses(TList &bases, TClass *cl)
loop over all base classes and add them to the container.
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition: TClass.cxx:3539
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
TViewPubDataMembers(const TViewPubDataMembers &)
Iterator abstract base class.
Definition: TIterator.h:32
void Reset()
Definition: TCollection.h:161
const TList * GetListForObject(const char *name) const
Return the THashTable's list (bucket) in which obj can be found based on its hash; see THashTable::Ge...
Definition: THashList.cxx:229
TObject * FindObject(const char *name) const
Find an object in this list using its name.
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
Bool_t operator!=(const TIterator &aIter) const
This operator compares two TIterator objects.
TObject * Remove(TObject *obj)
Remove is not allowed in this class.
void AddBefore(const TObject *before, TObject *obj)
AddBefore is not allowed in this class.
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
void AddFirst(TObject *obj)
AddFirst is not allowed in this class.
Iterator of over the view's content.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:918
A doubly linked list.
Definition: TList.h:47
View implementing the TList interface and giving access all the TDictionary describing public data me...
void RecursiveRemove(TObject *obj)
RecursiveRemove is not allowed in this class.
virtual ~TIter()
Definition: TCollection.h:156
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:162
void Delete(Option_t *option="")
Delete is not allowed in this class.
virtual TObjLink * LastLink() const
LastLink is not allowed in this class.
Collection abstract base class.
Definition: TCollection.h:48
TLine * l
Definition: textangle.C:4
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
void Reset()
Reset list iterator.
Each class (see TClass) has a linked list of its base class(es).
Definition: TBaseClass.h:35
void AddAfter(const TObject *after, TObject *obj)
AddAfter is not allowed in this class.
void AddAt(TObject *obj, Int_t idx)
AddAt is not allowed in this class.
virtual TObject * After(const TObject *obj) const
After is not allowed in this class.
virtual TObject * Last() const
Last is not allowed in this class.
virtual Long_t Property() const =0
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
void Clear(Option_t *option="")
Clear is not allowed in this class.
virtual void Add(TObject *obj)
Definition: TList.h:81
virtual Int_t GetSize() const
Return the total number of public data members(currently loaded in the list of DataMembers) in this c...
void Load()
Load all the DataMembers known to the interpreter for the scope 'fClass' and all its bases classes...
double result[121]
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
TIterator & operator=(const TIterator &rhs)
Overridden assignment operator.