 |
DD4hep
1.32.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file.
13 #ifndef DD4HEP_CALLBACK_H
14 #define DD4HEP_CALLBACK_H
39 typedef unsigned long (*
func_t)(
void* obj,
const void* fun,
const void* args[]);
71 operator bool()
const {
75 unsigned long execute(
const void* user_param[])
const {
79 template <
typename T>
static T*
cast(
void* p) {
83 template <
typename T>
static const T*
c_cast(
const void* p) {
117 template <
typename T>
const Callback&
_make(
ulong (*fptr)(
void* o,
const void* f,
const void* u[]), T pmf) {
119 typename Wrapper<T>::Functor f(pmf);
125 template <
typename R,
typename T>
const Callback&
make(R (T::*pmf)()) {
126 typedef R (T::*pfunc_t)();
127 struct _Wrapper :
public Wrapper<pfunc_t> {
128 static ulong call(
void* o,
const void* f,
const void*[]) {
132 return _make(_Wrapper::call, pmf);
135 template <
typename R,
typename T>
const Callback&
make(R (T::*pmf)()
const) {
136 typedef R (T::*pfunc_t)()
const;
137 struct _Wrapper :
public Wrapper<pfunc_t> {
138 static ulong call(
void* o,
const void* f,
const void*[]) {
142 return _make(_Wrapper::call, pmf);
146 typedef void (T::*pfunc_t)()
const;
147 struct _Wrapper :
public Wrapper<pfunc_t> {
148 static ulong call(
void* o,
const void* f,
const void*[]) {
153 return _make(_Wrapper::call, pmf);
157 typedef void (T::*pfunc_t)()
const;
158 struct _Wrapper :
public Wrapper<pfunc_t> {
159 static ulong call(
void* o,
const void* f,
const void*[]) {
164 return _make(_Wrapper::call, pmf);
168 template <
typename R,
typename T,
typename A>
const Callback&
make(R (T::*pmf)(A)) {
170 typedef R (T::*pfunc_t)(A);
171 struct _Wrapper :
public Wrapper<pfunc_t> {
172 static ulong call(
void* o,
const void* f,
const void* u[]) {
173 return (
ulong) (cast<T>(o)->*(
typename Wrapper<pfunc_t>::Functor(f).pmf))((A) u[0]);
176 return _make(_Wrapper::call, pmf);
179 template <
typename R,
typename T,
typename A>
const Callback&
make(R (T::*pmf)(A)
const) {
180 typedef R (T::*pfunc_t)(A)
const;
181 struct _Wrapper :
public Wrapper<pfunc_t> {
182 static ulong call(
void* o,
const void* f,
const void* u[]) {
186 return _make(_Wrapper::call, pmf);
189 template <
typename T,
typename A>
const Callback&
make(
void (T::*pmf)(A)) {
190 typedef void (T::*pfunc_t)(
const A);
191 struct _Wrapper :
public Wrapper<pfunc_t> {
192 static ulong call(
void* o,
const void* f,
const void* u[]) {
197 return _make(_Wrapper::call, pmf);
200 template <
typename T,
typename A>
const Callback&
make(
void (T::*pmf)(A)
const) {
201 typedef void (T::*pfunc_t)(
const A)
const;
202 struct _Wrapper :
public Wrapper<pfunc_t> {
203 static ulong call(
void* o,
const void* f,
const void* u[]) {
208 return _make(_Wrapper::call, pmf);
213 template <
typename R,
typename T,
typename A0,
typename A1>
const Callback&
make(R (T::*pmf)(A0, A1)) {
215 typedef R (T::*pfunc_t)(A0, A1);
216 typedef Wrapper<pfunc_t> _W;
217 struct _Wrapper :
public _W {
218 static ulong call(
void* o,
const void* f,
const void* u[]) {
219 return (
ulong) (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1]);
222 return _make(_Wrapper::call, pmf);
225 template <
typename R,
typename T,
typename A0,
typename A1>
const Callback&
make(R (T::*pmf)(A0, A1)
const) {
226 typedef R (T::*pfunc_t)(A0, A1);
228 struct _Wrapper :
public _W {
229 static ulong call(
void* o,
const void* f,
const void* u[]) {
230 return (
ulong) (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1]);
233 return _make(_Wrapper::call, pmf);
236 template <
typename T,
typename A0,
typename A1>
const Callback&
make(
void (T::*pmf)(A0, A1)) {
237 typedef void (T::*pfunc_t)(A0, A1);
239 struct _Wrapper :
public _W {
240 static ulong call(
void* o,
const void* f,
const void* u[]) {
241 (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1]);
245 return _make(_Wrapper::call, pmf);
248 template <
typename T,
typename A0,
typename A1>
const Callback&
make(
void (T::*pmf)(A0, A1)
const) {
249 typedef void (T::*pfunc_t)(A0, A1);
251 struct _Wrapper :
public _W {
252 static ulong call(
void* o,
const void* f,
const void* u[]) {
253 (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1]);
257 return _make(_Wrapper::call, pmf);
262 template <
typename R,
typename T,
typename A0,
typename A1,
typename A2>
const Callback&
make(R (T::*pmf)(A0, A1, A2)) {
264 typedef R (T::*pfunc_t)(A0, A1, A2);
265 typedef Wrapper<pfunc_t> _W;
266 struct _Wrapper :
public _W {
267 static ulong call(
void* o,
const void* f,
const void* u[]) {
268 return (
ulong) (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1], (A2) u[2]);
271 return _make(_Wrapper::call, pmf);
274 template <
typename R,
typename T,
typename A0,
typename A1,
typename A2>
const Callback&
make(R (T::*pmf)(A0, A1, A2)
const) {
275 typedef R (T::*pfunc_t)(A0, A1, A2);
277 struct _Wrapper :
public _W {
278 static ulong call(
void* o,
const void* f,
const void* u[]) {
279 return (
ulong) (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1], (A2) u[2]);
282 return _make(_Wrapper::call, pmf);
285 template <
typename T,
typename A0,
typename A1,
typename A2>
const Callback&
make(
void (T::*pmf)(A0, A1, A2)) {
286 typedef void (T::*pfunc_t)(A0, A1, A2);
288 struct _Wrapper :
public _W {
289 static ulong call(
void* o,
const void* f,
const void* u[]) {
290 (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1], (A2) u[2]);
294 return _make(_Wrapper::call, pmf);
297 template <
typename T,
typename A0,
typename A1,
typename A2>
const Callback&
make(
void (T::*pmf)(A0, A1, A2)
const) {
298 typedef void (T::*pfunc_t)(A0, A1, A2);
300 struct _Wrapper :
public _W {
301 static ulong call(
void* o,
const void* f,
const void* u[]) {
302 (cast<T>(o)->*(
typename _W::Functor(f).pmf))((A0) u[0], (A1) u[1], (A2) u[2]);
306 return _make(_Wrapper::call, pmf);
313 template <
typename P,
typename R,
typename T>
static T*
dyn_cast(P* p, R (T::*)()) {
314 return dynamic_cast<T*
>(p);
316 template <
typename P,
typename R,
typename T>
static const T*
dyn_cast(
const P* p, R (T::*)()
const) {
317 return dynamic_cast<const T*
>(p);
320 template <
typename P,
typename R,
typename T,
typename A>
static T*
dyn_cast(P* p, R (T::*)(A)) {
321 return dynamic_cast<T*
>(p);
323 template <
typename P,
typename R,
typename T,
typename A>
static const T*
dyn_cast(
const P* p, R (T::*)(A)
const) {
324 return dynamic_cast<const T*
>(p);
379 template <
typename A0>
void operator()(A0 a0)
const;
381 template <
typename A0,
typename A1>
void operator()(A0 a0, A1 a1)
const;
383 template <
typename A0,
typename A1,
typename A2>
void operator()(A0 a0, A1 a1, A2 a2)
const;
385 static void checkTypes(
const std::type_info& typ1,
const std::type_info& typ2,
void* test);
388 template <
typename TYPE,
typename R,
typename OBJECT>
391 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
395 template <
typename TYPE,
typename R,
typename OBJECT>
397 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
401 template <
typename TYPE,
typename OBJECT>
403 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
407 template <
typename TYPE,
typename OBJECT>
409 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
414 template <
typename TYPE,
typename R,
typename OBJECT,
typename A>
417 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
421 template <
typename TYPE,
typename OBJECT,
typename A>
423 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
427 template <
typename TYPE,
typename R,
typename OBJECT,
typename A>
429 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
433 template <
typename TYPE,
typename OBJECT,
typename A>
435 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
441 template <
typename TYPE,
typename R,
typename OBJECT,
typename A1,
typename A2>
444 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
448 template <
typename TYPE,
typename R,
typename OBJECT,
typename A1,
typename A2>
450 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
454 template <
typename TYPE,
typename OBJECT,
typename A1,
typename A2>
456 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
460 template <
typename TYPE,
typename OBJECT,
typename A1,
typename A2>
462 checkTypes(
typeid(TYPE),
typeid(OBJECT),
dynamic_cast<OBJECT*
>(pointer));
470 const void* args[1] = { 0 };
476 template <
typename A0>
inline
479 const void* args[1] = { a0 };
485 template <
typename A0,
typename A1>
inline
488 const void* args[2] = { a0, a1 };
494 template <
typename A0,
typename A1,
typename A2>
inline
497 const void* args[3] = { a0, a1, a2 };
504 #endif // DD4HEP_CALLBACK_H
void add(TYPE *pointer, void(OBJECT::*pmf)(A) const, Location where=CallbackSequence::END)
Add a new callback to a const void member function and 1 argument.
void add(TYPE *pointer, void(OBJECT::*pmf)(), Location where=CallbackSequence::END)
Add a new callback to a void member function with no arguments.
static const T * dyn_cast(const P *p, R(T::*)() const)
Structure definition to store callback related data.
Callback(const void *p)
Constructor with object initialization.
void add(TYPE *pointer, void(OBJECT::*pmf)(A), Location where=CallbackSequence::END)
Add a new callback to a void member function and 1 argument.
const Callback & _make(ulong(*fptr)(void *o, const void *f, const void *u[]), T pmf)
Callback setup function for Callbacks with member functions taking no arguments.
CallbackSequence & operator=(const CallbackSequence &c)
Assignment operator.
static mfunc_t pmf(pmf_t f)
const Callback & make(void(T::*pmf)(A0, A1))
Callback setup function for Callbacks with const void member functions taking 2 arguments.
static void checkTypes(const std::type_info &typ1, const std::type_info &typ2, void *test)
Check the compatibility of two typed objects. The test is the result of a dynamic_cast.
void add(const Callback &cb, Location where)
Generically Add a new callback to the sequence depending on the location arguments.
static T * dyn_cast(P *p, R(T::*)(A))
CallbackSequence(const CallbackSequence &c)
Copy constructor.
void add(TYPE *pointer, R(OBJECT::*pmf)() const, Location where=CallbackSequence::END)
Add a new callback to a const member function with explicit return type and no arguments.
void add(TYPE *pointer, void(OBJECT::*pmf)() const, Location where=CallbackSequence::END)
Add a new callback to a const void member function and no arguments.
const Callback & make(R(T::*pmf)(A0, A1, A2) const)
Callback setup function for Callbacks with const member functions with explicit return type taking 3 ...
void add(TYPE *pointer, R(OBJECT::*pmf)(A1, A2), Location where=CallbackSequence::END)
Add a new callback to a member function with explicit return type and 2 arguments.
const Callback & make(R(T::*pmf)())
Callback setup function for Callbacks with member functions with explicit return type taking no argum...
void add(TYPE *pointer, R(OBJECT::*pmf)(), Location where=CallbackSequence::END)
Add a new callback to a member function with explicit return type and no arguments.
Definition of an actor on sequences of callbacks.
CallbackSequence()
Default constructor.
static Callback make(void *p, T pmf)
Callback(void *p)
Constructor with object initialization.
void add(TYPE *pointer, void(OBJECT::*pmf)(A1, A2) const, Location where=CallbackSequence::END)
Add a new callback to a const void member function with 2 arguments.
Definition of the generic callback structure for member functions.
const Callback & make(void(T::*pmf)(A0, A1, A2))
Callback setup function for Callbacks with const void member functions taking 3 arguments.
void add(TYPE *pointer, R(OBJECT::*pmf)(A), Location where=CallbackSequence::END)
Add a new callback to a member function with explicit return type and 1 argument.
static T * dyn_cast(P *p, R(T::*)())
void add(const Callback &cb)
Generically Add a new callback to the sequence depending on the location arguments.
void operator()() const
Execution overload for callbacks with no arguments.
const Callback & make(void(T::*pmf)(A0, A1) const)
Callback setup function for Callbacks with const void member functions taking 2 arguments.
void clear()
Clear the sequence and remove all callbacks.
void add(TYPE *pointer, R(OBJECT::*pmf)(A) const, Location where=CallbackSequence::END)
Add a new callback to a const member function with explicit return type and 1 argument.
static const T * dyn_cast(const P *p, R(T::*)(A) const)
Callback(void *p, void *mf, func_t c)
Initializing constructor.
const Callback & make(void(T::*pmf)(A0, A1, A2) const)
Callback setup function for Callbacks with const void member functions taking 3 arguments.
Wrapper around a C++ member function pointer.
const Callback & make(void(T::*pmf)())
Callback setup function for Callbacks with void member functions taking no arguments.
const Callback & make(R(T::*pmf)(A) const)
Callback setup function for Callbacks with const member functions with explicit return type taking 1 ...
Union to store pointers to member functions in callback objects.
unsigned long execute(const void *user_param[]) const
Execute the callback with the required number of user parameters.
Namespace for the AIDA detector description toolkit.
Callback()
Default constructor.
void add(TYPE *pointer, R(OBJECT::*pmf)(A1, A2) const, Location where=CallbackSequence::END)
Add a new callback to a const member function with explicit return type and 2 arguments.
void add(TYPE *pointer, void(OBJECT::*pmf)(A1, A2), Location where=CallbackSequence::END)
Add a new callback to a void member function with 2 arguments.
static T * cast(void *p)
Template cast function used internally by the wrapper for type conversion to the object's type.
const Callback & make(void(T::*pmf)(A))
Callback setup function for Callbacks with void member functions taking 1 argument.
std::vector< Callback > Callbacks
const Callback & make(R(T::*pmf)(A0, A1) const)
Callback setup function for Callbacks with const member functions with explicit return type taking 2 ...
static const T * c_cast(const void *p)
Template const cast function used internally by the wrapper for type conversion to the object's type.
const Callback & make(R(T::*pmf)() const)
Callback setup function for Callbacks with const member functions with explicit return type taking no...
const Callback & make(void(T::*pmf)(A) const)
Callback setup function for Callbacks with const void member functions taking 1 argument.
const Callback & make(void(T::*pmf)() const)
Callback setup function for Callbacks with const void member functions taking no arguments.
unsigned long(* func_t)(void *obj, const void *fun, const void *args[])