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// ClassImp(TViewPubFunctions);
30
31////////////////////////////////////////////////////////////////////////////////
32/// loop over all base classes and add them to the container.
33
34static 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
69void TViewPubFunctions::Clear(Option_t * /* option="" */)
70{
71 ::Error("TViewPubFunctions::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
78void TViewPubFunctions::Delete(Option_t * /*option="" */)
79{
80 ::Error("TViewPubFunctions::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{
90 if (name==nullptr || name[0]==0) return nullptr;
91
92 TIter next(&fClasses);
93 while (TClass *cl = (TClass*)next()) {
94 THashList *hl = dynamic_cast<THashList*>(cl->GetListOfMethods(kFALSE));
95 TIter funcnext(hl->GetListForObject(name));
96 while (TFunction *p = (TFunction*) funcnext())
97 if (p->Property() & kIsPublic
98 && strncmp(p->GetName(),name,strlen(p->GetName())) == 0)
99 return p;
100 }
101 return nullptr;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Find an object in this list using the object's IsEqual()
106/// member function. Requires a sequential scan till the object has
107/// been found. Returns 0 if object is not found.
108
110{
111 TIter next(&fClasses);
112 while (TClass *cl = (TClass*)next()) {
113 TObject *result = cl->GetListOfMethods(kFALSE)->FindObject(obj);
114 if (result) return result;
115 }
116 return nullptr;
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Return a list iterator.
121
122TIterator *TViewPubFunctions::MakeIterator(Bool_t dir /* = kIterForward*/) const
123{
124 return new TViewPubFunctionsIter(this, dir);
125}
126
127////////////////////////////////////////////////////////////////////////////////
128/// AddFirst is not allowed in this class.
129/// See TList::AddFirst for the intended behavior.
130
132{
133 ::Error("TViewPubFunctions::AddFirst","Operation not allowed on a view.");
134}
135
136////////////////////////////////////////////////////////////////////////////////
137/// AddFirst is not allowed in this class.
138/// See TList::AddFirst for the intended behavior.
139
140void TViewPubFunctions::AddFirst(TObject * /* obj */, Option_t * /* opt */)
141{
142 ::Error("TViewPubFunctions::AddFirst","Operation not allowed on a view.");
143}
144
145////////////////////////////////////////////////////////////////////////////////
146/// AddLast is not allowed in this class.
147/// See TList::AddLast for the intended behavior.
148
150{
151 ::Error("TViewPubFunctions::AddLast","Operation not allowed on a view.");
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// AddLast is not allowed in this class.
156/// See TList::AddLast for the intended behavior.
157
158void TViewPubFunctions::AddLast(TObject * /* obj */, Option_t * /* opt */)
159{
160 ::Error("TViewPubFunctions::AddLast","Operation not allowed on a view.");
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// AddAt is not allowed in this class.
165/// See TList::AddAt for the intended behavior.
166
167void TViewPubFunctions::AddAt(TObject * /* obj */, Int_t /* idx */)
168{
169 ::Error("TViewPubFunctions::AddAt","Operation not allowed on a view.");
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// AddAfter is not allowed in this class.
174/// See TList::AddAfter for the intended behavior.
175
176void TViewPubFunctions::AddAfter(const TObject * /* after */, TObject * /* obj */)
177{
178 ::Error("TViewPubFunctions::RemAddLastove","Operation not allowed on a view.");
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// AddAfter is not allowed in this class.
183/// See TList::AddAfter for the intended behavior.
184
185void TViewPubFunctions::AddAfter(TObjLink * /* after */, TObject * /* obj */)
186{
187 ::Error("TViewPubFunctions::AddAfter","Operation not allowed on a view.");
188}
189
190////////////////////////////////////////////////////////////////////////////////
191/// AddBefore is not allowed in this class.
192/// See TList::AddBefore for the intended behavior.
193
194void TViewPubFunctions::AddBefore(const TObject * /* before */, TObject * /* obj */)
195{
196 ::Error("TViewPubFunctions::AddBefore","Operation not allowed on a view.");
197}
198
199////////////////////////////////////////////////////////////////////////////////
200/// AddBefore is not allowed in this class.
201/// See TList::AddBefore for the intended behavior.
202
203void TViewPubFunctions::AddBefore(TObjLink * /* before */, TObject * /* obj */)
204{
205 ::Error("TViewPubFunctions::AddBefore","Operation not allowed on a view.");
206}
207
208////////////////////////////////////////////////////////////////////////////////
209/// Returns the object at position idx. Returns 0 if idx is out of range.
210
212{
213 Int_t i = 0;
214 TIter next(&fClasses);
215 while (TClass *cl = (TClass*)next()) {
216 TIter funcnext(cl->GetListOfMethods(kFALSE));
217 while (TFunction *p = (TFunction*) funcnext()) {
218 if (p->Property() & kIsPublic) {
219 if (i == idx) return p;
220 ++i;
221 }
222 }
223 }
224 return nullptr;
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// After is not allowed in this class.
229/// See TList::After for the intended behavior.
230
231TObject *TViewPubFunctions::After(const TObject * /* obj */) const
232{
233 ::Error("TViewPubFunctions::After","Operation not allowed on a view.");
234 return nullptr;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Before is not allowed in this class.
239/// See TList::Before for the intended behavior.
240
242{
243 ::Error("TViewPubFunctions::Before","Operation not allowed on a view.");
244 return nullptr;
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// First is not allowed in this class.
249/// See TList::First for the intended behavior.
250
252{
253 ::Error("TViewPubFunctions::First","Operation not allowed on a view.");
254 return nullptr;
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// FirstLink is not allowed in this class.
259/// See TList::FirstLink for the intended behavior.
260
262{
263 ::Error("TViewPubFunctions::FirstLink","Operation not allowed on a view.");
264 return nullptr;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// GetObjectRef is not allowed in this class.
269/// See TList::GetObjectRef for the intended behavior.
270
272{
273 ::Error("TViewPubFunctions::GetObjectRef","Operation not yet allowed on a view.");
274 return nullptr;
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Return the total number of public methods (currently loaded in the list
279/// of functions) in this class and all its base classes.
280
282{
283 Int_t size = 0;
284 TIter next(&fClasses);
285 while (TClass *cl = (TClass*)next()) {
286 TIter funcnext(cl->GetListOfMethods(kFALSE));
287 while (TFunction *p = (TFunction*) funcnext())
288 if (p->Property() & kIsPublic) ++size;
289 }
290 return size;
291
292}
293
294////////////////////////////////////////////////////////////////////////////////
295/// Load all the functions known to the interpreter for the scope 'fClass'
296/// and all its bases classes.
297
299{
300 TIter next(&fClasses);
301 while (TClass *cl = (TClass*)next()) {
302 cl->GetListOfMethods(kTRUE);
303 }
304}
305
306////////////////////////////////////////////////////////////////////////////////
307/// Last is not allowed in this class.
308/// See TList::Last for the intended behavior.
309
311{
312 ::Error("TViewPubFunctions::Last","Operation not allowed on a view.");
313 return nullptr;
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// LastLink is not allowed in this class.
318/// See TList::LastLink for the intended behavior.
319
321{
322 ::Error("TViewPubFunctions::LastLink","Operation not allowed on a view.");
323 return nullptr;
324}
325
326////////////////////////////////////////////////////////////////////////////////
327/// RecursiveRemove is not allowed in this class.
328/// See TList::RecursiveRemove for the intended behavior.
329
331{
332 ::Error("TViewPubFunctions::RecursiveRemove","Operation not allowed on a view.");
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Remove is not allowed in this class.
337/// See TList::Remove for the intended behavior.
338
340{
341 ::Error("TViewPubFunctions::Remove","Operation not allowed on a view.");
342 return nullptr;
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Remove is not allowed in this class.
347/// See TList::Remove for the intended behavior.
348
350{
351 ::Error("TViewPubFunctions::Remove","Operation not allowed on a view.");
352 return nullptr;
353}
354
355/** \class TViewPubFunctionsIter
356Iterator of over the view's content
357*/
358
359// ClassImp(TViewPubFunctionsIter);
360
361////////////////////////////////////////////////////////////////////////////////
362/// Create a new list iterator. By default the iteration direction
363/// is kIterForward. To go backward use kIterBackward.
364
366: fView(l),fClassIter(l->GetListOfClasses(),dir), fFuncIter((TCollection *)nullptr),
367 fStarted(kFALSE), fDirection(dir)
368{
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Copy ctor.
373
375 TIterator(iter), fView(iter.fView),
376 fClassIter(iter.fClassIter), fFuncIter(iter.fFuncIter),
377 fStarted(iter.fStarted), fDirection(iter.fDirection)
378{
379}
380
381////////////////////////////////////////////////////////////////////////////////
382/// Overridden assignment operator.
383
385{
386 const TViewPubFunctionsIter *iter = dynamic_cast<const TViewPubFunctionsIter*>(&rhs);
387 if (this != &rhs && iter) {
388 fView = iter->fView;
389 fClassIter = iter->fClassIter;
390 fFuncIter = iter->fFuncIter;
391 fStarted = iter->fStarted;
392 fDirection = iter->fDirection;
393 }
394 return *this;
395}
396
397////////////////////////////////////////////////////////////////////////////////
398/// Overloaded assignment operator.
399
401{
402 if (this != &rhs) {
403 fView = rhs.fView;
405 fFuncIter = rhs.fFuncIter;
406 fStarted = rhs.fStarted;
408 }
409 return *this;
410}
411
412////////////////////////////////////////////////////////////////////////////////
413/// Return next object in the list. Returns 0 when no more objects in list.
414
416{
417 if (!fView) return nullptr;
418
419 if (!fStarted) {
420 TClass *current = (TClass*)fClassIter();
421 fStarted = kTRUE;
422 if (current) {
425 } else {
426 return nullptr;
427 }
428 }
429
430 while (1) {
431
432 TFunction *func = (TFunction *)fFuncIter();
433 if (!func) {
434 // End of list of functions, move to the next;
435 TClass *current = (TClass*)fClassIter();
436 if (current) {
439 continue;
440 } else {
441 return nullptr;
442 }
443 } else if (func->Property() & kIsPublic) {
444 // If it is public we found the next one.
445 return func;
446 }
447
448 }
449 // Not reachable.
450 return nullptr;
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Reset list iterator.
455
457{
460}
461
462////////////////////////////////////////////////////////////////////////////////
463/// This operator compares two TIterator objects.
464
466{
467 const TViewPubFunctionsIter *iter = dynamic_cast<const TViewPubFunctionsIter*>(&aIter);
468 if (iter) {
469 return (fClassIter != iter->fClassIter || fFuncIter != iter->fFuncIter);
470 }
471 return false; // for base class we don't implement a comparison
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// This operator compares two TViewPubFunctionsIter objects.
476
478{
479 return (fClassIter != aIter.fClassIter || fFuncIter != aIter.fFuncIter);
480}
481
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
@ 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:81
TList * GetListOfMethods(Bool_t load=kTRUE)
Return list containing the TMethods of a class.
Definition TClass.cxx:3812
TList * GetListOfBases()
Return list containing the TBaseClass(es) of a class.
Definition TClass.cxx:3636
Collection abstract base class.
Definition TCollection.h:65
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
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...
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 const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
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