Logo ROOT   6.12/07
Reference Guide
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 #include "TDictionary.h"
31 
32 #include "TInterpreter.h"
33 
34 class TClass;
35 class TFunction;
36 
37 class TMethodCall : public TObject {
38 
39 public:
41 
42  // For backward compatibility:
48  // Historical name.
50 
51  // enum EReturnType { kLong, kDouble, kString, kOther, kNone };
52 
53 private:
54  CallFunc_t *fFunc; //CINT method invocation environment
55  Long_t fOffset; //offset added to object pointer before method invocation
56  TClass *fClass; //pointer to the class info
57  TFunction *fMetPtr; //pointer to the method or function info
58  TString fMethod; //method name
59  TString fParams; //argument string
60  TString fProto; //prototype string
61  Bool_t fDtorOnly; //call only dtor and not delete when calling ~xxx
62  EReturnType fRetType; //method return type
63 
64  void Execute(const char *, const char *, int * /*error*/ = 0) { } // versions of TObject
65  void Execute(TMethod *, TObjArray *, int * /*error*/ = 0) { }
66 
67  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);
68 
69 public:
70  TMethodCall();
71  TMethodCall(TClass *cl, CallFunc_t *callfunc, Long_t offset = 0);
72  TMethodCall(TClass *cl, const char *method, const char *params);
73  TMethodCall(const char *function, const char *params);
74  TMethodCall(const TFunction *func);
75  TMethodCall(const TMethodCall &org);
76  TMethodCall& operator=(const TMethodCall &rhs);
77  ~TMethodCall();
78 
79  void Init(const TFunction *func);
80  void Init(TClass *cl, CallFunc_t *func, Long_t offset = 0);
81  void Init(TClass *cl, const char *method, const char *params, Bool_t objectIsConst = kFALSE);
82  void Init(const char *function, const char *params);
83  void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst = kFALSE, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
84  void InitWithPrototype(const char *function, const char *proto, ROOT::EFunctionMatchMode mode = ROOT::kConversionMatch);
85  Bool_t IsValid() const;
86  TObject *Clone(const char *newname="") const;
87  void CallDtorOnly(Bool_t set = kTRUE) { fDtorOnly = set; }
88 
90  const char *GetMethodName() const { return fMethod.Data(); }
91  const char *GetParams() const { return fParams.Data(); }
92  const char *GetProto() const { return fProto.Data(); }
93  CallFunc_t *GetCallFunc() const { return fFunc; }
95 
96  void SetParamPtrs(void *paramArr, Int_t nparam = -1);
97  void ResetParam();
98  void SetParam(Long_t l);
99  void SetParam(Float_t f);
100  void SetParam(Double_t d);
101  void SetParam(Long64_t ll);
102  void SetParam(ULong64_t ull);
103 
104  template <typename... T> void SetParams(const T&... params) {
105  if (!fFunc) return;
106  gInterpreter->CallFunc_SetArguments(fFunc,params...);
107  }
108 
109  void Execute(void *object);
110  void Execute(void *object, const char *params);
111  void Execute(void *object, Long_t &retLong);
112  void Execute(void *object, const char *params, Long_t &retLong);
113  void Execute(void *object, Double_t &retDouble);
114  void Execute(void *object, const char *params, Double_t &retDouble);
115 
116  void Execute(void *object, char **retText);
117  void Execute(void *object, const char *params, char **retText);
118 
119  void Execute();
120  void Execute(const char *params);
121  void Execute(Long_t &retLong);
122  void Execute(const char *params, Long_t &retLong);
123  void Execute(Double_t &retDouble);
124  void Execute(const char *params, Double_t &retDouble);
125 
126  void Execute(void *objAddress, const void* args[], int nargs, void *ret = 0);
127 
128  ClassDef(TMethodCall,0) //Method calling interface
129 };
130 
131 inline void TMethodCall::Execute()
132  { Execute((void *)0); }
133 inline void TMethodCall::Execute(const char *params)
134  { Execute((void *)0, params); }
135 inline void TMethodCall::Execute(Long_t &retLong)
136  { Execute((void *)0, retLong); }
137 inline void TMethodCall::Execute(const char *params, Long_t &retLong)
138  { Execute((void *)0, params, retLong); }
139 inline void TMethodCall::Execute(Double_t &retDouble)
140  { Execute((void *)0, retDouble); }
141 inline void TMethodCall::Execute(const char *params, Double_t &retDouble)
142  { Execute((void *)0, params, retDouble); }
143 
144 #endif
TString fMethod
Definition: TMethodCall.h:58
An array of TObjects.
Definition: TObjArray.h:37
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:65
static const EReturnType kOther
Definition: TMethodCall.h:46
TMethodCall()
Default TMethodCall ctor.
Definition: TMethodCall.cxx:37
double T(double x)
Definition: ChebyshevPol.h:34
CallFunc_t * GetCallFunc() const
Definition: TMethodCall.h:93
CallFunc_t * fFunc
Definition: TMethodCall.h:54
static const EReturnType kLong
Definition: TMethodCall.h:43
Basic string class.
Definition: TString.h:125
Long_t fOffset
Definition: TMethodCall.h:55
EReturnType fRetType
Definition: TMethodCall.h:62
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
#define gInterpreter
Definition: TInterpreter.h:526
static const EReturnType kString
Definition: TMethodCall.h:45
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
#define ClassDef(name, id)
Definition: Rtypes.h:320
TFunction * fMetPtr
Definition: TMethodCall.h:57
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
~TMethodCall()
TMethodCall dtor.
EFunctionMatchMode
Definition: TDictionary.h:151
static const EReturnType kDouble
Definition: TMethodCall.h:44
Method or function calling interface.
Definition: TMethodCall.h:37
const char * GetMethodName() const
Definition: TMethodCall.h:90
TObject * Clone(const char *newname="") const
Return an exact copy of this object.
TString fParams
Definition: TMethodCall.h:59
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
const char * GetProto() const
Definition: TMethodCall.h:92
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
static const EReturnType kNoReturnType
Definition: TMethodCall.h:47
const char * GetParams() const
Definition: TMethodCall.h:91
void SetParams(const T &... params)
Definition: TMethodCall.h:104
void Execute()
Definition: TMethodCall.h:131
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
const Bool_t kFALSE
Definition: RtypesCore.h:88
Bool_t fDtorOnly
Definition: TMethodCall.h:61
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
#define org(otri, vertexptr)
Definition: triangle.c:1037
Mother of all ROOT objects.
Definition: TObject.h:37
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:28
void CallDtorOnly(Bool_t set=kTRUE)
Definition: TMethodCall.h:87
auto * l
Definition: textangle.C:4
TString fProto
Definition: TMethodCall.h:60
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
void SetParam(Long_t l)
Add a long method parameter.
const char * proto
Definition: civetweb.c:11652
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:49
TMethodCall & operator=(const TMethodCall &rhs)
Assignment operator.
const Bool_t kTRUE
Definition: RtypesCore.h:87
TClass * fClass
Definition: TMethodCall.h:56
EReturnType ReturnType()
Returns the return type of the method.
const char * Data() const
Definition: TString.h:345