45 #define G4AnyMethod_h 1
54 virtual const char*
what()
const throw() {
55 return "G4BadArgument: failed operator()";
59 #if defined(G4USE_STD11) || defined(G4USE_STD14)
60 #include <type_traits>
61 using std::remove_reference;
62 using std::remove_const;
75 template<
typename T>
struct remove_const<
const T> {
typedef T
type;};
87 fContent =
new FuncRef<S,T>(f);
89 template <
class S,
class T,
class A0>
G4AnyMethod(
S (T::*f)(A0)) : narg(1) {
90 fContent =
new FuncRef1<S,T,A0>(f);
92 template <
class S,
class T,
class A0,
class A1>
G4AnyMethod(
S (T::*f)(A0,A1)) : narg(2) {
93 fContent =
new FuncRef2<S,T,A0,A1>(f);
96 fContent(other.fContent ? other.fContent->Clone() : 0),narg(other.narg) {}
103 std::swap(fContent, rhs.fContent);
104 std::swap(narg, rhs.narg);
135 fContent->operator()(obj);
138 fContent->operator()(obj,
a0);
141 size_t NArg()
const {
return narg; }
143 const std::type_info&
ArgType(
size_t n = 0)
const {
144 return fContent ? fContent->ArgType(
n) :
typeid(
void);
151 virtual ~Placeholder() {}
152 virtual Placeholder* Clone()
const = 0;
154 virtual void operator()(
void*,
const std::string&) = 0;
155 virtual const std::type_info&
ArgType(
size_t)
const = 0;
158 template <
class S,
class T>
struct FuncRef:
public Placeholder {
159 FuncRef(
S (T::*f)()) : fRef(f) {}
164 virtual void operator()(
void*,
const std::string&) {
167 virtual Placeholder* Clone()
const {
168 return new FuncRef(fRef);
170 virtual const std::type_info&
ArgType(
size_t)
const {
176 template <
class S,
class T,
class A0>
struct FuncRef1:
public Placeholder {
177 typedef typename remove_const<typename remove_reference<A0>::type>::type nakedA0;
179 FuncRef1(
S (T::*f)(A0)) : fRef(f) {}
184 virtual void operator()(
void* obj,
const std::string&
s0) {
186 std::stringstream strs(s0);
188 ((T*)obj->*fRef)(
a0);
190 virtual Placeholder* Clone()
const {
191 return new FuncRef1(fRef);
193 virtual const std::type_info&
ArgType(
size_t)
const {
199 template <
class S,
class T,
class A0,
class A1>
struct FuncRef2:
public Placeholder {
200 typedef typename remove_const<typename remove_reference<A0>::type>::type nakedA0;
201 typedef typename remove_const<typename remove_reference<A1>::type>::type nakedA1;
203 FuncRef2(
S (T::*f)(A0, A1)) : fRef(f) {}
208 virtual void operator()(
void* obj,
const std::string&
s0) {
211 std::stringstream strs(s0);
213 ((T*)obj->*fRef)(
a0, a1);
215 virtual Placeholder* Clone()
const {
216 return new FuncRef2(fRef);
218 virtual const std::type_info&
ArgType(
size_t i)
const {
219 return i == 0 ?
typeid(A0) :
typeid(A1);
221 S (T::*fRef)(A0, A1);
224 Placeholder* fContent;
G4AnyMethod(S(T::*f)(A0))
G4AnyMethod(const G4AnyMethod &other)
G4AnyMethod(S(T::*f)(A0, A1))
G4AnyMethod & operator=(S(T::*f)())
const G4ThreeVector const G4double const
G4AnyMethod & Swap(G4AnyMethod &rhs)
void operator()(void *obj)
const std::type_info & ArgType(size_t n=0) const
virtual const char * what() const
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
void operator()(void *obj, const std::string &a0)