Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TListOfFunctions.cxx
Go to the documentation of this file.
1// @(#)root/cont
2// Author: Philippe Canal Aug 2013
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, 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 TListOfFunctions
13A collection of TFunction objects designed for fast access given a
14DeclId_t and for keep track of TFunction that were described
15unloaded function.
16*/
17
18#include "TListOfFunctions.h"
19#include "TClass.h"
20#include "TExMap.h"
21#include "TFunction.h"
22#include "TMethod.h"
23#include "TInterpreter.h"
24#include "TVirtualMutex.h"
25#include "TROOT.h"
26
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
31TListOfFunctions::TListOfFunctions(TClass *cl) : fClass(cl),fIds(nullptr),fUnloaded(nullptr),fLastLoadMarker(0)
32{
33 fIds = new TExMap;
34 fUnloaded = new THashList;
35}
36
37////////////////////////////////////////////////////////////////////////////////
38/// Destructor.
39
47
48////////////////////////////////////////////////////////////////////////////////
49/// Add pair<id, object> to the map of functions and their ids.
50
52{
53 TFunction *f = dynamic_cast<TFunction*>(obj);
54 if (f) {
55 fIds->Add((Long64_t)f->GetDeclId(),(Long64_t)f);
56 }
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Add object at the beginning of the list.
61
67
68////////////////////////////////////////////////////////////////////////////////
69/// Add object at the beginning of the list and also store option.
70/// Storing an option is useful when one wants to change the behaviour
71/// of an object a little without having to create a complete new
72/// copy of the object. This feature is used, for example, by the Draw()
73/// method. It allows the same object to be drawn in different ways.
74
76{
77 THashList::AddFirst(obj,opt);
78 MapObject(obj);
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// Add object at the end of the list.
83
89
90////////////////////////////////////////////////////////////////////////////////
91/// Add object at the end of the list and also store option.
92/// Storing an option is useful when one wants to change the behaviour
93/// of an object a little without having to create a complete new
94/// copy of the object. This feature is used, for example, by the Draw()
95/// method. It allows the same object to be drawn in different ways.
96
98{
99 THashList::AddLast(obj, opt);
100 MapObject(obj);
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Insert object at location idx in the list.
105
107{
108 THashList::AddAt(obj, idx);
109 MapObject(obj);
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Insert object at location idx in the list, with options.
114
116{
117 THashList::AddAt(obj, idx, opt);
118 MapObject(obj);
119}
120
121////////////////////////////////////////////////////////////////////////////////
122/// Insert object after object after in the list.
123
125{
127 MapObject(obj);
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Insert object after object after in the list.
132
138
139////////////////////////////////////////////////////////////////////////////////
140/// Insert object after object after in the list, with options.
141
143{
144 THashList::AddAfter(after, obj, opt);
145 MapObject(obj);
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Insert object after object after in the list, with options.
150
152{
153 THashList::AddAfter(after, obj, opt);
154 MapObject(obj);
155}
156
157////////////////////////////////////////////////////////////////////////////////
158/// Insert object before object before in the list.
159
165
166////////////////////////////////////////////////////////////////////////////////
167/// Insert object before object before in the list.
168
174
175////////////////////////////////////////////////////////////////////////////////
176/// Insert object before object before in the list, with options.
177
179{
180 THashList::AddBefore(before, obj, opt);
181 MapObject(obj);
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Insert object before object before in the list, with options.
186
192
193////////////////////////////////////////////////////////////////////////////////
194/// Remove all objects from the list. Does not delete the objects unless
195/// the THashList is the owner (set via SetOwner()).
196
203
204////////////////////////////////////////////////////////////////////////////////
205/// Delete all TFunction object files.
206
213
214////////////////////////////////////////////////////////////////////////////////
215/// Specialize FindObject to do search for the
216/// a function just by name or create it if its not already in the list
217
219{
222 if (!result) {
223
225 if (fClass) decl = gInterpreter->GetFunction(fClass->GetClassInfo(),name);
226 else decl = gInterpreter->GetFunction(nullptr,name);
227 if (decl) result = const_cast<TListOfFunctions*>(this)->Get(decl);
228 }
229 return result;
230}
231
232////////////////////////////////////////////////////////////////////////////////
233/// Return the set of overloads for this name, collecting all available ones.
234/// Can construct and insert new TFunction-s.
235
237{
239
242 Bool_t wasEmpty = true;
243 if (!overloads) {
244 overloads = new TList();
245 overloads->SetName(name);
247 } else {
249 while (TFunction* over = (TFunction*)iOverload()) {
250 wasEmpty = false;
251 overloadsSet.Add((Long64_t)(ULong64_t)over->GetDeclId(),
253 }
254 }
255
256 // Update if needed.
257 std::vector<DeclId_t> overloadDecls;
258 ClassInfo_t* ci = fClass ? fClass->GetClassInfo() : nullptr;
259 gInterpreter->GetFunctionOverloads(ci, name, overloadDecls);
260 for (std::vector<DeclId_t>::const_iterator iD = overloadDecls.begin(),
261 eD = overloadDecls.end(); iD != eD; ++iD) {
262 TFunction* over = Get(*iD);
263 if (wasEmpty || !overloadsSet.GetValue((Long64_t)(ULong64_t)over->GetDeclId())) {
264 overloads->Add(over);
265 }
266 }
267
268 return overloads;
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Return the set of overloads for this name, collecting all available ones.
273/// Can construct and insert new TFunction-s.
274
276{
277 return const_cast<TListOfFunctions*>(this)->GetListForObjectNonConst(name);
278}
279
280////////////////////////////////////////////////////////////////////////////////
281/// Return the set of overloads for function obj, collecting all available ones.
282/// Can construct and insert new TFunction-s.
283
285{
286 if (!obj) return nullptr;
287 return const_cast<TListOfFunctions*>(this)
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Return the TMethod or TFunction describing the function corresponding
293/// to the Decl 'id'. Return NULL if not found.
294
296{
297 if (!id) return nullptr;
298
300 return (TFunction*)fIds->GetValue((Long64_t)id);
301}
302
303////////////////////////////////////////////////////////////////////////////////
304/// Return (after creating it if necessary) the TMethod or TFunction
305/// describing the function corresponding to the Decl 'id'.
306
308{
309 if (!id) return nullptr;
310
312 //need the Find and possible Add to be one atomic operation
313 TFunction *f = Find(id);
314 if (f) return f;
315
316 if (gROOT->TestBit(kInvalidObject)) {
317 // Abort early during tear down.
318 return nullptr;
319 }
320
321 if (fClass) {
322 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(),id)) return nullptr;
323 } else {
324 if (!gInterpreter->ClassInfo_Contains(nullptr,id)) return nullptr;
325 }
326
327 MethodInfo_t *m = gInterpreter->MethodInfo_Factory(id);
328
329 // Let's see if this is a reload ...
330 const char *name = gInterpreter->MethodInfo_Name(m);
332 TString mangledName( gInterpreter->MethodInfo_GetMangledName(m) );
334 TFunction *uf;
335 while ((uf = (TFunction *) next())) {
336 if (uf->GetMangledName() == mangledName) {
337 // Reuse
339
340 uf->Update(m);
341 f = uf;
342 break;
343 }
344 }
345 }
346 if (!f) {
347 if (fClass) f = new TMethod(m, fClass);
348 else f = new TFunction(m);
349 }
350 // Calling 'just' THahList::Add would turn around and call
351 // TListOfFunctions::AddLast which should *also* do the fIds->Add.
353 fIds->Add((Long64_t)id,(Long64_t)f);
354
355 return f;
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Remove a pair<id, object> from the map of functions and their ids.
360
362{
363 TFunction *f = dynamic_cast<TFunction*>(obj);
364 if (f) {
365 fIds->Remove((Long64_t)f->GetDeclId());
366 }
367}
368
369////////////////////////////////////////////////////////////////////////////////
370/// Remove object from this collection and recursively remove the object
371/// from all other objects (and collections).
372/// This function overrides TCollection::RecursiveRemove that calls
373/// the Remove function. THashList::Remove cannot be called because
374/// it uses the hash value of the hash table. This hash value
375/// is not available anymore when RecursiveRemove is called from
376/// the TObject destructor.
377
379{
380 if (!obj) return;
381
384 UnmapObject(obj);
385
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Remove object from the list.
390
392{
393 Bool_t found;
394
395 found = THashList::Remove(obj);
396 if (!found) {
397 found = fUnloaded->Remove(obj);
398 }
399 UnmapObject(obj);
400 if (found) return obj;
401 else return nullptr;
402}
403
404////////////////////////////////////////////////////////////////////////////////
405/// Remove object via its objlink from the list.
406
408{
409 if (!lnk) return nullptr;
410
411 TObject *obj = lnk->GetObject();
412
414 fUnloaded->Remove(obj);
415
416 UnmapObject(obj);
417 return obj;
418}
419
420////////////////////////////////////////////////////////////////////////////////
421/// Load all the functions known to the interpreter for the scope 'fClass'
422/// into this collection.
423
425{
426 if (fClass && fClass->GetClassInfo() == nullptr) return;
427
429
430 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
432 return;
433 }
435
437 if (fClass) info = fClass->GetClassInfo();
438 else info = gInterpreter->ClassInfo_Factory();
439
440 MethodInfo_t *t = gInterpreter->MethodInfo_Factory(info);
441 while (gInterpreter->MethodInfo_Next(t)) {
442 if (gInterpreter->MethodInfo_IsValid(t)) {
443 TDictionary::DeclId_t mid = gInterpreter->GetDeclId(t);
444 // Get will check if there is already there or create a new one
445 // (or re-use a previously unloaded version).
446 Get(mid);
447 }
448 }
449 gInterpreter->MethodInfo_Delete(t);
450 if (!fClass) gInterpreter->ClassInfo_Delete(info);
451}
452
453////////////////////////////////////////////////////////////////////////////////
454/// Mark 'all func' as being unloaded.
455/// After the unload, the function can no longer be found directly,
456/// until the decl can be found again in the interpreter (in which
457/// the func object will be reused.
458
460{
462 while (lnk) {
463 TFunction *func = (TFunction*)lnk->GetObject();
464
465 fIds->Remove((Long64_t)func->GetDeclId());
466 fUnloaded->Add(func);
467
468 lnk = lnk->Next();
469 }
470
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Mark 'func' as being unloaded.
476/// After the unload, the function can no longer be found directly,
477/// until the decl can be found again in the interpreter (in which
478/// the func object will be reused.
479
481{
482 if (THashList::Remove(func)) {
483 // We contains the object, let remove it from the other internal
484 // list and move it to the list of unloaded objects.
485
486 fIds->Remove((Long64_t)func->GetDeclId());
487 fUnloaded->Add(func);
488 }
489}
490
491////////////////////////////////////////////////////////////////////////////////
492
498
499////////////////////////////////////////////////////////////////////////////////
500
506
507////////////////////////////////////////////////////////////////////////////////
508
514
515////////////////////////////////////////////////////////////////////////////////
516
518{
520 return THashList::After(obj);
521}
522
523////////////////////////////////////////////////////////////////////////////////
524
530
531////////////////////////////////////////////////////////////////////////////////
532
538
539////////////////////////////////////////////////////////////////////////////////
540
546
547////////////////////////////////////////////////////////////////////////////////
548
554
555////////////////////////////////////////////////////////////////////////////////
556
562
563////////////////////////////////////////////////////////////////////////////////
564
570
571
572////////////////////////////////////////////////////////////////////////////////
573
579
580////////////////////////////////////////////////////////////////////////////////
581
587
588
589////////////////////////////////////////////////////////////////////////////////
590
596
597/** \class TListOfFunctionsIter
598Iterator for TListOfFunctions.
599*/
600
601
602////////////////////////////////////////////////////////////////////////////////
603
606
607////////////////////////////////////////////////////////////////////////////////
608
614
Cppyy::TCppType_t fClass
#define f(i)
Definition RSha256.hxx:104
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
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.
Option_t Option_t option
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
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
@ kInvalidObject
Definition TObject.h:377
#define gROOT
Definition TROOT.h:411
#define R__LOCKGUARD(mutex)
const_iterator begin() const
const_iterator end() const
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
ClassInfo_t * GetClassInfo() const
Definition TClass.h:445
virtual TObject ** GetObjectRef(const TObject *obj) const =0
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
const void * DeclId_t
This class stores a (key,value) pair using an external hash.
Definition TExMap.h:33
void Remove(ULong64_t hash, Long64_t key)
Remove entry with specified key from the TExMap.
Definition TExMap.cxx:216
void Add(ULong64_t hash, Long64_t key, Long64_t value)
Add an (key,value) pair to the table. The key should be unique.
Definition TExMap.cxx:87
Long64_t GetValue(ULong64_t hash, Long64_t key)
Return the value belonging to specified key and hash value.
Definition TExMap.cxx:173
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
DeclId_t GetDeclId() const
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
void Clear(Option_t *option="") override
Remove all objects from the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition THashList.cxx:68
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
THashList(const THashList &)=delete
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...
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * FindObject(const char *name) const override
Find object using its name.
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition THashList.cxx:94
void Add(TObject *obj) override
Add object to the hash table.
TObject * FindObject(const char *name) const override
Find object using its name.
TDictionary::DeclId_t DeclId_t
Iterator abstract base class.
Definition TIterator.h:30
Iterator of linked list.
Definition TList.h:196
TObject * Next() override
Return next object in the list. Returns 0 when no more objects in list.
Definition TList.cxx:1243
Iterator for TListOfFunctions.
TListOfFunctionsIter(const TListOfFunctions *l, Bool_t dir=kIterForward)
TObject * Next() override
Return next object in the list. Returns 0 when no more objects in list.
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
THashList * fUnloaded
void Clear(Option_t *option="") override
Remove all objects from the list.
void MapObject(TObject *obj)
Add pair<id, object> to the map of functions and their ids.
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
TObject ** GetObjectRef(const TObject *obj) const override
Return address of pointer to obj.
TFunction * Get(DeclId_t id)
Return (after creating it if necessary) the TMethod or TFunction describing the function correspondin...
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Int_t IndexOf(const TObject *obj) const override
Return index of object in collection.
void Delete(Option_t *option="") override
Delete all TFunction object files.
void Load()
Load all the functions known to the interpreter for the scope 'fClass' into this collection.
TListOfFunctions(const TListOfFunctions &)=delete
TObject * Remove(TObject *obj) override
Remove object from the list.
TObject * After(const TObject *obj) const override
Returns the object after object obj.
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
TList * GetListForObjectNonConst(const char *name)
Return the set of overloads for this name, collecting all available ones.
~TListOfFunctions()
Destructor.
void UnmapObject(TObject *obj)
Remove a pair<id, object> from the map of functions and their ids.
TFunction * Find(DeclId_t id) const
Return the TMethod or TFunction describing the function corresponding to the Decl 'id'.
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
virtual TList * GetListForObject(const char *name) const
Return the set of overloads for this name, collecting all available ones.
TDictionary::DeclId_t DeclId_t
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
TObjLink * FirstLink() const override
void Unload()
Mark 'all func' as being unloaded.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void AddLast(TObject *obj) override
Add object at the end of the list.
void RecursiveRemove(TObject *obj) override
Remove object from this collection and recursively remove the object from all other objects (and coll...
TIterator * MakeIterator(Bool_t dir=kIterForward) const override
Return a list iterator.
Int_t GetSize() const override
Return the capacity of the collection, i.e.
TObjLink * LastLink() const override
ULong64_t fLastLoadMarker
Int_t GetLast() const override
Returns index of last object in collection.
TObject * FindObject(const TObject *obj) const override
Find object using its hash value (returned by its Hash() member).
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:460
virtual TObjLink * LastLink() const
Definition TList.h:110
TObject * Before(const TObject *obj) const override
Returns the object before object obj.
Definition TList.cxx:501
void Add(TObject *obj) override
Definition TList.h:81
TObject * Last() const override
Return the last object in the list. Returns 0 when list is empty.
Definition TList.cxx:823
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
virtual TObjLink * FirstLink() const
Definition TList.h:107
TList()
Definition TList.h:72
TObject * At(Int_t idx) const override
Returns the object at position idx. Returns 0 if idx is out of range.
Definition TList.cxx:487
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Clear(Option_t *="")
Definition TObject.h:125
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
virtual Int_t IndexOf(const TObject *obj) const
Return index of object in collection.
virtual Int_t GetLast() const
Returns index of last object in collection.
Basic string class.
Definition TString.h:138
TMarker m
Definition textangle.C:8
TLine l
Definition textangle.C:4