31 ClassImp(TMethodCall);
37 TMethodCall::TMethodCall():
38 fFunc(0), fOffset(0), fClass(0), fMetPtr(0), fDtorOnly(kFALSE), fRetType(kNone)
46 TMethodCall::TMethodCall(TClass *cl, CallFunc_t *callfunc, Long_t offset):
47 fFunc(0), fOffset(0), fClass(0), fMetPtr(0), fDtorOnly(kFALSE), fRetType(kNone)
49 Init(cl, callfunc, offset);
59 TMethodCall::TMethodCall(TClass *cl,
const char *method,
const char *params):
60 fFunc(0), fOffset(0), fClass(0), fMetPtr(0), fDtorOnly(kFALSE), fRetType(kNone)
62 Init(cl, method, params);
72 TMethodCall::TMethodCall(
const char *
function,
const char *params):
73 fFunc(0), fOffset(0), fClass(0), fMetPtr(0), fDtorOnly(kFALSE), fRetType(kNone)
75 Init(
function, params);
84 TMethodCall::TMethodCall(
const TFunction *func):
85 fFunc(0), fOffset(0), fClass(0), fMetPtr(0), fDtorOnly(kFALSE), fRetType(kNone)
92 TMethodCall::TMethodCall(
const TMethodCall &orig) :
94 fFunc(orig.fFunc ? gCling->CallFunc_FactoryCopy(orig.fFunc) : 0),
95 fOffset(orig.fOffset), fClass(orig.fClass), fMetPtr(0 ),
96 fMethod(orig.fMethod), fParams(orig.fParams), fProto(orig.fProto),
97 fDtorOnly(orig.fDtorOnly), fRetType(orig.fRetType)
104 TMethodCall &TMethodCall::operator=(
const TMethodCall &rhs)
107 gCling->CallFunc_Delete(fFunc);
108 fFunc = rhs.fFunc ? gCling->CallFunc_FactoryCopy(rhs.fFunc) : 0;
109 fOffset = rhs.fOffset;
111 fMethod = rhs.fMethod;
112 fParams = rhs.fParams;
114 fDtorOnly = rhs.fDtorOnly;
115 fRetType = rhs.fRetType;
127 TMethodCall::~TMethodCall()
129 gCling->CallFunc_Delete(fFunc);
136 TObject *TMethodCall::Clone(
const char *)
const
138 TObject *newobj =
new TMethodCall(*
this);
146 static TClass *R__FindScope(
const char *
function, UInt_t &pos, ClassInfo_t *cinfo)
155 for(
int i=strlen(
function); i>=0; --i) {
156 switch(
function[i]) {
157 case '<': ++nested;
break;
158 case '>':
if (nested==0) { Error(
"TMethodCall R__FindScope",
"%s is not well formed function name",
function);
return 0; }
162 if (i>1 &&
function[i-1]==
':') {
163 TString scope(
function);
166 TClass *cl = TClass::GetClass(scope);
167 if (!cl) gCling->ClassInfo_Init(cinfo, scope);
182 void TMethodCall::Init(TClass *cl, CallFunc_t *
function, Long_t offset)
191 MethodInfo_t* info = gCling->CallFunc_FactoryMethod(
function);
194 fFunc = gCling->CallFunc_Factory();
196 gCling->CallFunc_Init(fFunc);
200 fMetPtr =
new TMethod(info,cl);
202 fMetPtr =
new TFunction(info);
204 fMethod = fMetPtr->GetName();
206 fProto = fMetPtr->GetSignature()+1;
207 Ssiz_t s = fProto.Last(
')');
215 gCling->CallFunc_SetFunc(fFunc,info);
223 void TMethodCall::Init(
const TFunction *
function)
225 if (!
function)
return;
228 fFunc = gCling->CallFunc_Factory();
230 gCling->CallFunc_Init(fFunc);
232 const TMethod *m =
dynamic_cast<const TMethod*
>(
function);
233 fClass = m ? m->GetClass() : 0;
234 fMetPtr = (TFunction*)function->Clone();
235 fMethod = fMetPtr->GetName();
237 fProto = fMetPtr->GetSignature()+1;
238 Ssiz_t s = fProto.Last(
')');
244 gCling->CallFunc_SetFunc(fFunc,function->fInfo);
257 void TMethodCall::Init(TClass *cl,
const char *method,
const char *params, Bool_t objectIsConst )
259 ClassInfo_t *cinfo = gCling->ClassInfo_Factory();
262 cl = R__FindScope(method,pos,cinfo);
265 InitImplementation(method,params,0,objectIsConst,cl,cinfo);
266 gCling->ClassInfo_Delete(cinfo);
278 void TMethodCall::Init(
const char *
function,
const char *params)
281 ClassInfo_t *cinfo = gCling->ClassInfo_Factory();
282 TClass *cl = R__FindScope(
function,pos,cinfo);
283 InitImplementation(
function+pos, params, 0,
false, cl, cinfo);
284 gCling->ClassInfo_Delete(cinfo);
293 void TMethodCall::InitImplementation(
const char *methodname,
const char *params,
295 Bool_t objectIsConst, TClass *cl,
296 const ClassInfo_t *cinfo,
297 ROOT::EFunctionMatchMode mode )
300 R__LOCKGUARD(gInterpreterMutex);
301 fFunc = gCling->CallFunc_Factory();
303 gCling->CallFunc_Init(fFunc);
307 fMethod = methodname;
308 fParams = params ? params :
"";
309 fProto = proto ? proto :
"";
313 ClassInfo_t *scope = 0;
314 if (cl) scope = (ClassInfo_t*)cl->GetClassInfo();
315 else scope = (ClassInfo_t*)cinfo;
319 R__LOCKGUARD(gInterpreterMutex);
320 if (params && params[0]) {
321 gCling->CallFunc_SetFunc(fFunc, scope, (
char *)methodname, (
char *)params, objectIsConst, &fOffset);
322 }
else if (proto && proto[0]) {
323 gCling->CallFunc_SetFuncProto(fFunc, scope, (
char *)methodname, (
char *)proto, objectIsConst, &fOffset, mode);
326 gCling->CallFunc_SetFuncProto(fFunc, scope, (
char *)methodname,
"", objectIsConst, &fOffset, mode);
339 void TMethodCall::InitWithPrototype(TClass *cl,
const char *method,
const char *proto, Bool_t objectIsConst , ROOT::EFunctionMatchMode mode )
341 ClassInfo_t *cinfo = gCling->ClassInfo_Factory();
344 cl = R__FindScope(method,pos,cinfo);
347 InitImplementation(method, 0, proto, objectIsConst, cl, cinfo, mode);
348 gCling->ClassInfo_Delete(cinfo);
360 void TMethodCall::InitWithPrototype(
const char *
function,
const char *proto, ROOT::EFunctionMatchMode mode )
363 ClassInfo_t *cinfo = gCling->ClassInfo_Factory();
364 TClass *cl = R__FindScope(
function,pos,cinfo);
365 InitImplementation(
function+pos, 0, proto,
false, cl, cinfo, mode);
366 gCling->ClassInfo_Delete(cinfo);
373 Bool_t TMethodCall::IsValid()
const
375 return fFunc ? gCling->CallFunc_IsValid(fFunc) : kFALSE;
383 TFunction *TMethodCall::GetMethod()
389 if (fFunc && gCling->CallFunc_IsValid(fFunc)) {
391 fMetPtr =
new TMethod( gCling->CallFunc_FactoryMethod(fFunc), fClass );
393 fMetPtr =
new TFunction( gCling->CallFunc_FactoryMethod(fFunc) );
397 fMetPtr = fClass->GetMethod(fMethod.Data(), fParams.Data());
399 fMetPtr = fClass->GetMethodWithPrototype(fMethod.Data(), fProto.Data());
401 TMethod *met =
dynamic_cast<TMethod*
>(fMetPtr);
402 if (met) fMetPtr =
new TMethod(*met);
405 fMetPtr = gROOT->GetGlobalFunction(fMethod.Data(), fParams.Data(), kFALSE);
407 fMetPtr = gROOT->GetGlobalFunctionWithPrototype(fMethod.Data(), fProto.Data(), kFALSE);
408 if (fMetPtr) fMetPtr =
new TFunction(*fMetPtr);
418 void TMethodCall::Execute(
void *
object)
423 if (
object) address = (
void*)((Long_t)
object + fOffset);
424 if (!fDtorOnly && fMethod[0]==
'~') {
425 Error(
"Execute",
"TMethodCall can no longer be use to call the operator delete and the destructor at the same time");
427 gCling->CallFunc_Exec(fFunc,address);
433 void TMethodCall::Execute(
void *
object,
const char *params)
438 gCling->CallFunc_SetArgs(fFunc, (
char *)params);
441 if (
object) address = (
void*)((Long_t)
object + fOffset);
442 gCling->SetTempLevel(1);
443 gCling->CallFunc_Exec(fFunc,address);
444 gCling->SetTempLevel(-1);
450 void TMethodCall::Execute(
void *
object, Long_t &retLong)
455 if (
object) address = (
void*)((Long_t)
object + fOffset);
456 gCling->SetTempLevel(1);
457 retLong = gCling->CallFunc_ExecInt(fFunc,address);
458 gCling->SetTempLevel(-1);
464 void TMethodCall::Execute(
void *
object,
const char *params, Long_t &retLong)
469 gCling->CallFunc_SetArgs(fFunc, (
char *)params);
472 if (
object) address = (
void*)((Long_t)
object + fOffset);
473 gCling->SetTempLevel(1);
474 retLong = gCling->CallFunc_ExecInt(fFunc,address);
475 gCling->SetTempLevel(-1);
481 void TMethodCall::Execute(
void *
object, Double_t &retDouble)
486 if (
object) address = (
void*)((Long_t)
object + fOffset);
487 gCling->SetTempLevel(1);
488 retDouble = gCling->CallFunc_ExecDouble(fFunc,address);
489 gCling->SetTempLevel(-1);
495 void TMethodCall::Execute(
void *
object,
const char *params, Double_t &retDouble)
499 gCling->CallFunc_SetArgs(fFunc, (
char *)params);
502 if (
object) address = (
void*)((Long_t)
object + fOffset);
503 gCling->SetTempLevel(1);
504 retDouble = gCling->CallFunc_ExecDouble(fFunc,address);
505 gCling->SetTempLevel(-1);
511 void TMethodCall::Execute(
void *
object,
char **retText)
516 if (
object) address = (
void*)((Long_t)
object + fOffset);
517 gCling->SetTempLevel(1);
518 *retText =(
char*) (gCling->CallFunc_ExecInt(fFunc,address));
519 gCling->SetTempLevel(-1);
525 void TMethodCall::Execute(
void *
object,
const char *params,
char **retText)
530 gCling->CallFunc_SetArgs(fFunc, (
char *)params);
533 if (
object) address = (
void*)((Long_t)
object + fOffset);
534 gCling->SetTempLevel(1);
535 *retText =(
char*)(gCling->CallFunc_ExecInt(fFunc,address));
536 gCling->SetTempLevel(-1);
549 void TMethodCall::Execute(
void *objAddress,
const void* args[],
int nargs,
void *ret )
553 gCling->CallFunc_ExecWithArgsAndReturn(fFunc,objAddress,args,nargs,ret);
562 TMethodCall::EReturnType TMethodCall::ReturnType()
564 if ( fRetType == kNone) {
565 TFunction *func = GetMethod();
568 Error(
"ReturnType",
"Unknown method");
572 fRetType = gCling->MethodCallReturnType(func);
585 void TMethodCall::SetParamPtrs(
void *paramArr, Int_t nparam)
588 gCling->CallFunc_SetArgArray(fFunc,(Long_t *)paramArr, nparam);
594 void TMethodCall::ResetParam()
597 gCling->CallFunc_ResetArg(fFunc);
603 void TMethodCall::SetParam(Long_t l)
606 gCling->CallFunc_SetArg(fFunc,l);
612 void TMethodCall::SetParam(Float_t f)
615 gCling->CallFunc_SetArg(fFunc,f);
621 void TMethodCall::SetParam(Double_t d)
624 gCling->CallFunc_SetArg(fFunc,d);
630 void TMethodCall::SetParam(Long64_t ll)
633 gCling->CallFunc_SetArg(fFunc,ll);
639 void TMethodCall::SetParam(ULong64_t ull)
642 gCling->CallFunc_SetArg(fFunc,ull);