Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TViewPubFunctions.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 TViewPubFunctions
13View implementing the TList interface and giving access all the
14TFunction describing public methods in a class and all its base
15classes without caching any of the TFunction pointers.
16
17Adding to this collection directly is prohibited.
18Iteration can only be done via the TIterator interfaces.
19*/
20
21#include "TViewPubFunctions.h"
22
23#include "TClass.h"
24#include "TBaseClass.h"
25#include "TError.h"
26#include "TFunction.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 TViewPubFunctions::Clear(Option_t * /* option="" */)
69{
70 ::Error("TViewPubFunctions::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
77void TViewPubFunctions::Delete(Option_t * /*option="" */)
78{
79 ::Error("TViewPubFunctions::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 if (name==nullptr || name[0]==0) return nullptr;
90
91 TIter next(&fClasses);
92 while (TClass *cl = (TClass*)next()) {
93 THashList *hl = dynamic_cast<THashList*>(cl->GetListOfMethods(kFALSE));
94 TIter funcnext(hl->GetListForObject(name));
95 while (TFunction *p = (TFunction*) funcnext())
96 if (p->Property() & kIsPublic
97 && strncmp(p->GetName(),name,strlen(p->GetName())) == 0)
98 return p;
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->GetListOfMethods(kFALSE)->FindObject(obj);
113 if (result) return result;
114 }
115 return nullptr;
116}
117
118////////////////////////////////////////////////////////////////////////////////
119/// Return a list iterator.
120
121TIterator *TViewPubFunctions::MakeIterator(Bool_t dir /* = kIterForward*/) const
122{
123 return new TViewPubFunctionsIter(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("TViewPubFunctions::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 TViewPubFunctions::AddFirst(TObject * /* obj */, Option_t * /* opt */)
140{
141 ::Error("TViewPubFunctions::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("TViewPubFunctions::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 TViewPubFunctions::AddLast(TObject * /* obj */, Option_t * /* opt */)
158{
159 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAt(TObject * /* obj */, Int_t /* idx */)
167{
168 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAt(TObject * /* obj */, Int_t /* idx */, Option_t * /* opt */)
176{
177 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAfter(const TObject * /* after */, TObject * /* obj */)
185{
186 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAfter(TObjLink * /* after */, TObject * /* obj */)
194{
195 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAfter(const TObject * /* after */, TObject * /* obj */, Option_t * /* opt */)
203{
204 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddAfter(TObjLink * /* after */, TObject * /* obj */, Option_t * /* opt */)
212{
213 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddBefore(const TObject * /* before */, TObject * /* obj */)
221{
222 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddBefore(TObjLink * /* before */, TObject * /* obj */)
230{
231 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddBefore(const TObject * /* before */, TObject * /* obj */, Option_t * /* opt */)
239{
240 ::Error("TViewPubFunctions::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 TViewPubFunctions::AddBefore(TObjLink * /* before */, TObject * /* obj */, Option_t * /* opt */)
248{
249 ::Error("TViewPubFunctions::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 funcnext(cl->GetListOfMethods(kFALSE));
261 while (TFunction *p = (TFunction*) funcnext()) {
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
275TObject *TViewPubFunctions::After(const TObject * /* obj */) const
276{
277 ::Error("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::GetObjectRef","Operation not yet allowed on a view.");
318 return nullptr;
319}
320
321////////////////////////////////////////////////////////////////////////////////
322/// Return the total number of public methods (currently loaded in the list
323/// of functions) 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 funcnext(cl->GetListOfMethods(kFALSE));
331 while (TFunction *p = (TFunction*) funcnext())
332 if (p->Property() & kIsPublic) ++size;
333 }
334 return size;
335
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Load all the functions 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->GetListOfMethods(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("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::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("TViewPubFunctions::Remove","Operation not allowed on a view.");
396 return nullptr;
397}
398
399/** \class TViewPubFunctionsIter
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), fFuncIter((TCollection *)nullptr),
410 fStarted(kFALSE), fDirection(dir)
411{
412}
413
414////////////////////////////////////////////////////////////////////////////////
415/// Copy ctor.
416
418 TIterator(iter), fView(iter.fView),
419 fClassIter(iter.fClassIter), fFuncIter(iter.fFuncIter),
420 fStarted(iter.fStarted), fDirection(iter.fDirection)
421{
422}
423
424////////////////////////////////////////////////////////////////////////////////
425/// Overridden assignment operator.
426
428{
429 const TViewPubFunctionsIter *iter = dynamic_cast<const TViewPubFunctionsIter*>(&rhs);
430 if (this != &rhs && iter) {
431 fView = iter->fView;
432 fClassIter = iter->fClassIter;
433 fFuncIter = iter->fFuncIter;
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 fFuncIter = rhs.fFuncIter;
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) {
468 } else {
469 return nullptr;
470 }
471 }
472
473 while (1) {
474
475 TFunction *func = (TFunction *)fFuncIter();
476 if (!func) {
477 // End of list of functions, move to the next;
478 TClass *current = (TClass*)fClassIter();
479 if (current) {
482 continue;
483 } else {
484 return nullptr;
485 }
486 } else if (func->Property() & kIsPublic) {
487 // If it is public we found the next one.
488 return func;
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 TViewPubFunctionsIter *iter = dynamic_cast<const TViewPubFunctionsIter*>(&aIter);
511 if (iter) {
512 return (fClassIter != iter->fClassIter || fFuncIter != iter->fFuncIter);
513 }
514 return false; // for base class we don't implement a comparison
515}
516
517////////////////////////////////////////////////////////////////////////////////
518/// This operator compares two TViewPubFunctionsIter objects.
519
521{
522 return (fClassIter != aIter.fClassIter || fFuncIter != aIter.fFuncIter);
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.
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 * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3839
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
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
Long_t Property() const override
Get property description word. For meaning of bits see EProperty.
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.
TIterator & operator=(const TIterator &rhs) override
Overridden assignment operator.
void Reset() override
Reset list iterator.
Bool_t operator!=(const TIterator &aIter) const override
This operator compares two TIterator objects.
View implementing the TList interface and giving access all the TFunction describing public methods i...
void AddLast(TObject *obj) override
AddLast is not allowed in this class.
TObject * Remove(TObject *obj) override
Remove is not allowed in this class.
void Load()
Load all the functions known to the interpreter for the scope 'fClass' and all its bases classes.
TObject * Before(const TObject *obj) const override
Before is not allowed in this class.
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
TObjLink * LastLink() const override
LastLink is not allowed in this class.
TObject * First() const override
First 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.
TObject ** GetObjectRef(const TObject *obj) const override
GetObjectRef is not allowed in this class.
virtual ~TViewPubFunctions()
Default destructor.
TObjLink * FirstLink() const override
FirstLink is not allowed in this class.
Int_t GetSize() const override
Return the total number of public methods (currently loaded in the list of functions) in this class a...
TObject * After(const TObject *obj) const override
After is not allowed in this class.
void Delete(Option_t *option="") override
Delete is not allowed in this class.
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void AddFirst(TObject *obj) override
AddFirst is not allowed in this class.
void AddAt(TObject *obj, Int_t idx) override
AddAt is not allowed in this class.
void AddAfter(const TObject *after, TObject *obj) override
AddAfter is not allowed in this class.
TObject * Last() const override
Last 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.
TViewPubFunctions(const TViewPubFunctions &)=delete
void AddBefore(const TObject *before, TObject *obj) override
AddBefore is not allowed in this class.
TLine l
Definition textangle.C:4