Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
13View implementing the TList interface and giving access all the
14TDictionary describing public data members in a class and all its
15base classes without caching any of the TDictionary pointers.
16
17Adding to this collection directly is prohibited.
18Iteration 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
30////////////////////////////////////////////////////////////////////////////////
31/// loop over all base classes and add them to the container.
32
34{
36 TBaseClass *base;
37 while ((base = (TBaseClass*) nextBaseClass())) {
38 if (!base->GetClassPointer()) continue;
39 if (!(base->Property() & kIsPublic)) continue;
40
41 bases.Add(base->GetClassPointer());
43 }
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Usual constructor
48
50{
51 if (cl) {
52 fClasses.Add(cl);
54 }
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Default destructor.
59
63
64////////////////////////////////////////////////////////////////////////////////
65/// Clear is not allowed in this class.
66/// See TList::Clear for the intended behavior.
67
68void TViewPubDataMembers::Clear(Option_t * /* option="" */)
69{
70 ::Error("TViewPubDataMembers::Clear","Operation not allowed on a view.");
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Delete is not allowed in this class.
75/// See TList::Delete for the intended behavior.
76
78{
79 ::Error("TViewPubDataMembers::Delete","Operation not allowed on a view.");
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// Find an object in this list using its name. Requires a sequential
84/// scan till the object has been found. Returns 0 if object with specified
85/// name is not found.
86
88{
89 TIter next(&fClasses);
90 while (TClass *cl = (TClass*)next()) {
91 THashList *hl = dynamic_cast<THashList*>(cl->GetListOfDataMembers(kFALSE));
92 TIter content_next(hl->GetListForObject(name));
93 while (TDictionary *p = (TDictionary*) content_next()) {
94 // The 'ListForObject' is actually a hash table bucket that can also
95 // contain other element/name.
96 if (strcmp(name,p->GetName())==0 && (p->Property() & kIsPublic))
97 return p;
98 }
99 }
100 return nullptr;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Find an object in this list using the object's IsEqual()
105/// member function. Requires a sequential scan till the object has
106/// been found. Returns 0 if object is not found.
107
109{
110 TIter next(&fClasses);
111 while (TClass *cl = (TClass*)next()) {
112 TObject *result = cl->GetListOfDataMembers(kFALSE)->FindObject(obj);
113 if (result) return result;
114 }
115 return nullptr;
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Return a list iterator.
120
122{
123 return new TViewPubDataMembersIter(this, dir);
124}
125
126////////////////////////////////////////////////////////////////////////////////
127/// AddFirst is not allowed in this class.
128/// See TList::AddFirst for the intended behavior.
129
131{
132 ::Error("TViewPubDataMembers::AddFirst","Operation not allowed on a view.");
133}
134
135////////////////////////////////////////////////////////////////////////////////
136/// AddFirst is not allowed in this class.
137/// See TList::AddFirst for the intended behavior.
138
139void TViewPubDataMembers::AddFirst(TObject * /* obj */, Option_t * /* opt */)
140{
141 ::Error("TViewPubDataMembers::AddFirst","Operation not allowed on a view.");
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// AddLast is not allowed in this class.
146/// See TList::AddLast for the intended behavior.
147
149{
150 ::Error("TViewPubDataMembers::AddLast","Operation not allowed on a view.");
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// AddLast is not allowed in this class.
155/// See TList::AddLast for the intended behavior.
156
157void TViewPubDataMembers::AddLast(TObject * /* obj */, Option_t * /* opt */)
158{
159 ::Error("TViewPubDataMembers::AddLast","Operation not allowed on a view.");
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// AddAt is not allowed in this class.
164/// See TList::AddAt for the intended behavior.
165
166void TViewPubDataMembers::AddAt(TObject * /* obj */, Int_t /* idx */)
167{
168 ::Error("TViewPubDataMembers::AddAt","Operation not allowed on a view.");
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// AddAt is not allowed in this class.
173/// See TList::AddAt for the intended behavior.
174
175void TViewPubDataMembers::AddAt(TObject * /* obj */, Int_t /* idx */, Option_t * /* opt */)
176{
177 ::Error("TViewPubDataMembers::AddAt","Operation not allowed on a view.");
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// AddAfter is not allowed in this class.
182/// See TList::AddAfter for the intended behavior.
183
184void TViewPubDataMembers::AddAfter(const TObject * /* after */, TObject * /* obj */)
185{
186 ::Error("TViewPubDataMembers::RemAddLastove","Operation not allowed on a view.");
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// AddAfter is not allowed in this class.
191/// See TList::AddAfter for the intended behavior.
192
193void TViewPubDataMembers::AddAfter(TObjLink * /* after */, TObject * /* obj */)
194{
195 ::Error("TViewPubDataMembers::AddAfter","Operation not allowed on a view.");
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// AddAfter is not allowed in this class.
200/// See TList::AddAfter for the intended behavior.
201
202void TViewPubDataMembers::AddAfter(const TObject * /* after */, TObject * /* obj */, Option_t * /* opt */)
203{
204 ::Error("TViewPubDataMembers::RemAddLastove","Operation not allowed on a view.");
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// AddAfter is not allowed in this class.
209/// See TList::AddAfter for the intended behavior.
210
211void TViewPubDataMembers::AddAfter(TObjLink * /* after */, TObject * /* obj */, Option_t * /* opt */)
212{
213 ::Error("TViewPubDataMembers::AddAfter","Operation not allowed on a view.");
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// AddBefore is not allowed in this class.
218/// See TList::AddBefore for the intended behavior.
219
220void TViewPubDataMembers::AddBefore(const TObject * /* before */, TObject * /* obj */)
221{
222 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// AddBefore is not allowed in this class.
227/// See TList::AddBefore for the intended behavior.
228
229void TViewPubDataMembers::AddBefore(TObjLink * /* before */, TObject * /* obj */)
230{
231 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// AddBefore is not allowed in this class.
236/// See TList::AddBefore for the intended behavior.
237
238void TViewPubDataMembers::AddBefore(const TObject * /* before */, TObject * /* obj */, Option_t * /* opt */)
239{
240 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// AddBefore is not allowed in this class.
245/// See TList::AddBefore for the intended behavior.
246
247void TViewPubDataMembers::AddBefore(TObjLink * /* before */, TObject * /* obj */, Option_t * /* opt */)
248{
249 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Returns the object at position idx. Returns 0 if idx is out of range.
254
256{
257 Int_t i = 0;
258 TIter next(&fClasses);
259 while (TClass *cl = (TClass*)next()) {
260 TIter content_next(cl->GetListOfDataMembers(kFALSE));
261 while (TDictionary *p = (TDictionary*) content_next()) {
262 if (p->Property() & kIsPublic) {
263 if (i == idx) return p;
264 ++i;
265 }
266 }
267 }
268 return nullptr;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// After is not allowed in this class.
273/// See TList::After for the intended behavior.
274
276{
277 ::Error("TViewPubDataMembers::After","Operation not allowed on a view.");
278 return nullptr;
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Before is not allowed in this class.
283/// See TList::Before for the intended behavior.
284
286{
287 ::Error("TViewPubDataMembers::Before","Operation not allowed on a view.");
288 return nullptr;
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// First is not allowed in this class.
293/// See TList::First for the intended behavior.
294
296{
297 ::Error("TViewPubDataMembers::First","Operation not allowed on a view.");
298 return nullptr;
299}
300
301////////////////////////////////////////////////////////////////////////////////
302/// FirstLink is not allowed in this class.
303/// See TList::FirstLink for the intended behavior.
304
306{
307 ::Error("TViewPubDataMembers::FirstLink","Operation not allowed on a view.");
308 return nullptr;
309}
310
311////////////////////////////////////////////////////////////////////////////////
312/// GetObjectRef is not allowed in this class.
313/// See TList::GetObjectRef for the intended behavior.
314
316{
317 ::Error("TViewPubDataMembers::GetObjectRef","Operation not yet allowed on a view.");
318 return nullptr;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Return the total number of public data members(currently loaded in the list
323/// of DataMembers) in this class and all its base classes.
324
326{
327 Int_t size = 0;
328 TIter next(&fClasses);
329 while (TClass *cl = (TClass*)next()) {
330 TIter content_next(cl->GetListOfDataMembers(kFALSE));
331 while (TDictionary *p = (TDictionary*) content_next())
332 if (p->Property() & kIsPublic) ++size;
333 }
334 return size;
335
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Load all the DataMembers known to the interpreter for the scope 'fClass'
340/// and all its bases classes.
341
343{
344 TIter next(&fClasses);
345 while (TClass *cl = (TClass*)next()) {
346 cl->GetListOfDataMembers(kTRUE);
347 }
348}
349
350////////////////////////////////////////////////////////////////////////////////
351/// Last is not allowed in this class.
352/// See TList::Last for the intended behavior.
353
355{
356 ::Error("TViewPubDataMembers::Last","Operation not allowed on a view.");
357 return nullptr;
358}
359
360////////////////////////////////////////////////////////////////////////////////
361/// LastLink is not allowed in this class.
362/// See TList::LastLink for the intended behavior.
363
365{
366 ::Error("TViewPubDataMembers::LastLink","Operation not allowed on a view.");
367 return nullptr;
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// RecursiveRemove is not allowed in this class.
372/// See TList::RecursiveRemove for the intended behavior.
373
375{
376 ::Error("TViewPubDataMembers::RecursiveRemove","Operation not allowed on a view.");
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Remove is not allowed in this class.
381/// See TList::Remove for the intended behavior.
382
384{
385 ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
386 return nullptr;
387}
388
389////////////////////////////////////////////////////////////////////////////////
390/// Remove is not allowed in this class.
391/// See TList::Remove for the intended behavior.
392
394{
395 ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
396 return nullptr;
397}
398
399/** \class TViewPubDataMembersIter
400Iterator of over the view's content.
401*/
402
403
404////////////////////////////////////////////////////////////////////////////////
405/// Create a new list iterator. By default the iteration direction
406/// is kIterForward. To go backward use kIterBackward.
407
409: fView(l),fClassIter(l->GetListOfClasses(),dir), fIter((TCollection *)nullptr),
410fStarted(kFALSE), fDirection(dir)
411{
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Copy ctor.
416
418TIterator(iter), fView(iter.fView),
419fClassIter(iter.fClassIter), fIter(iter.fIter),
420fStarted(iter.fStarted), fDirection(iter.fDirection)
421{
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// Overridden assignment operator.
426
428{
429 const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&rhs);
430 if (this != &rhs && iter) {
431 fView = iter->fView;
432 fClassIter = iter->fClassIter;
433 fIter = iter->fIter;
434 fStarted = iter->fStarted;
435 fDirection = iter->fDirection;
436 }
437 return *this;
438}
439
440////////////////////////////////////////////////////////////////////////////////
441/// Overloaded assignment operator.
442
444{
445 if (this != &rhs) {
446 fView = rhs.fView;
447 fClassIter = rhs.fClassIter;
448 fIter = rhs.fIter;
449 fStarted = rhs.fStarted;
450 fDirection = rhs.fDirection;
451 }
452 return *this;
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// Return next object in the list. Returns 0 when no more objects in list.
457
459{
460 if (!fView) return nullptr;
461
462 if (!fStarted) {
463 TClass *current = (TClass*)fClassIter();
464 fStarted = kTRUE;
465 if (current) {
466 fIter.~TIter();
468 } else {
469 return nullptr;
470 }
471 }
472
473 while (1) {
474
475 TDictionary *obj = (TDictionary *)fIter();
476 if (!obj) {
477 // End of list of DataMembers, move to the next;
478 TClass *current = (TClass*)fClassIter();
479 if (current) {
480 fIter.~TIter();
482 continue;
483 } else {
484 return nullptr;
485 }
486 } else if (obj->Property() & kIsPublic) {
487 // If it is public we found the next one.
488 return obj;
489 }
490
491 }
492 // Not reachable.
493 return nullptr;
494}
495
496////////////////////////////////////////////////////////////////////////////////
497/// Reset list iterator.
498
504
505////////////////////////////////////////////////////////////////////////////////
506/// This operator compares two TIterator objects.
507
509{
510 const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&aIter);
511 if (iter) {
512 return (fClassIter != iter->fClassIter || fIter != iter->fIter);
513 }
514 return false; // for base class we don't implement a comparison
515}
516
517////////////////////////////////////////////////////////////////////////////////
518/// This operator compares two TViewPubDataMembersIter objects.
519
521{
522 return (fClassIter != aIter.fClassIter || fIter != aIter.fIter);
523}
524
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
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.
@ kIsPublic
Definition TDictionary.h:75
winID h TVirtualViewer3D TVirtualGLPainter p
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
char name[80]
Definition TGX11.cxx:110
static void AddBasesClasses(TList &bases, TClass *cl)
loop over all base classes and add them to the container.
Each class (see TClass) has a linked list of its base class(es).
Definition TBaseClass.h:33
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
TClass * GetClassPointer(Bool_t load=kTRUE)
Get pointer to the base class TClass.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TList * GetListOfDataMembers(Bool_t load=kTRUE)
Return list containing the TDataMembers of a class.
Definition TClass.cxx:3797
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3663
Collection abstract base class.
Definition TCollection.h:65
std::size_t size() const
This class defines an abstract interface that must be implemented by all classes that contain diction...
virtual Long_t Property() const =0
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
virtual ~TIter()
void Reset()
Iterator abstract base class.
Definition TIterator.h:30
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1088
Iterator of over the view's content.
TObject * Next() override
Return next object in the list. Returns 0 when no more objects in list.
void Reset() override
Reset list iterator.
Bool_t operator!=(const TIterator &aIter) const override
This operator compares two TIterator objects.
TIterator & operator=(const TIterator &rhs) override
Overridden assignment operator.
View implementing the TList interface and giving access all the TDictionary describing public data me...
TObjLink * FirstLink() const override
FirstLink is not allowed in this class.
TObject * Last() const override
Last is not allowed in this class.
void Load()
Load all the DataMembers known to the interpreter for the scope 'fClass' and all its bases classes.
TObject * First() const override
First is not allowed in this class.
Int_t GetSize() const override
Return the total number of public data members(currently loaded in the list of DataMembers) in this c...
void Delete(Option_t *option="") override
Delete is not allowed in this class.
TObject ** GetObjectRef(const TObject *obj) const override
GetObjectRef is not allowed in this class.
void AddBefore(const TObject *before, TObject *obj) override
AddBefore is not allowed in this class.
TViewPubDataMembers(const TViewPubDataMembers &)=delete
void AddFirst(TObject *obj) override
AddFirst is not allowed in this class.
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
void AddLast(TObject *obj) override
AddLast is not allowed in this class.
void AddAfter(const TObject *after, TObject *obj) override
AddAfter is not allowed in this class.
TObject * Remove(TObject *obj) override
Remove is not allowed in this class.
TObject * Before(const TObject *obj) const override
Before is not allowed in this class.
void Clear(Option_t *option="") override
Clear is not allowed in this class.
void RecursiveRemove(TObject *obj) override
RecursiveRemove is not allowed in this class.
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
void AddAt(TObject *obj, Int_t idx) override
AddAt is not allowed in this class.
TObjLink * LastLink() const override
LastLink is not allowed in this class.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
TObject * After(const TObject *obj) const override
After is not allowed in this class.
virtual ~TViewPubDataMembers()
Default destructor.
TLine l
Definition textangle.C:4