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
13 Global functions class (global functions are obtained from CINT).
14 This class describes one single global function.
15 The TROOT class contains a list of all currently defined global
16 functions (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 
35 TFunction::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 
97 TObject *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())
119  CreateSignature();
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 
141 const char *TFunction::GetReturnTypeName() const
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 
237 const 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 
246 const char *TFunction::GetPrototype() const
247 {
248  if (fInfo) {
251  } else
252  return 0;
253 }
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 /// List TFunction name and title.
257 
258 void 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 
268 void 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 
279 Bool_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;
301  TString newMangledName = gCling->MethodInfo_GetMangledName(fInfo);
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 }
TInterpreter::MethodInfo_NDefaultArg
virtual int MethodInfo_NDefaultArg(MethodInfo_t *) const
Definition: TInterpreter.h:495
TInterpreter::MethodArgInfo_FactoryCopy
virtual MethodArgInfo_t * MethodArgInfo_FactoryCopy(MethodArgInfo_t *) const
Definition: TInterpreter.h:512
TFunction::operator=
TFunction & operator=(const TFunction &rhs)
Assignment operator.
Definition: TFunction.cxx:63
TInterpreter::MethodInfo_Type
virtual TypeInfo_t * MethodInfo_Type(MethodInfo_t *) const
Definition: TInterpreter.h:499
TFunction::TFunction
TFunction(MethodInfo_t *info=0)
Default TFunction ctor.
Definition: TFunction.cxx:35
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TInterpreter::MethodInfo_InterfaceMethod
virtual void * MethodInfo_InterfaceMethod(MethodInfo_t *) const
Definition: TInterpreter.h:492
TInterpreter::MethodInfo_Name
virtual const char * MethodInfo_Name(MethodInfo_t *) const
Definition: TInterpreter.h:503
TNamed::SetName
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition: TNamed.cxx:140
Option_t
const char Option_t
Definition: RtypesCore.h:66
TCollection::GetEntries
virtual Int_t GetEntries() const
Definition: TCollection.h:177
TList::Delete
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
Definition: TList.cxx:470
TString::Data
const char * Data() const
Definition: TString.h:369
TFunction.h
TInterpreter::MethodInfo_TypeName
virtual const char * MethodInfo_TypeName(MethodInfo_t *) const
Definition: TInterpreter.h:504
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TInterpreter::MethodArgInfo_Next
virtual int MethodArgInfo_Next(MethodArgInfo_t *) const
Definition: TInterpreter.h:514
TInterpreter::MethodInfo_GetMangledName
virtual const char * MethodInfo_GetMangledName(MethodInfo_t *) const
Definition: TInterpreter.h:501
TMethodArg
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition: TMethodArg.h:36
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
TFunction::fMangledName
TString fMangledName
Definition: TFunction.h:37
TFunction::GetListOfMethodArgs
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
Definition: TFunction.cxx:127
TFunction::fSignature
TString fSignature
Definition: TFunction.h:38
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:560
TInterpreter::MethodInfo_ExtraProperty
virtual Long_t MethodInfo_ExtraProperty(MethodInfo_t *) const =0
TInterpreter::MethodInfo_GetPrototype
virtual const char * MethodInfo_GetPrototype(MethodInfo_t *) const
Definition: TInterpreter.h:502
TObject::Fatal
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition: TObject.cxx:918
TNamed::fName
TString fName
Definition: TNamed.h:32
TSeqCollection::LastIndex
Int_t LastIndex() const
Definition: TSeqCollection.h:55
TInterpreter::MethodInfo_Title
virtual const char * MethodInfo_Title(MethodInfo_t *) const
Definition: TInterpreter.h:506
TInterpreter::MethodInfo_NArg
virtual int MethodInfo_NArg(MethodInfo_t *) const
Definition: TInterpreter.h:494
Strlen.h
TList.h
TFunction::GetDeclId
DeclId_t GetDeclId() const
Definition: TFunction.cxx:199
TFunction::Print
virtual void Print(Option_t *option="") const
Print TFunction name and title.
Definition: TFunction.cxx:268
TString
Basic string class.
Definition: TString.h:136
TFunction::Clone
virtual TObject * Clone(const char *newname="") const
Clone method.
Definition: TFunction.cxx:97
bool
TROOT.h
TFunction::fInfo
MethodInfo_t * fInfo
Definition: TFunction.h:36
TFunction::IsValid
virtual Bool_t IsValid()
Return true if this function object is pointing to a currently loaded function.
Definition: TFunction.cxx:219
TList::At
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
TFunction::GetPrototype
virtual const char * GetPrototype() const
Returns the prototype of a function as defined by CINT, or 0 in case of error.
Definition: TFunction.cxx:246
TFunction::GetNargsOpt
Int_t GetNargsOpt() const
Number of function optional (default) arguments.
Definition: TFunction.cxx:175
TFunction::GetReturnTypeNormalizedName
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
Definition: TFunction.cxx:155
TInterpreter::MethodArgInfo_Factory
virtual MethodArgInfo_t * MethodArgInfo_Factory() const
Definition: TInterpreter.h:510
TFunction::Property
Long_t Property() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:184
TFunction::InterfaceMethod
void * InterfaceMethod() const
Return pointer to the interface method.
Definition: TFunction.cxx:209
TInterpreter::MethodArgInfo_IsValid
virtual Bool_t MethodArgInfo_IsValid(MethodArgInfo_t *) const
Definition: TInterpreter.h:513
gInterpreterMutex
R__EXTERN TVirtualMutex * gInterpreterMutex
Definition: TInterpreter.h:44
TInterpreter::MethodInfo_FactoryCopy
virtual MethodInfo_t * MethodInfo_FactoryCopy(MethodInfo_t *) const
Definition: TInterpreter.h:491
TNamed::Print
virtual void Print(Option_t *option="") const
Print TNamed name and title.
Definition: TNamed.cxx:128
TDictionary::DeclId_t
const void * DeclId_t
Definition: TDictionary.h:223
TInterpreter::MethodInfo_CreateSignature
virtual void MethodInfo_CreateSignature(MethodInfo_t *, TString &) const
Definition: TInterpreter.h:486
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TFunction::fMethodArgs
TList * fMethodArgs
Definition: TFunction.h:39
Long_t
long Long_t
Definition: RtypesCore.h:54
TInterpreter::MethodInfo_Property
virtual Long_t MethodInfo_Property(MethodInfo_t *) const =0
R__LOCKGUARD
#define R__LOCKGUARD(mutex)
Definition: TVirtualMutex.h:104
TFunction::GetReturnTypeName
const char * GetReturnTypeName() const
Get full type description of function return type, e,g.: "class TDirectory*".
Definition: TFunction.cxx:141
TFunction::GetNargs
Int_t GetNargs() const
Number of function arguments.
Definition: TFunction.cxx:165
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TVirtualMutex.h
TROOT::IndentLevel
static void IndentLevel()
Functions used by ls() to indent an object hierarchy.
Definition: TROOT.cxx:2806
TFunction::ExtraProperty
Long_t ExtraProperty() const
Get property description word. For meaning of bits see EProperty.
Definition: TFunction.cxx:192
TDictionary
This class defines an abstract interface that must be implemented by all classes that contain diction...
Definition: TDictionary.h:167
TMethodArg::Update
void Update(MethodArgInfo_t *info)
Update fInfo (to 0 for unloading and non-zero for reloading).
Definition: TMethodArg.cxx:129
TFunction::GetMangledName
virtual const char * GetMangledName() const
Returns the mangled name as defined by CINT, or 0 in case of error.
Definition: TFunction.cxx:237
TFunction::Update
virtual bool Update(MethodInfo_t *info)
Update the TFunction to reflect the new info.
Definition: TFunction.cxx:279
TString::IsNull
Bool_t IsNull() const
Definition: TString.h:407
TInterpreter::MethodInfo_Delete
virtual void MethodInfo_Delete(MethodInfo_t *) const
Definition: TInterpreter.h:487
TInterpreter.h
TInterpreter::MethodInfo_TypeNormalizedName
virtual std::string MethodInfo_TypeNormalizedName(MethodInfo_t *) const
Definition: TInterpreter.h:505
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TFunction::~TFunction
virtual ~TFunction()
TFunction dtor deletes adopted CINT MethodInfo.
Definition: TFunction.cxx:85
gCling
R__EXTERN TInterpreter * gCling
Definition: TInterpreter.h:561
TDictionary::UpdateInterpreterStateMarker
Bool_t UpdateInterpreterStateMarker()
the Cling ID of the transaction that last updated the object
Definition: TDictionary.cxx:109
TFunction::GetSignature
const char * GetSignature()
Return signature of function.
Definition: TFunction.cxx:116
TMethodArg.h
TNamed::ls
virtual void ls(Option_t *option="") const
List TNamed name and title.
Definition: TNamed.cxx:113
TFunction::CreateSignature
virtual void CreateSignature()
Using the CINT method arg information to create a complete signature string.
Definition: TFunction.cxx:107
TFunction
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:30
TList
A doubly linked list.
Definition: TList.h:44
int
TFunction::ls
virtual void ls(Option_t *option="") const
List TFunction name and title.
Definition: TFunction.cxx:258