Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TListOfFunctionTemplates.cxx
Go to the documentation of this file.
1// @(#)root/cont
2// Author: Bianca-Cristina Cristescu March 2014
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 TListOfFunctionTemplates
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
19#include "TClass.h"
20#include "TExMap.h"
21#include "TFunction.h"
22#include "TFunctionTemplate.h"
23#include "TMethod.h"
24#include "TInterpreter.h"
25#include "TVirtualMutex.h"
26
27
28////////////////////////////////////////////////////////////////////////////////
29/// Constructor.
30
32 fUnloaded(nullptr),fLastLoadMarker(0)
33{
34 fIds = new TExMap;
35 fUnloaded = new THashList;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// Destructor.
40
48
49////////////////////////////////////////////////////////////////////////////////
50/// Add pair<id, object> to the map of functions and their ids.
51
53{
54 TFunctionTemplate *f = dynamic_cast<TFunctionTemplate*>(obj);
55 if (f) {
56 fIds->Add((Long64_t)f->GetDeclId(),(Long64_t)f);
57 }
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Add object at the beginning of the list.
62
68
69////////////////////////////////////////////////////////////////////////////////
70/// Add object at the beginning of the list and also store option.
71/// Storing an option is useful when one wants to change the behaviour
72/// of an object a little without having to create a complete new
73/// copy of the object. This feature is used, for example, by the Draw()
74/// method. It allows the same object to be drawn in different ways.
75
81
82////////////////////////////////////////////////////////////////////////////////
83/// Add object at the end of the list.
84
90
91////////////////////////////////////////////////////////////////////////////////
92/// Add object at the end of the list and also store option.
93/// Storing an option is useful when one wants to change the behaviour
94/// of an object a little without having to create a complete new
95/// copy of the object. This feature is used, for example, by the Draw()
96/// method. It allows the same object to be drawn in different ways.
97
99{
100 THashList::AddLast(obj, opt);
101 MapObject(obj);
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Insert object at location idx in the list.
106
108{
109 THashList::AddAt(obj, idx);
110 MapObject(obj);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Insert object at location idx in the list, with options.
115
117{
118 THashList::AddAt(obj, idx, opt);
119 MapObject(obj);
120}
121
122////////////////////////////////////////////////////////////////////////////////
123/// Insert object after object after in the list.
124
130
131////////////////////////////////////////////////////////////////////////////////
132/// Insert object after object after in the list.
133
139
140////////////////////////////////////////////////////////////////////////////////
141/// Insert object after object after in the list, with options.
142
144{
145 THashList::AddAfter(after, obj, opt);
146 MapObject(obj);
147}
148
149////////////////////////////////////////////////////////////////////////////////
150/// Insert object after object after in the list, with options.
151
157
158////////////////////////////////////////////////////////////////////////////////
159/// Insert object before object before in the list.
160
166
167////////////////////////////////////////////////////////////////////////////////
168/// Insert object before object before in the list.
169
175
176////////////////////////////////////////////////////////////////////////////////
177/// Insert object before object before in the list, with options.
178
180{
181 THashList::AddBefore(before, obj, opt);
182 MapObject(obj);
183}
184
185////////////////////////////////////////////////////////////////////////////////
186/// Insert object before object before in the list, with options.
187
193
194////////////////////////////////////////////////////////////////////////////////
195/// Remove all objects from the list. Does not delete the objects unless
196/// the THashList is the owner (set via SetOwner()).
197
204
205////////////////////////////////////////////////////////////////////////////////
206/// Delete all TFunction object files.
207
214
215////////////////////////////////////////////////////////////////////////////////
216/// Specialize FindObject to do search for the
217/// a function just by name or create it if its not already in the list
218
220{
222 if (!result) {
223
225
227 if (fClass) decl = gInterpreter->GetFunctionTemplate(fClass->GetClassInfo(),name);
228 else decl = gInterpreter->GetFunctionTemplate(nullptr,name);
229 if (decl) result = const_cast<TListOfFunctionTemplates*>(this)->Get(decl);
230 }
231 return result;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Return the set of overloads for this name, collecting all available ones.
236/// Can construct and insert new TFunction-s.
237
239{
241
244 Bool_t wasEmpty = true;
245 if (!overloads) {
246 overloads = new TList();
247 overloads->SetName(name);
249 } else {
252 wasEmpty = false;
253 overloadsSet.Add((Long64_t)(ULong64_t)over->GetDeclId(),
255 }
256 }
257
258 // Update if needed.
259 std::vector<DeclId_t> overloadDecls;
260 ClassInfo_t* ci = fClass ? fClass->GetClassInfo() : nullptr;
261 gInterpreter->GetFunctionOverloads(ci, name, overloadDecls);
262 for (std::vector<DeclId_t>::const_iterator iD = overloadDecls.begin(),
263 eD = overloadDecls.end(); iD != eD; ++iD) {
265 if (wasEmpty || !overloadsSet.GetValue((Long64_t)(ULong64_t)over->GetDeclId())) {
266 overloads->Add(over);
267 }
268 }
269
270 return overloads;
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Return the set of overloads for this name, collecting all available ones.
275/// Can construct and insert new TFunction-s.
276
281
282////////////////////////////////////////////////////////////////////////////////
283/// Return the set of overloads for function obj, collecting all available ones.
284/// Can construct and insert new TFunction-s.
285
287{
288 if (!obj) return nullptr;
289 return const_cast<TListOfFunctionTemplates*>(this)
291}
292
293////////////////////////////////////////////////////////////////////////////////
294/// Return (after creating it if necessary) the TMethod or TFunction
295/// describing the function corresponding to the Decl 'id'.
296
298{
299 if (!id) return nullptr;
300
302 if (!f) {
303 if (fClass) {
304 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(),id)) return nullptr;
305 } else {
306 if (!gInterpreter->ClassInfo_Contains(nullptr,id)) return nullptr;
307 }
308
310
311 FuncTempInfo_t *m = gInterpreter->FuncTempInfo_Factory(id);
312
313 // Let's see if this is a reload ...
315 gInterpreter->FuncTempInfo_Name(m, name);
317 if (update) {
319 update->Update(m);
320 f = update;
321 }
322 if (!f) {
323 if (fClass) f = new TFunctionTemplate(m, fClass);
324 else f = new TFunctionTemplate(m, nullptr);
325 }
326 // Calling 'just' THahList::Add would turn around and call
327 // TListOfFunctionTemplates::AddLast which should *also* do the fIds->Add.
329 fIds->Add((Long64_t)id,(Long64_t)f);
330 }
331 return f;
332}
333
334////////////////////////////////////////////////////////////////////////////////
335/// Remove a pair<id, object> from the map of functions and their ids.
336
338{
339 TFunctionTemplate *f = dynamic_cast<TFunctionTemplate*>(obj);
340 if (f) {
341 fIds->Remove((Long64_t)f->GetDeclId());
342 }
343}
344
345////////////////////////////////////////////////////////////////////////////////
346/// Remove object from this collection and recursively remove the object
347/// from all other objects (and collections).
348/// This function overrides TCollection::RecursiveRemove that calls
349/// the Remove function. THashList::Remove cannot be called because
350/// it uses the hash value of the hash table. This hash value
351/// is not available anymore when RecursiveRemove is called from
352/// the TObject destructor.
353
355{
356 if (!obj) return;
357
360 UnmapObject(obj);
361
362}
363
364////////////////////////////////////////////////////////////////////////////////
365/// Remove object from the list.
366
368{
369 Bool_t found;
370
371 found = THashList::Remove(obj);
372 if (!found) {
373 found = fUnloaded->Remove(obj);
374 }
375 UnmapObject(obj);
376 if (found) return obj;
377 else return nullptr;
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Remove object via its objlink from the list.
382
384{
385 if (!lnk) return nullptr;
386
387 TObject *obj = lnk->GetObject();
388
390 fUnloaded->Remove(obj);
391
392 UnmapObject(obj);
393 return obj;
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Load all the functions known to the interpreter for the scope 'fClass'
398/// into this collection.
399
401{
402 if (fClass && fClass->GetClassInfo() == nullptr) return;
403
405
406 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
408 return;
409 }
411
412 gInterpreter->LoadFunctionTemplates(fClass);
413}
414
415////////////////////////////////////////////////////////////////////////////////
416/// Mark 'all func' as being unloaded.
417/// After the unload, the function can no longer be found directly,
418/// until the decl can be found again in the interpreter (in which
419/// the func object will be reused.
420
422{
424 while (lnk) {
425 TFunctionTemplate *func = (TFunctionTemplate*)lnk->GetObject();
426
427 fIds->Remove((Long64_t)func->GetDeclId());
428 fUnloaded->Add(func);
429
430 lnk = lnk->Next();
431 }
432
434}
435
436////////////////////////////////////////////////////////////////////////////////
437/// Mark 'func' as being unloaded.
438/// After the unload, the function can no longer be found directly,
439/// until the decl can be found again in the interpreter (in which
440/// the func object will be reused.
441
443{
444 if (THashList::Remove(func)) {
445 // We contains the object, let remove it from the other internal
446 // list and move it to the list of unloaded objects.
447
448 fIds->Remove((Long64_t)func->GetDeclId());
449 fUnloaded->Add(func);
450 }
451}
Cppyy::TCppType_t fClass
#define f(i)
Definition RSha256.hxx:104
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char name[80]
Definition TGX11.cxx:110
R__EXTERN TVirtualMutex * gInterpreterMutex
#define gInterpreter
#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
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
Dictionary for function template This class describes one single function template.
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
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
A collection of TFunction objects designed for fast access given a DeclId_t and for keep track of TFu...
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
TFunctionTemplate * Get(DeclId_t id)
Return (after creating it if necessary) the TMethod or TFunction describing the function correspondin...
TObject * FindObject(const char *name) const override
Specialize FindObject to do search for the a function just by name or create it if its not already in...
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
void Clear(Option_t *option="") override
Remove all objects from the list.
void Load()
Load all the functions known to the interpreter for the scope 'fClass' into this collection.
TObject * Remove(TObject *obj) override
Remove object from the list.
void Unload()
Mark 'all func' as being unloaded.
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before 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...
void Delete(Option_t *option="") override
Delete all TFunction object files.
virtual TList * GetListForObject(const char *name) const
Return the set of overloads for this name, collecting all available ones.
void MapObject(TObject *obj)
Add pair<id, object> to the map of functions and their ids.
TList * GetListForObjectNonConst(const char *name)
Return the set of overloads for this name, collecting all available ones.
void UnmapObject(TObject *obj)
Remove a pair<id, object> from the map of functions and their ids.
TListOfFunctionTemplates(const TListOfFunctionTemplates &)=delete
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
virtual TObjLink * FirstLink() const
Definition TList.h:107
TList()
Definition TList.h:72
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
Basic string class.
Definition TString.h:138
TMarker m
Definition textangle.C:8