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/// AddAfter is not allowed in this class.
173/// See TList::AddAfter for the intended behavior.
174
175void TViewPubDataMembers::AddAfter(const TObject * /* after */, TObject * /* obj */)
176{
177 ::Error("TViewPubDataMembers::RemAddLastove","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(TObjLink * /* after */, TObject * /* obj */)
185{
186 ::Error("TViewPubDataMembers::AddAfter","Operation not allowed on a view.");
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// AddBefore is not allowed in this class.
191/// See TList::AddBefore for the intended behavior.
192
193void TViewPubDataMembers::AddBefore(const TObject * /* before */, TObject * /* obj */)
194{
195 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// AddBefore is not allowed in this class.
200/// See TList::AddBefore for the intended behavior.
201
202void TViewPubDataMembers::AddBefore(TObjLink * /* before */, TObject * /* obj */)
203{
204 ::Error("TViewPubDataMembers::AddBefore","Operation not allowed on a view.");
205}
206
207////////////////////////////////////////////////////////////////////////////////
208/// Returns the object at position idx. Returns 0 if idx is out of range.
209
211{
212 Int_t i = 0;
213 TIter next(&fClasses);
214 while (TClass *cl = (TClass*)next()) {
215 TIter content_next(cl->GetListOfDataMembers(kFALSE));
216 while (TDictionary *p = (TDictionary*) content_next()) {
217 if (p->Property() & kIsPublic) {
218 if (i == idx) return p;
219 ++i;
220 }
221 }
222 }
223 return nullptr;
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// After is not allowed in this class.
228/// See TList::After for the intended behavior.
229
231{
232 ::Error("TViewPubDataMembers::After","Operation not allowed on a view.");
233 return nullptr;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Before is not allowed in this class.
238/// See TList::Before for the intended behavior.
239
241{
242 ::Error("TViewPubDataMembers::Before","Operation not allowed on a view.");
243 return nullptr;
244}
245
246////////////////////////////////////////////////////////////////////////////////
247/// First is not allowed in this class.
248/// See TList::First for the intended behavior.
249
251{
252 ::Error("TViewPubDataMembers::First","Operation not allowed on a view.");
253 return nullptr;
254}
255
256////////////////////////////////////////////////////////////////////////////////
257/// FirstLink is not allowed in this class.
258/// See TList::FirstLink for the intended behavior.
259
261{
262 ::Error("TViewPubDataMembers::FirstLink","Operation not allowed on a view.");
263 return nullptr;
264}
265
266////////////////////////////////////////////////////////////////////////////////
267/// GetObjectRef is not allowed in this class.
268/// See TList::GetObjectRef for the intended behavior.
269
271{
272 ::Error("TViewPubDataMembers::GetObjectRef","Operation not yet allowed on a view.");
273 return nullptr;
274}
275
276////////////////////////////////////////////////////////////////////////////////
277/// Return the total number of public data members(currently loaded in the list
278/// of DataMembers) in this class and all its base classes.
279
281{
282 Int_t size = 0;
283 TIter next(&fClasses);
284 while (TClass *cl = (TClass*)next()) {
285 TIter content_next(cl->GetListOfDataMembers(kFALSE));
286 while (TDictionary *p = (TDictionary*) content_next())
287 if (p->Property() & kIsPublic) ++size;
288 }
289 return size;
290
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Load all the DataMembers known to the interpreter for the scope 'fClass'
295/// and all its bases classes.
296
298{
299 TIter next(&fClasses);
300 while (TClass *cl = (TClass*)next()) {
301 cl->GetListOfDataMembers(kTRUE);
302 }
303}
304
305////////////////////////////////////////////////////////////////////////////////
306/// Last is not allowed in this class.
307/// See TList::Last for the intended behavior.
308
310{
311 ::Error("TViewPubDataMembers::Last","Operation not allowed on a view.");
312 return nullptr;
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// LastLink is not allowed in this class.
317/// See TList::LastLink for the intended behavior.
318
320{
321 ::Error("TViewPubDataMembers::LastLink","Operation not allowed on a view.");
322 return nullptr;
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// RecursiveRemove is not allowed in this class.
327/// See TList::RecursiveRemove for the intended behavior.
328
330{
331 ::Error("TViewPubDataMembers::RecursiveRemove","Operation not allowed on a view.");
332}
333
334////////////////////////////////////////////////////////////////////////////////
335/// Remove is not allowed in this class.
336/// See TList::Remove for the intended behavior.
337
339{
340 ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
341 return nullptr;
342}
343
344////////////////////////////////////////////////////////////////////////////////
345/// Remove is not allowed in this class.
346/// See TList::Remove for the intended behavior.
347
349{
350 ::Error("TViewPubDataMembers::Remove","Operation not allowed on a view.");
351 return nullptr;
352}
353
354/** \class TViewPubDataMembersIter
355Iterator of over the view's content.
356*/
357
358
359////////////////////////////////////////////////////////////////////////////////
360/// Create a new list iterator. By default the iteration direction
361/// is kIterForward. To go backward use kIterBackward.
362
364: fView(l),fClassIter(l->GetListOfClasses(),dir), fIter((TCollection *)nullptr),
365fStarted(kFALSE), fDirection(dir)
366{
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Copy ctor.
371
373TIterator(iter), fView(iter.fView),
374fClassIter(iter.fClassIter), fIter(iter.fIter),
375fStarted(iter.fStarted), fDirection(iter.fDirection)
376{
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Overridden assignment operator.
381
383{
384 const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&rhs);
385 if (this != &rhs && iter) {
386 fView = iter->fView;
387 fClassIter = iter->fClassIter;
388 fIter = iter->fIter;
389 fStarted = iter->fStarted;
390 fDirection = iter->fDirection;
391 }
392 return *this;
393}
394
395////////////////////////////////////////////////////////////////////////////////
396/// Overloaded assignment operator.
397
399{
400 if (this != &rhs) {
401 fView = rhs.fView;
402 fClassIter = rhs.fClassIter;
403 fIter = rhs.fIter;
404 fStarted = rhs.fStarted;
405 fDirection = rhs.fDirection;
406 }
407 return *this;
408}
409
410////////////////////////////////////////////////////////////////////////////////
411/// Return next object in the list. Returns 0 when no more objects in list.
412
414{
415 if (!fView) return nullptr;
416
417 if (!fStarted) {
418 TClass *current = (TClass*)fClassIter();
419 fStarted = kTRUE;
420 if (current) {
421 fIter.~TIter();
423 } else {
424 return nullptr;
425 }
426 }
427
428 while (1) {
429
430 TDictionary *obj = (TDictionary *)fIter();
431 if (!obj) {
432 // End of list of DataMembers, move to the next;
433 TClass *current = (TClass*)fClassIter();
434 if (current) {
435 fIter.~TIter();
437 continue;
438 } else {
439 return nullptr;
440 }
441 } else if (obj->Property() & kIsPublic) {
442 // If it is public we found the next one.
443 return obj;
444 }
445
446 }
447 // Not reachable.
448 return nullptr;
449}
450
451////////////////////////////////////////////////////////////////////////////////
452/// Reset list iterator.
453
459
460////////////////////////////////////////////////////////////////////////////////
461/// This operator compares two TIterator objects.
462
464{
465 const TViewPubDataMembersIter *iter = dynamic_cast<const TViewPubDataMembersIter*>(&aIter);
466 if (iter) {
467 return (fClassIter != iter->fClassIter || fIter != iter->fIter);
468 }
469 return false; // for base class we don't implement a comparison
470}
471
472////////////////////////////////////////////////////////////////////////////////
473/// This operator compares two TViewPubDataMembersIter objects.
474
476{
477 return (fClassIter != aIter.fClassIter || fIter != aIter.fIter);
478}
479
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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
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:1071
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