Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TList.h"
22#include "TROOT.h"
23#include "TInterpreter.h"
24#include "Strlen.h"
25
26#include <iostream>
27#include "TVirtualMutex.h"
28
30
31////////////////////////////////////////////////////////////////////////////////
32/// Default TFunction ctor. TFunctions are constructed in TROOT via
33/// a call to TCling::UpdateListOfGlobalFunctions().
34
35TFunction::TFunction(MethodInfo_t *info) : TDictionary()
36{
37 fInfo = info;
38 fMethodArgs = 0;
39 if (fInfo) {
43 }
44}
45
46////////////////////////////////////////////////////////////////////////////////
47/// Copy operator.
48
50{
51 if (orig.fInfo) {
55 } else
56 fInfo = 0;
57 fMethodArgs = 0;
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Assignment operator.
62
64{
65 if (this != &rhs) {
69 delete fMethodArgs;
70 if (rhs.fInfo) {
75 } else
76 fInfo = 0;
77 fMethodArgs = 0;
78 }
79 return *this;
80}
81
82////////////////////////////////////////////////////////////////////////////////
83/// TFunction dtor deletes adopted CINT MethodInfo.
84
86{
89
91 delete fMethodArgs;
92}
93
94////////////////////////////////////////////////////////////////////////////////
95/// Clone method.
96
97TObject *TFunction::Clone(const char *newname) const
98{
99 TNamed *newobj = new TFunction(*this);
100 if (newname && strlen(newname)) newobj->SetName(newname);
101 return newobj;
102}
103
104////////////////////////////////////////////////////////////////////////////////
105/// Using the CINT method arg information to create a complete signature string.
106
108{
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Return signature of function.
115
117{
118 if (fInfo && fSignature.IsNull())
120
121 return fSignature.Data();
122}
123
124////////////////////////////////////////////////////////////////////////////////
125/// Return list containing the TMethodArgs of a TFunction.
126
128{
129 if (!fMethodArgs && fInfo) {
130 if (!gInterpreter)
131 Fatal("GetListOfMethodArgs", "gInterpreter not initialized");
132
133 gInterpreter->CreateListOfMethodArgs(this);
134 }
135 return fMethodArgs;
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Get full type description of function return type, e,g.: "class TDirectory*".
140
142{
144 if (fInfo == 0 || gCling->MethodInfo_Type(fInfo) == 0) return "Unknown";
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Get the normalized name of the return type. A normalized name is fully
150/// qualified and has all typedef desugared except for the 'special' typedef
151/// which include Double32_t, Float16_t, [U]Long64_t and std::string. It
152/// also has std:: removed [This is subject to change].
153///
154
156{
158 if (fInfo == 0 || gCling->MethodInfo_Type(fInfo) == 0) return "Unknown";
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Number of function arguments.
164
166{
167 if (fInfo) return gCling->MethodInfo_NArg(fInfo);
168 else if (fMethodArgs) return fMethodArgs->GetEntries();
169 else return 0;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Number of function optional (default) arguments.
174
176{
177 // FIXME: when unload this is an over-estimate.
179}
180
181////////////////////////////////////////////////////////////////////////////////
182/// Get property description word. For meaning of bits see EProperty.
183
185{
186 return fInfo ? gCling->MethodInfo_Property(fInfo) : 0;
187}
188
189////////////////////////////////////////////////////////////////////////////////
190/// Get property description word. For meaning of bits see EProperty.
191
193{
195}
196
197////////////////////////////////////////////////////////////////////////////////
198
200{
201 return gInterpreter->GetDeclId(fInfo);
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Return pointer to the interface method. Using this pointer we
206/// can find which TFunction belongs to a CINT MethodInfo object.
207/// Both need to have the same InterfaceMethod pointer.
208
210{
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Return true if this function object is pointing to a currently
216/// loaded function. If a function is unloaded after the TFunction
217/// is created, the TFunction will be set to be invalid.
218
220{
221 // Register the transaction when checking the validity of the object.
223 // Only for global functions. For data member functions TMethod does it.
224 DeclId_t newId = gInterpreter->GetFunction(0, fName);
225 if (newId) {
226 MethodInfo_t *info = gInterpreter->MethodInfo_Factory(newId);
227 Update(info);
228 }
229 return newId != 0;
230 }
231 return fInfo != 0;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Returns the mangled name as defined by CINT, or 0 in case of error.
236
237const char *TFunction::GetMangledName() const
238{
239 return fMangledName;
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Returns the prototype of a function as defined by CINT, or 0 in
244/// case of error.
245
246const char *TFunction::GetPrototype() const
247{
248 if (fInfo) {
251 } else
252 return 0;
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// List TFunction name and title.
257
258void TFunction::ls(Option_t *options /* ="" */) const
259{
260 TDictionary::ls(options);
262 std::cout << " " << GetPrototype() << '\n';
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Print TFunction name and title.
267
268void TFunction::Print(Option_t *options /* ="" */) const
269{
270 TDictionary::Print(options);
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Update the TFunction to reflect the new info.
275///
276/// This can be used to implement unloading (info == 0) and then reloading
277/// (info being the 'new' decl address).
278
279Bool_t TFunction::Update(MethodInfo_t *info)
280{
281 if (info == 0) {
282
283 if (fInfo) {
286 }
287 fInfo = 0;
288 if (fMethodArgs) {
289 for (Int_t i = 0; i < fMethodArgs->LastIndex() + 1; i ++) {
290 TMethodArg *arg = (TMethodArg *) fMethodArgs->At( i );
291 arg->Update(0);
292 }
293 }
294 return kTRUE;
295 } else {
296 if (fInfo) {
299 }
300 fInfo = info;
302 if (newMangledName != fMangledName) {
303 Error("Update","TFunction object updated with the 'wrong' MethodInfo (%s vs %s).",
304 fMangledName.Data(),newMangledName.Data());
305 fInfo = 0;
306 return false;
307 }
309 if (fMethodArgs) {
310 MethodArgInfo_t *arg = gCling->MethodArgInfo_Factory(fInfo);
311 Int_t i = 0;
313 while (gCling->MethodArgInfo_Next(arg)) {
314 if (gCling->MethodArgInfo_IsValid(arg)) {
315 MethodArgInfo_t *new_arg = gCling->MethodArgInfo_FactoryCopy(arg);
316 ((TMethodArg *) fMethodArgs->At( i ))->Update(new_arg);
317 ++i;
318 }
319 }
320 }
321 return kTRUE;
322 }
323}
long Long_t
Definition RtypesCore.h:54
const Bool_t kTRUE
Definition RtypesCore.h:91
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TVirtualMutex * gInterpreterMutex
R__EXTERN TInterpreter * gCling
#define gInterpreter
#define R__LOCKGUARD(mutex)
virtual Int_t GetEntries() const
This class defines an abstract interface that must be implemented by all classes that contain diction...
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
const void * DeclId_t
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
TList * fMethodArgs
Definition TFunction.h:39
TString fSignature
Definition TFunction.h:38
virtual void CreateSignature()
Using the CINT method arg information to create a complete signature string.
virtual void Print(Option_t *option="") const
Print TFunction name and title.
TString fMangledName
Definition TFunction.h:37
virtual const char * GetPrototype() const
Returns the prototype of a function as defined by CINT, or 0 in case of error.
void * InterfaceMethod() const
Return pointer to the interface method.
virtual Bool_t IsValid()
Return true if this function object is pointing to a currently loaded function.
MethodInfo_t * fInfo
Definition TFunction.h:36
const char * GetSignature()
Return signature of function.
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
virtual TObject * Clone(const char *newname="") const
Clone method.
Definition TFunction.cxx:97
virtual bool Update(MethodInfo_t *info)
Update the TFunction to reflect the new info.
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Int_t GetNargs() const
Number of function arguments.
DeclId_t GetDeclId() const
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
virtual void ls(Option_t *option="") const
List TFunction name and title.
virtual ~TFunction()
TFunction dtor deletes adopted CINT MethodInfo.
Definition TFunction.cxx:85
TFunction & operator=(const TFunction &rhs)
Assignment operator.
Definition TFunction.cxx:63
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
TFunction(MethodInfo_t *info=0)
Default TFunction ctor.
Definition TFunction.cxx:35
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
virtual int MethodInfo_NArg(MethodInfo_t *) const
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *) const =0
virtual const char * MethodInfo_Title(MethodInfo_t *) const
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *) const
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *) const
virtual int MethodArgInfo_Next(MethodArgInfo_t *) const
virtual void MethodInfo_Delete(MethodInfo_t *) const
virtual int MethodInfo_NDefaultArg(MethodInfo_t *) const
virtual Bool_t MethodArgInfo_IsValid(MethodArgInfo_t *) const
virtual const char * MethodInfo_TypeName(MethodInfo_t *) const
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *) const
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *) const
virtual const char * MethodInfo_Name(MethodInfo_t *) const
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *) const
virtual void MethodInfo_CreateSignature(MethodInfo_t *, TString &) const
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *) const
virtual Long_t MethodInfo_Property(MethodInfo_t *) const =0
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *) const
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:357
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:470
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
void Update(MethodArgInfo_t *info)
Update fInfo (to 0 for unloading and non-zero for reloading).
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:893
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:921
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition TROOT.cxx:2811
Int_t LastIndex() const
Basic string class.
Definition TString.h:136
const char * Data() const
Definition TString.h:369
Bool_t IsNull() const
Definition TString.h:407