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 "TDictionary.h"
31
32#include "TInterpreter.h"
33
34class TClass;
35class TFunction;
36
37class TMethodCall : public TObject {
38
39public:
41
42 // For backward compatibility:
48 // Historical name.
50
51 // enum EReturnType { kLong, kDouble, kString, kOther, kNone };
52
53private:
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
69public:
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);
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);
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
132 { Execute((void *)0); }
133inline void TMethodCall::Execute(const char *params)
134 { Execute((void *)0, params); }
135inline void TMethodCall::Execute(Long_t &retLong)
136 { Execute((void *)0, retLong); }
137inline void TMethodCall::Execute(const char *params, Long_t &retLong)
138 { Execute((void *)0, params, retLong); }
139inline void TMethodCall::Execute(Double_t &retDouble)
140 { Execute((void *)0, retDouble); }
141inline void TMethodCall::Execute(const char *params, Double_t &retDouble)
142 { Execute((void *)0, params, retDouble); }
143
144#endif
#define d(i)
Definition: RSha256.hxx:102
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
long long Long64_t
Definition: RtypesCore.h:69
unsigned long long ULong64_t
Definition: RtypesCore.h:70
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassDef(name, id)
Definition: Rtypes.h:326
#define gInterpreter
Definition: TInterpreter.h:555
const char * proto
Definition: civetweb.c:16604
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Global functions class (global functions are obtained from CINT).
Definition: TFunction.h:28
Method or function calling interface.
Definition: TMethodCall.h:37
EReturnType ReturnType()
Returns the return type of the method.
TMethodCall()
Default TMethodCall ctor.
Definition: TMethodCall.cxx:37
void CallDtorOnly(Bool_t set=kTRUE)
Definition: TMethodCall.h:87
TFunction * fMetPtr
Definition: TMethodCall.h:57
TMethodCall & operator=(const TMethodCall &rhs)
Assignment operator.
~TMethodCall()
TMethodCall dtor.
Bool_t fDtorOnly
Definition: TMethodCall.h:61
static const EReturnType kLong
Definition: TMethodCall.h:43
TString fParams
Definition: TMethodCall.h:59
const char * GetMethodName() const
Definition: TMethodCall.h:90
EReturnType fRetType
Definition: TMethodCall.h:62
static const EReturnType kNoReturnType
Definition: TMethodCall.h:47
static const EReturnType kString
Definition: TMethodCall.h:45
void ResetParam()
Reset parameter list. To be used before the first call the SetParam().
static const EReturnType kOther
Definition: TMethodCall.h:46
const char * GetParams() const
Definition: TMethodCall.h:91
CallFunc_t * GetCallFunc() const
Definition: TMethodCall.h:93
CallFunc_t * fFunc
Definition: TMethodCall.h:54
TClass * fClass
Definition: TMethodCall.h:56
TFunction * GetMethod()
Returns the TMethod describing the method to be executed.
const char * GetProto() const
Definition: TMethodCall.h:92
static const EReturnType kNone
Definition: TMethodCall.h:49
void Init(const TFunction *func)
Initialize the method invocation environment based on the TFunction object.
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.
TInterpreter::EReturnType EReturnType
Definition: TMethodCall.h:40
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
void SetParams(const T &... params)
Definition: TMethodCall.h:104
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
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
static const EReturnType kDouble
Definition: TMethodCall.h:44
void Execute()
Definition: TMethodCall.h:131
void SetParam(Long_t l)
Add a long method parameter.
void SetParamPtrs(void *paramArr, Int_t nparam=-1)
ParamArr is an array containing the function argument values.
Long_t fOffset
Definition: TMethodCall.h:55
TString fMethod
Definition: TMethodCall.h:58
TObject * Clone(const char *newname="") const
Return an exact copy of this object.
void Execute(TMethod *, TObjArray *, int *=0)
Execute method on this object with parameters stored in the TObjArray.
Definition: TMethodCall.h:65
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
An array of TObjects.
Definition: TObjArray.h:37
Mother of all ROOT objects.
Definition: TObject.h:37
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
double T(double x)
Definition: ChebyshevPol.h:34
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
EFunctionMatchMode
Definition: TDictionary.h:155
@ kConversionMatch
Definition: TDictionary.h:157
auto * l
Definition: textangle.C:4
#define org(otri, vertexptr)
Definition: triangle.c:1037