Logo ROOT  
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 "TObject.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
l
auto * l
Definition: textangle.C:4
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMethodCall::SetParam
void SetParam(Long_t l)
Add a long method parameter.
Definition: TMethodCall.cxx:603
TMethodCall::Execute
void Execute(TMethod *, TObjArray *, int *=0)
Execute method on this object with parameters stored in the TObjArray.
Definition: TMethodCall.h:65
TObjArray
An array of TObjects.
Definition: TObjArray.h:37
TMethodCall::ReturnType
EReturnType ReturnType()
Returns the return type of the method.
Definition: TMethodCall.cxx:562
f
#define f(i)
Definition: RSha256.hxx:104
TMethodCall::fClass
TClass * fClass
Definition: TMethodCall.h:56
ROOT::kConversionMatch
@ kConversionMatch
Definition: TDictionary.h:162
TMethodCall::kString
static const EReturnType kString
Definition: TMethodCall.h:45
TString::Data
const char * Data() const
Definition: TString.h:369
TMethodCall::fOffset
Long_t fOffset
Definition: TMethodCall.h:55
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TMethodCall::TMethodCall
TMethodCall()
Default TMethodCall ctor.
Definition: TMethodCall.cxx:37
gInterpreter
#define gInterpreter
Definition: TInterpreter.h:560
Float_t
float Float_t
Definition: RtypesCore.h:57
TMethodCall::fFunc
CallFunc_t * fFunc
Definition: TMethodCall.h:54
Int_t
int Int_t
Definition: RtypesCore.h:45
TMethodCall::kOther
static const EReturnType kOther
Definition: TMethodCall.h:46
TMethodCall::Init
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
Definition: TMethodCall.cxx:223
TMethodCall::GetCallFunc
CallFunc_t * GetCallFunc() const
Definition: TMethodCall.h:93
TMethodCall::kDouble
static const EReturnType kDouble
Definition: TMethodCall.h:44
TMethodCall::~TMethodCall
~TMethodCall()
TMethodCall dtor.
Definition: TMethodCall.cxx:127
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
bool
TMethodCall::SetParamPtrs
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
Definition: TMethodCall.cxx:585
TMethodCall::kLong
static const EReturnType kLong
Definition: TMethodCall.h:43
TInterpreter::EReturnType::kDouble
@ kDouble
TMethodCall::fMetPtr
TFunction * fMetPtr
Definition: TMethodCall.h:57
TMethodCall::fRetType
EReturnType fRetType
Definition: TMethodCall.h:62
TMethodCall::GetMethodName
const char * GetMethodName() const
Definition: TMethodCall.h:90
TInterpreter::EReturnType::kOther
@ kOther
TMethodCall::fParams
TString fParams
Definition: TMethodCall.h:59
TMethodCall::fDtorOnly
Bool_t fDtorOnly
Definition: TMethodCall.h:61
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMethodCall::IsValid
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
Definition: TMethodCall.cxx:373
TMethod
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
Long_t
long Long_t
Definition: RtypesCore.h:54
TMethodCall::GetProto
const char * GetProto() const
Definition: TMethodCall.h:92
TInterpreter::EReturnType::kLong
@ kLong
org
#define org(otri, vertexptr)
Definition: triangle.c:1037
TMethodCall::SetParams
void SetParams(const T &... params)
Definition: TMethodCall.h:104
TMethodCall::fProto
TString fProto
Definition: TMethodCall.h:60
TMethodCall::GetParams
const char * GetParams() const
Definition: TMethodCall.h:91
TMethodCall::ResetParam
void ResetParam()
Reset parameter list. To be used before the first call the SetParam().
Definition: TMethodCall.cxx:594
TMethodCall::Execute
void Execute()
Definition: TMethodCall.h:131
TMethodCall::Clone
TObject * Clone(const char *newname="") const
Return an exact copy of this object.
Definition: TMethodCall.cxx:136
TMethodCall::GetMethod
TFunction * GetMethod()
Returns the TMethod describing the method to be executed.
Definition: TMethodCall.cxx:383
ROOT::EFunctionMatchMode
EFunctionMatchMode
Definition: TDictionary.h:160
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
proto
const char * proto
Definition: civetweb.c:16604
TMethodCall::InitWithPrototype
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
Definition: TMethodCall.cxx:339
Double_t
double Double_t
Definition: RtypesCore.h:59
TMethodCall::EReturnType
TInterpreter::EReturnType EReturnType
Definition: TMethodCall.h:40
TObject.h
TMethodCall::Execute
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
TInterpreter.h
TClass
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
TInterpreter::EReturnType::kNoReturnType
@ kNoReturnType
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
TMethodCall::kNoReturnType
static const EReturnType kNoReturnType
Definition: TMethodCall.h:47
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMethodCall::CallDtorOnly
void CallDtorOnly(Bool_t set=kTRUE)
Definition: TMethodCall.h:87
ROOT::Math::Chebyshev::T
double T(double x)
Definition: ChebyshevPol.h:34
d
#define d(i)
Definition: RSha256.hxx:102
TMethodCall
Method or function calling interface.
Definition: TMethodCall.h:37
TMethodCall::InitImplementation
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.
Definition: TMethodCall.cxx:293
TInterpreter::EReturnType::kString
@ kString
TMethodCall::kNone
static const EReturnType kNone
Definition: TMethodCall.h:49
TInterpreter::EReturnType
EReturnType
Definition: TInterpreter.h:84
TFunction
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:30
TMethodCall::fMethod
TString fMethod
Definition: TMethodCall.h:58
TMethodCall::operator=
TMethodCall & operator=(const TMethodCall &rhs)
Assignment operator.
Definition: TMethodCall.cxx:104