48#define G4AnyMethod_hh 1
57 const char*
what()
const throw()
override
59 return "G4BadArgument: failed operator()";
64using std::remove_const;
65using std::remove_reference;
75 template <
class S,
class T>
78 fContent =
new FuncRef<S, T>(f);
81 template <
class S,
class T,
class A0>
85 fContent =
new FuncRef1<S, T, A0>(f);
88 template <
class S,
class T,
class A0,
class A1>
92 fContent =
new FuncRef2<S, T, A0, A1>(f);
96 : fContent(other.fContent != nullptr ? other.fContent->Clone() : nullptr)
106 std::swap(fContent, rhs.fContent);
107 std::swap(narg, rhs.narg);
113 template <
class S,
class T>
121 template <
class S,
class T,
class A0>
128 template <
class S,
class T,
class A0,
class A1>
152 fContent->operator()(obj,
a0);
157 std::size_t
NArg()
const {
return narg; }
159 const std::type_info&
ArgType(
size_t n = 0)
const
161 return fContent !=
nullptr ? fContent->ArgType(n) :
typeid(void);
169 Placeholder() =
default;
170 virtual ~Placeholder() =
default;
171 virtual Placeholder* Clone()
const = 0;
172 virtual void operator()(
void*) = 0;
173 virtual void operator()(
void*,
const std::string&) = 0;
174 virtual const std::type_info& ArgType(
size_t)
const = 0;
177 template <
class S,
class T>
178 struct FuncRef :
public Placeholder
184 void operator()(
void* obj)
override { ((T*) obj->*fRef)(); }
185 void operator()(
void*,
const std::string&)
override
189 Placeholder* Clone()
const override {
return new FuncRef(fRef); }
190 const std::type_info& ArgType(std::size_t)
const override
197 template <
class S,
class T,
class A0>
198 struct FuncRef1 :
public Placeholder
201 typename remove_const<typename remove_reference<A0>::type>::type;
203 FuncRef1(
S (T::*f)(A0))
208 void operator()(
void* obj,
const std::string& s0)
override
211 std::stringstream strs(s0);
213 ((T*) obj->*fRef)(
a0);
215 Placeholder* Clone()
const override {
return new FuncRef1(fRef); }
216 const std::type_info& ArgType(
size_t)
const override
223 template <
class S,
class T,
class A0,
class A1>
224 struct FuncRef2 :
public Placeholder
227 typename remove_const<typename remove_reference<A0>::type>::type;
229 typename remove_const<typename remove_reference<A1>::type>::type;
231 FuncRef2(
S (T::*f)(A0, A1))
236 void operator()(
void* obj,
const std::string& s0)
override
240 std::stringstream strs(s0);
242 ((T*) obj->*fRef)(
a0, a1);
244 Placeholder* Clone()
const override {
return new FuncRef2(fRef); }
245 const std::type_info& ArgType(
size_t i)
const override
247 return i == 0 ?
typeid(A0) :
typeid(A1);
249 S (T::*fRef)(A0, A1);
252 Placeholder* fContent =
nullptr;
253 std::size_t narg = 0;
G4double S(G4double temp)
G4AnyMethod(S(T::*f)(A0, A1))
G4AnyMethod & Swap(G4AnyMethod &rhs)
void operator()(void *obj)
const std::type_info & ArgType(size_t n=0) const
G4AnyMethod & operator=(S(T::*f)(A0, A1))
G4AnyMethod(S(T::*f)(A0))
G4AnyMethod(const G4AnyMethod &other)
G4AnyMethod & operator=(const G4AnyMethod &rhs)
G4AnyMethod & operator=(S(T::*f)(A0))
void operator()(void *obj, const std::string &a0)
G4AnyMethod & operator=(S(T::*f)())
const char * what() const override