45 #define G4AnyMethod_h 1
54 virtual const char*
what()
const throw() {
55 return "G4BadArgument: failed operator()";
72 fContent =
new FuncRef<S,T>(
f);
74 template <
class S,
class T,
class A0>
G4AnyMethod(S (T::*f)(A0)) : narg(1) {
75 fContent =
new FuncRef1<S,T,A0>(
f);
77 template <
class S,
class T,
class A0,
class A1>
G4AnyMethod(S (T::*f)(A0,A1)) : narg(2) {
78 fContent =
new FuncRef2<S,T,A0,A1>(
f);
81 fContent(other.fContent ? other.fContent->Clone() : 0),narg(other.narg) {}
120 fContent->operator()(obj);
123 fContent->operator()(obj, a0);
126 size_t NArg()
const {
return narg; }
128 const std::type_info&
ArgType(
size_t n = 0)
const {
129 return fContent ? fContent->ArgType(
n) :
typeid(
void);
136 virtual ~Placeholder() {}
137 virtual Placeholder* Clone()
const = 0;
139 virtual void operator()(
void*,
const std::string&) = 0;
140 virtual const std::type_info&
ArgType(
size_t)
const = 0;
143 template <
class S,
class T>
struct FuncRef:
public Placeholder {
144 FuncRef(S (T::*f)()) : fRef(f) {}
149 virtual void operator()(
void*,
const std::string&) {
152 virtual Placeholder* Clone()
const {
153 return new FuncRef(fRef);
155 virtual const std::type_info&
ArgType(
size_t)
const {
161 template <
class S,
class T,
class A0>
struct FuncRef1:
public Placeholder {
164 FuncRef1(S (T::*f)(A0)) : fRef(f) {}
169 virtual void operator()(
void* obj,
const std::string&
s0) {
171 std::stringstream strs(s0);
173 ((T*)obj->*fRef)(a0);
175 virtual Placeholder* Clone()
const {
176 return new FuncRef1(fRef);
178 virtual const std::type_info&
ArgType(
size_t)
const {
184 template <
class S,
class T,
class A0,
class A1>
struct FuncRef2:
public Placeholder {
188 FuncRef2(S (T::*f)(A0, A1)) : fRef(f) {}
193 virtual void operator()(
void* obj,
const std::string&
s0) {
196 std::stringstream strs(s0);
198 ((T*)obj->*fRef)(a0, a1);
200 virtual Placeholder* Clone()
const {
201 return new FuncRef2(fRef);
203 virtual const std::type_info&
ArgType(
size_t i)
const {
204 return i == 0 ?
typeid(A0) :
typeid(A1);
206 S (T::*fRef)(A0, A1);
209 Placeholder* fContent;