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 after object after in the list.
115
121
122////////////////////////////////////////////////////////////////////////////////
123/// Insert object after object after in the list.
124
130
131////////////////////////////////////////////////////////////////////////////////
132/// Insert object before object before in the list.
133
139
140////////////////////////////////////////////////////////////////////////////////
141/// Insert object before object before in the list.
142
148
149////////////////////////////////////////////////////////////////////////////////
150/// Remove all objects from the list. Does not delete the objects unless
151/// the THashList is the owner (set via SetOwner()).
152
159
160////////////////////////////////////////////////////////////////////////////////
161/// Delete all TFunction object files.
162
169
170////////////////////////////////////////////////////////////////////////////////
171/// Specialize FindObject to do search for the
172/// a function just by name or create it if its not already in the list
173
175{
177 if (!result) {
178
180
182 if (fClass) decl = gInterpreter->GetFunctionTemplate(fClass->GetClassInfo(),name);
183 else decl = gInterpreter->GetFunctionTemplate(nullptr,name);
184 if (decl) result = const_cast<TListOfFunctionTemplates*>(this)->Get(decl);
185 }
186 return result;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Return the set of overloads for this name, collecting all available ones.
191/// Can construct and insert new TFunction-s.
192
194{
196
199 Bool_t wasEmpty = true;
200 if (!overloads) {
201 overloads = new TList();
202 overloads->SetName(name);
204 } else {
207 wasEmpty = false;
208 overloadsSet.Add((Long64_t)(ULong64_t)over->GetDeclId(),
210 }
211 }
212
213 // Update if needed.
214 std::vector<DeclId_t> overloadDecls;
215 ClassInfo_t* ci = fClass ? fClass->GetClassInfo() : nullptr;
216 gInterpreter->GetFunctionOverloads(ci, name, overloadDecls);
217 for (std::vector<DeclId_t>::const_iterator iD = overloadDecls.begin(),
218 eD = overloadDecls.end(); iD != eD; ++iD) {
220 if (wasEmpty || !overloadsSet.GetValue((Long64_t)(ULong64_t)over->GetDeclId())) {
221 overloads->Add(over);
222 }
223 }
224
225 return overloads;
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Return the set of overloads for this name, collecting all available ones.
230/// Can construct and insert new TFunction-s.
231
236
237////////////////////////////////////////////////////////////////////////////////
238/// Return the set of overloads for function obj, collecting all available ones.
239/// Can construct and insert new TFunction-s.
240
242{
243 if (!obj) return nullptr;
244 return const_cast<TListOfFunctionTemplates*>(this)
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Return (after creating it if necessary) the TMethod or TFunction
250/// describing the function corresponding to the Decl 'id'.
251
253{
254 if (!id) return nullptr;
255
257 if (!f) {
258 if (fClass) {
259 if (!gInterpreter->ClassInfo_Contains(fClass->GetClassInfo(),id)) return nullptr;
260 } else {
261 if (!gInterpreter->ClassInfo_Contains(nullptr,id)) return nullptr;
262 }
263
265
266 FuncTempInfo_t *m = gInterpreter->FuncTempInfo_Factory(id);
267
268 // Let's see if this is a reload ...
270 gInterpreter->FuncTempInfo_Name(m, name);
272 if (update) {
274 update->Update(m);
275 f = update;
276 }
277 if (!f) {
278 if (fClass) f = new TFunctionTemplate(m, fClass);
279 else f = new TFunctionTemplate(m, nullptr);
280 }
281 // Calling 'just' THahList::Add would turn around and call
282 // TListOfFunctionTemplates::AddLast which should *also* do the fIds->Add.
284 fIds->Add((Long64_t)id,(Long64_t)f);
285 }
286 return f;
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Remove a pair<id, object> from the map of functions and their ids.
291
293{
294 TFunctionTemplate *f = dynamic_cast<TFunctionTemplate*>(obj);
295 if (f) {
296 fIds->Remove((Long64_t)f->GetDeclId());
297 }
298}
299
300////////////////////////////////////////////////////////////////////////////////
301/// Remove object from this collection and recursively remove the object
302/// from all other objects (and collections).
303/// This function overrides TCollection::RecursiveRemove that calls
304/// the Remove function. THashList::Remove cannot be called because
305/// it uses the hash value of the hash table. This hash value
306/// is not available anymore when RecursiveRemove is called from
307/// the TObject destructor.
308
310{
311 if (!obj) return;
312
315 UnmapObject(obj);
316
317}
318
319////////////////////////////////////////////////////////////////////////////////
320/// Remove object from the list.
321
323{
324 Bool_t found;
325
326 found = THashList::Remove(obj);
327 if (!found) {
328 found = fUnloaded->Remove(obj);
329 }
330 UnmapObject(obj);
331 if (found) return obj;
332 else return nullptr;
333}
334
335////////////////////////////////////////////////////////////////////////////////
336/// Remove object via its objlink from the list.
337
339{
340 if (!lnk) return nullptr;
341
342 TObject *obj = lnk->GetObject();
343
345 fUnloaded->Remove(obj);
346
347 UnmapObject(obj);
348 return obj;
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// Load all the functions known to the interpreter for the scope 'fClass'
353/// into this collection.
354
356{
357 if (fClass && fClass->GetClassInfo() == nullptr) return;
358
360
361 ULong64_t currentTransaction = gInterpreter->GetInterpreterStateMarker();
363 return;
364 }
366
367 gInterpreter->LoadFunctionTemplates(fClass);
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Mark 'all func' as being unloaded.
372/// After the unload, the function can no longer be found directly,
373/// until the decl can be found again in the interpreter (in which
374/// the func object will be reused.
375
377{
379 while (lnk) {
380 TFunctionTemplate *func = (TFunctionTemplate*)lnk->GetObject();
381
382 fIds->Remove((Long64_t)func->GetDeclId());
383 fUnloaded->Add(func);
384
385 lnk = lnk->Next();
386 }
387
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Mark 'func' as being unloaded.
393/// After the unload, the function can no longer be found directly,
394/// until the decl can be found again in the interpreter (in which
395/// the func object will be reused.
396
398{
399 if (THashList::Remove(func)) {
400 // We contains the object, let remove it from the other internal
401 // list and move it to the list of unloaded objects.
402
403 fIds->Remove((Long64_t)func->GetDeclId());
404 fUnloaded->Add(func);
405 }
406}
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:102
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