Logo ROOT  
Reference Guide
TFunction.cxx
Go to the documentation of this file.
1// @(#)root/meta:$Id$
2// Author: Fons Rademakers 07/02/97
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 TFunction
13Global functions class (global functions are obtained from CINT).
14This class describes one single global function.
15The TROOT class contains a list of all currently defined global
16functions (accessible via TROOT::GetListOfGlobalFunctions()).
17*/
18
19#include "TFunction.h"
20#include "TMethodArg.h"
21#include "TROOT.h"
22#include "TInterpreter.h"
23#include "Strlen.h"
24
25#include <iostream>
26#include "TVirtualMutex.h"
27
29
30////////////////////////////////////////////////////////////////////////////////
31/// Default TFunction ctor. TFunctions are constructed in TROOT via
32/// a call to TCling::UpdateListOfGlobalFunctions().
33
34TFunction::TFunction(MethodInfo_t *info) : TDictionary()
35{
36 fInfo = info;
37 fMethodArgs = 0;
38 if (fInfo) {
42 }
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// Copy operator.
47
49{
50 if (orig.fInfo) {
54 } else
55 fInfo = 0;
56 fMethodArgs = 0;
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// Assignment operator.
61
63{
64 if (this != &rhs) {
68 delete fMethodArgs;
69 if (rhs.fInfo) {
74 } else
75 fInfo = 0;
76 fMethodArgs = 0;
77 }
78 return *this;
79}
80
81////////////////////////////////////////////////////////////////////////////////
82/// TFunction dtor deletes adopted CINT MethodInfo.
83
85{
88
90 delete fMethodArgs;
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Clone method.
95
96TObject *TFunction::Clone(const char *newname) const
97{
98 TNamed *newobj = new TFunction(*this);
99 if (newname && strlen(newname)) newobj->SetName(newname);
100 return newobj;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Using the CINT method arg information to create a complete signature string.
105
107{
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Return signature of function.
114
116{
117 if (fInfo && fSignature.IsNull())
119
120 return fSignature.Data();
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Return list containing the TMethodArgs of a TFunction.
125
127{
128 if (!fMethodArgs && fInfo) {
129 if (!gInterpreter)
130 Fatal("GetListOfMethodArgs", "gInterpreter not initialized");
131
132 gInterpreter->CreateListOfMethodArgs(this);
133 }
134 return fMethodArgs;
135}
136
137////////////////////////////////////////////////////////////////////////////////
138/// Get full type description of function return type, e,g.: "class TDirectory*".
139
141{
143 if (fInfo == 0 || gCling->MethodInfo_Type(fInfo) == 0) return "Unknown";
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Get the normalized name of the return type. A normalized name is fully
149/// qualified and has all typedef desugared except for the 'special' typedef
150/// which include Double32_t, Float16_t, [U]Long64_t and std::string. It
151/// also has std:: removed [This is subject to change].
152///
153
155{
157 if (fInfo == 0 || gCling->MethodInfo_Type(fInfo) == 0) return "Unknown";
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Number of function arguments.
163
165{
166 if (fInfo) return gCling->MethodInfo_NArg(fInfo);
167 else if (fMethodArgs) return fMethodArgs->GetEntries();
168 else return 0;
169}
170
171////////////////////////////////////////////////////////////////////////////////
172/// Number of function optional (default) arguments.
173
175{
176 // FIXME: when unload this is an over-estimate.
178}
179
180////////////////////////////////////////////////////////////////////////////////
181/// Get property description word. For meaning of bits see EProperty.
182
184{
185 return fInfo ? gCling->MethodInfo_Property(fInfo) : 0;
186}
187
188////////////////////////////////////////////////////////////////////////////////
189/// Get property description word. For meaning of bits see EProperty.
190
192{
194}
195
196////////////////////////////////////////////////////////////////////////////////
197
199{
200 return gInterpreter->GetDeclId(fInfo);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Return pointer to the interface method. Using this pointer we
205/// can find which TFunction belongs to a CINT MethodInfo object.
206/// Both need to have the same InterfaceMethod pointer.
207
209{
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Return true if this function object is pointing to a currently
215/// loaded function. If a function is unloaded after the TFunction
216/// is created, the TFunction will be set to be invalid.
217
219{
220 // Register the transaction when checking the validity of the object.
222 // Only for global functions. For data member functions TMethod does it.
223 DeclId_t newId = gInterpreter->GetFunction(0, fName);
224 if (newId) {
225 MethodInfo_t *info = gInterpreter->MethodInfo_Factory(newId);
226 Update(info);
227 }
228 return newId != 0;
229 }
230 return fInfo != 0;
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Returns the mangled name as defined by CINT, or 0 in case of error.
235
236const char *TFunction::GetMangledName() const
237{
238 return fMangledName;
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Returns the prototype of a function as defined by CINT, or 0 in
243/// case of error.
244
245const char *TFunction::GetPrototype() const
246{
247 if (fInfo) {
250 } else
251 return 0;
252}
253
254////////////////////////////////////////////////////////////////////////////////
255/// List TFunction name and title.
256
257void TFunction::ls(Option_t *options /* ="" */) const
258{
259 TDictionary::ls(options);
261 std::cout << " " << GetPrototype() << '\n';
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Print TFunction name and title.
266
267void TFunction::Print(Option_t *options /* ="" */) const
268{
269 TDictionary::Print(options);
270}
271
272////////////////////////////////////////////////////////////////////////////////
273/// Update the TFunction to reflect the new info.
274///
275/// This can be used to implement unloading (info == 0) and then reloading
276/// (info being the 'new' decl address).
277
278Bool_t TFunction::Update(MethodInfo_t *info)
279{
280 if (info == 0) {
281
282 if (fInfo) {
285 }
286 fInfo = 0;
287 if (fMethodArgs) {
288 for (Int_t i = 0; i < fMethodArgs->LastIndex() + 1; i ++) {
289 TMethodArg *arg = (TMethodArg *) fMethodArgs->At( i );
290 arg->Update(0);
291 }
292 }
293 return kTRUE;
294 } else {
295 if (fInfo) {
298 }
299 fInfo = info;
301 if (newMangledName != fMangledName) {
302 Error("Update","TFunction object updated with the 'wrong' MethodInfo (%s vs %s).",
303 fMangledName.Data(),newMangledName.Data());
304 fInfo = 0;
305 return false;
306 }
308 if (fMethodArgs) {
309 MethodArgInfo_t *arg = gCling->MethodArgInfo_Factory(fInfo);
310 Int_t i = 0;
312 while (gCling->MethodArgInfo_Next(arg)) {
313 if (gCling->MethodArgInfo_IsValid(arg)) {
314 MethodArgInfo_t *new_arg = gCling->MethodArgInfo_FactoryCopy(arg);
315 ((TMethodArg *) fMethodArgs->At( i ))->Update(new_arg);
316 ++i;
317 }
318 }
319 }
320 return kTRUE;
321 }
322}
int Int_t
Definition: RtypesCore.h:41
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:40
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:556
#define gInterpreter
Definition: TInterpreter.h:555
#define R__LOCKGUARD(mutex)
virtual Int_t GetEntries() const
Definition: TCollection.h:177
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:162
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
const void * DeclId_t
Definition: TDictionary.h:209
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:28
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
Definition: TFunction.cxx:236
TList * fMethodArgs
Definition: TFunction.h:37
TString fSignature
Definition: TFunction.h:36
virtual void CreateSignature()
Using the CINT method arg information to create a complete signature string.
Definition: TFunction.cxx:106
virtual void Print(Option_t *option="") const
Print TFunction name and title.
Definition: TFunction.cxx:267
TString fMangledName
Definition: TFunction.h:35
virtual const char * GetPrototype() const
Returns the prototype of a function as defined by CINT, or 0 in case of error.
Definition: TFunction.cxx:245
void * InterfaceMethod() const
Return pointer to the interface method.
Definition: TFunction.cxx:208
virtual Bool_t IsValid()
Return true if this function object is pointing to a currently loaded function.
Definition: TFunction.cxx:218
MethodInfo_t * fInfo
Definition: TFunction.h:34
const char * GetSignature()
Return signature of function.
Definition: TFunction.cxx:115
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:183
virtual TObject * Clone(const char *newname="") const
Clone method.
Definition: TFunction.cxx:96
virtual bool Update(MethodInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TFunction.cxx:278
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Definition: TFunction.cxx:174
Int_t GetNargs() const
Number of function arguments.
Definition: TFunction.cxx:164
DeclId_t GetDeclId() const
Definition: TFunction.cxx:198
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:191
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
Definition: TFunction.cxx:126
virtual void ls(Option_t *option="") const
List TFunction name and title.
Definition: TFunction.cxx:257
virtual ~TFunction()
TFunction dtor deletes adopted CINT MethodInfo.
Definition: TFunction.cxx:84
TFunction & operator=(const TFunction &rhs)
Assignment operator.
Definition: TFunction.cxx:62
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
Definition: TFunction.cxx:140
TFunction(MethodInfo_t *info=0)
Default TFunction ctor.
Definition: TFunction.cxx:34
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
Definition: TFunction.cxx:154
virtual int MethodInfo_NArg(MethodInfo_t *) const
Definition: TInterpreter.h:489
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *) const =0
virtual const char * MethodInfo_Title(MethodInfo_t *) const
Definition: TInterpreter.h:501
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *) const
Definition: TInterpreter.h:497
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *) const
Definition: TInterpreter.h:494
virtual int MethodArgInfo_Next(MethodArgInfo_t *) const
Definition: TInterpreter.h:509
virtual void MethodInfo_Delete(MethodInfo_t *) const
Definition: TInterpreter.h:482
virtual int MethodInfo_NDefaultArg(MethodInfo_t *) const
Definition: TInterpreter.h:490
virtual Bool_t MethodArgInfo_IsValid(MethodArgInfo_t *) const
Definition: TInterpreter.h:508
virtual const char * MethodInfo_TypeName(MethodInfo_t *) const
Definition: TInterpreter.h:499
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
Definition: TInterpreter.h:505
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *) const
Definition: TInterpreter.h:487
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *) const
Definition: TInterpreter.h:486
virtual const char * MethodInfo_Name(MethodInfo_t *) const
Definition: TInterpreter.h:498
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *) const
Definition: TInterpreter.h:507
virtual void MethodInfo_CreateSignature(MethodInfo_t *, TString &) const
Definition: TInterpreter.h:481
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *) const
Definition: TInterpreter.h:500
virtual Long_t MethodInfo_Property(MethodInfo_t *) const =0
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *) const
Definition: TInterpreter.h:496
A doubly linked list.
Definition: TList.h:44
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
Definition: TList.cxx:354
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:467
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:31
void Update(MethodArgInfo_t *info)
Update fInfo (to 0 for unloading and non-zero for reloading).
Definition: TMethodArg.cxx:130
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual void ls(Option_t *option="") const
List TNamed name and title.
Definition: TNamed.cxx:113
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TNamed.cxx:128
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TString fName
Definition: TNamed.h:32
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:908
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2829
Int_t LastIndex() const
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402