ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TMethodCall.h
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Fons Rademakers 13/06/96
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 #ifndef ROOT_TMethodCall
13 #define ROOT_TMethodCall
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TMethodCall //
19 // //
20 // Method or function calling interface. Objects of this class contain //
21 // the (CINT) environment to call a global function or a method for an //
22 // object of a specific class with the desired arguments. This class is //
23 // espicially useful when a method has to be called more times for //
24 // different objects and/or with different arguments. If a function or //
25 // method needs to be called only once one better uses //
26 // TInterpreter::Execute(). //
27 // //
28 //////////////////////////////////////////////////////////////////////////
29 
30 #ifndef ROOT_TDictionary
31 #include "TDictionary.h"
32 #endif
33 
34 #ifndef ROOT_TInterpreter
35 #include "TInterpreter.h"
36 #endif
37 
38 class TClass;
39 class TFunction;
40 
41 class TMethodCall : public TObject {
42 
43 public:
45 
46  // For backward compatibility:
52  // Historical name.
54 
55  // enum EReturnType { kLong, kDouble, kString, kOther, kNone };
56 
57 private:
58  CallFunc_t *fFunc; //CINT method invocation environment
59  Long_t fOffset; //offset added to object pointer before method invocation
60  TClass *fClass; //pointer to the class info
61  TFunction *fMetPtr; //pointer to the method or function info
62  TString fMethod; //method name
63  TString fParams; //argument string
64  TString fProto; //prototype string
65  Bool_t fDtorOnly; //call only dtor and not delete when calling ~xxx
66  EReturnType fRetType; //method return type
67 
68  void Execute(const char *, const char *, int * /*error*/ = 0) { } // versions of TObject
69  void Execute(TMethod *, TObjArray *, int * /*error*/ = 0) { }
70 
71  void InitImplementation(const char *methodname, const char *params, const char *proto, Bool_t objectIsConst, TClass *cl, const ClassInfo_t *cinfo, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
72 
73 public:
74  TMethodCall();
75  TMethodCall(TClass *cl, CallFunc_t *callfunc, Long_t offset = 0);
76  TMethodCall(TClass *cl, const char *method, const char *params);
77  TMethodCall(const char *function, const char *params);
78  TMethodCall(const TFunction *func);
79  TMethodCall(const TMethodCall &org);
80  TMethodCall& operator=(const TMethodCall &rhs);
81  ~TMethodCall();
82 
83  void Init(const TFunction *func);
84  void Init(TClass *cl, CallFunc_t *func, Long_t offset = 0);
85  void Init(TClass *cl, const char *method, const char *params, Bool_t objectIsConst = kFALSE);
86  void Init(const char *function, const char *params);
87  void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst = kFALSE, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
88  void InitWithPrototype(const char *function, const char *proto, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
89  Bool_t IsValid() const;
90  TObject *Clone(const char *newname="") const;
91  void CallDtorOnly(Bool_t set = kTRUE) { fDtorOnly = set; }
92 
94  const char *GetMethodName() const { return fMethod.Data(); }
95  const char *GetParams() const { return fParams.Data(); }
96  const char *GetProto() const { return fProto.Data(); }
97  CallFunc_t *GetCallFunc() const { return fFunc; }
99 
100  void SetParamPtrs(void *paramArr, Int_t nparam = -1);
101  void ResetParam();
102  void SetParam(Long_t l);
103  void SetParam(Float_t f);
104  void SetParam(Double_t d);
105  void SetParam(Long64_t ll);
106  void SetParam(ULong64_t ull);
107 
108  template <typename... T> void SetParams(const T&... params) {
109  if (!fFunc) return;
110  gInterpreter->CallFunc_SetArguments(fFunc,params...);
111  }
112 
113  void Execute(void *object);
114  void Execute(void *object, const char *params);
115  void Execute(void *object, Long_t &retLong);
116  void Execute(void *object, const char *params, Long_t &retLong);
117  void Execute(void *object, Double_t &retDouble);
118  void Execute(void *object, const char *params, Double_t &retDouble);
119 
120  void Execute(void *object, char **retText);
121  void Execute(void *object, const char *params, char **retText);
122 
123  void Execute();
124  void Execute(const char *params);
125  void Execute(Long_t &retLong);
126  void Execute(const char *params, Long_t &retLong);
127  void Execute(Double_t &retDouble);
128  void Execute(const char *params, Double_t &retDouble);
129 
130  void Execute(void *objAddress, const void* args[], int nargs, void *ret = 0);
131 
132  ClassDef(TMethodCall,0) //Method calling interface
133 };
134 
135 inline void TMethodCall::Execute()
136  { Execute((void *)0); }
137 inline void TMethodCall::Execute(const char *params)
138  { Execute((void *)0, params); }
139 inline void TMethodCall::Execute(Long_t &retLong)
140  { Execute((void *)0, retLong); }
141 inline void TMethodCall::Execute(const char *params, Long_t &retLong)
142  { Execute((void *)0, params, retLong); }
143 inline void TMethodCall::Execute(Double_t &retDouble)
144  { Execute((void *)0, retDouble); }
145 inline void TMethodCall::Execute(const char *params, Double_t &retDouble)
146  { Execute((void *)0, params, retDouble); }
147 
148 #endif
TString fMethod
Definition: TMethodCall.h:62
An array of TObjects.
Definition: TObjArray.h:39
long long Long64_t
Definition: RtypesCore.h:69
float Float_t
Definition: RtypesCore.h:53
void Execute(TMethod *, TObjArray *, int *=0)
Execute method on this object with parameters stored in the TObjArray.
Definition: TMethodCall.h:69
static const EReturnType kOther
Definition: TMethodCall.h:50
tuple offset
Definition: tree.py:93
const char * GetParams() const
Definition: TMethodCall.h:95
CallFunc_t * fFunc
Definition: TMethodCall.h:58
CallFunc_t * GetCallFunc() const
Definition: TMethodCall.h:97
static const EReturnType kLong
Definition: TMethodCall.h:47
Basic string class.
Definition: TString.h:137
Long_t fOffset
Definition: TMethodCall.h:59
EReturnType fRetType
Definition: TMethodCall.h:66
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
#define gInterpreter
Definition: TInterpreter.h:502
const char * GetMethodName() const
Definition: TMethodCall.h:94
TFile * f
static const EReturnType kString
Definition: TMethodCall.h:49
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
TTree * T
const char * Data() const
Definition: TString.h:349
#define ClassDef(name, id)
Definition: Rtypes.h:254
TFunction * fMetPtr
Definition: TMethodCall.h:61
int d
Definition: tornado.py:11
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
~TMethodCall()
TMethodCall dtor.
EFunctionMatchMode
Definition: TDictionary.h:155
static const EReturnType kDouble
Definition: TMethodCall.h:48
Method or function calling interface.
Definition: TMethodCall.h:41
TString fParams
Definition: TMethodCall.h:63
TLine * l
Definition: textangle.C:4
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
static const EReturnType kNoReturnType
Definition: TMethodCall.h:51
void Execute()
Definition: TMethodCall.h:135
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
Bool_t fDtorOnly
Definition: TMethodCall.h:65
long Long_t
Definition: RtypesCore.h:50
TFunction * GetMethod()
Returns the TMethod describing the method to be executed.
void ResetParam()
Reset parameter list. To be used before the first call the SetParam().
double Double_t
Definition: RtypesCore.h:55
unsigned long long ULong64_t
Definition: RtypesCore.h:70
double func(double *x, double *p)
Definition: stressTF1.cxx:213
TObject * Clone(const char *newname="") const
Return an exact copy of this object.
#define org(otri, vertexptr)
Definition: triangle.c:1037
Mother of all ROOT objects.
Definition: TObject.h:58
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:30
TInterpreter::EReturnType EReturnType
Definition: TMethodCall.h:44
void CallDtorOnly(Bool_t set=kTRUE)
Definition: TMethodCall.h:91
TString fProto
Definition: TMethodCall.h:64
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:68
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
void SetParam(Long_t l)
Add a long method parameter.
void SetParams(const T &...params)
Definition: TMethodCall.h:108
void InitImplementation(const char *methodname, const char *params, const char *proto, Bool_t objectIsConst, TClass *cl, const ClassInfo_t *cinfo, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
This function implements Init and InitWithPrototype.
static const EReturnType kNone
Definition: TMethodCall.h:53
TMethodCall & operator=(const TMethodCall &rhs)
Assignment operator.
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
TClass * fClass
Definition: TMethodCall.h:60
EReturnType ReturnType()
Returns the return type of the method.
const char * GetProto() const
Definition: TMethodCall.h:96