16 #ifndef FUNCTIONPOINTER_H 17 #define FUNCTIONPOINTER_H 33 FP0(R (*
function)(
void) = 0) {
34 memset(_member,0,
sizeof(_member));
44 FP0(T *
object, R (T::*member)(
void)) {
53 _p.function =
function;
63 void attach(T *
object, R (T::*member)(
void)) {
64 _p.object =
static_cast<void*
>(object);
65 *
reinterpret_cast<R (T::**)(
void)
>(_member) = member;
66 _membercaller = &FP0::membercaller<T>;
72 if (_membercaller == 0 && _p.function) {
74 }
else if (_membercaller && _p.object) {
75 return _membercaller(_p.object, _member);
80 typedef R (*static_fp)();
81 static_fp get_function()
const {
82 return (R(*)())_p.function;
89 void *q = &_p.function;
90 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
95 static void membercaller(
void *
object, uintptr_t *member) {
96 T* o =
static_cast<T*
>(object);
97 R (T::**m)(void) =
reinterpret_cast<R (T::**)(
void)
>(member);
105 uintptr_t _member[2];
106 R (*_membercaller)(
void*, uintptr_t*);
113 template <
typename R,
typename A1>
120 FP1(R (*
function)(A1) = 0) {
121 memset(_member,0,
sizeof(_member));
131 FP1(T *
object, R (T::*member)(A1)) {
140 _p.function =
function;
150 void attach(T *
object, R (T::*member)(A1)) {
151 _p.object =
static_cast<void*
>(object);
152 *
reinterpret_cast<R (T::**)(A1)
>(_member) = member;
153 _membercaller = &FP1::membercaller<T>;
159 if (_membercaller == 0 && _p.function) {
160 return _p.function(a);
161 }
else if (_membercaller && _p.object) {
162 return _membercaller(_p.object, _member, a);
167 typedef R (*static_fp)();
168 static_fp get_function()
const {
169 return (R(*)())_p.function;
172 R operator ()(A1 a) {
177 void *q = &_p.function;
178 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
182 static void membercaller(
void *
object, uintptr_t *member, A1 a) {
183 T* o =
static_cast<T*
>(object);
184 R (T::**m)(A1) =
reinterpret_cast<R (T::**)(A1)
>(member);
192 uintptr_t _member[2];
193 R (*_membercaller)(
void*, uintptr_t*, A1);
198 template <
typename R,
typename A1,
typename A2>
205 FP2(R (*
function)(A1, A2) = 0) {
206 memset(_member,0,
sizeof(_member));
216 FP2(T *
object, R (T::*member)(A1, A2)) {
225 _p.function =
function;
235 void attach(T *
object, R (T::*member)(A1, A2)) {
236 _p.object =
static_cast<void*
>(object);
237 *
reinterpret_cast<R (T::**)(A1, A2)
>(_member) = member;
238 _membercaller = &FP2::membercaller<T>;
244 if (_membercaller == 0 && _p.function) {
245 return _p.function(a1, a2);
246 }
else if (_membercaller && _p.object) {
247 return _membercaller(_p.object, _member, a1, a2);
252 typedef R (*static_fp)();
253 static_fp get_function()
const {
254 return (R(*)())_p.function;
257 R operator ()(A1 a1, A2 a2) {
262 void *q = &_p.function;
263 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
267 static void membercaller(
void *
object, uintptr_t *member, A1 a1, A2 a2) {
268 T* o =
static_cast<T*
>(object);
269 R (T::**m)(A1, A2) =
reinterpret_cast<R (T::**)(A1, A2)
>(member);
274 R (*
function)(A1, A2);
277 uintptr_t _member[2];
278 R (*_membercaller)(
void*, uintptr_t*, A1, A2);
283 template <
typename R,
typename A1,
typename A2,
typename A3>
290 FP3(R (*
function)(A1, A2, A3) = 0) {
291 memset(_member,0,
sizeof(_member));
301 FP3(T *
object, R (T::*member)(A1, A2, A3)) {
310 _p.function =
function;
320 void attach(T *
object, R (T::*member)(A1, A2, A3)) {
321 _p.object =
static_cast<void*
>(object);
322 *
reinterpret_cast<R (T::**)(A1, A2, A3)
>(_member) = member;
323 _membercaller = &FP3::membercaller<T>;
329 if (_membercaller == 0 && _p.function) {
330 return _p.function(a1, a2, a3);
331 }
else if (_membercaller && _p.object) {
332 return _membercaller(_p.object, _member, a1, a2, a3);
337 typedef R (*static_fp)();
338 static_fp get_function()
const {
339 return (R(*)())_p.function;
342 R operator ()(A1 a1, A2 a2, A3 a3) {
343 return call(a1, a2, a3);
347 void *q = &_p.function;
348 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
352 static void membercaller(
void *
object, uintptr_t *member, A1 a1, A2 a2, A3 a3) {
353 T* o =
static_cast<T*
>(object);
354 R (T::**m)(A1, A2, A3) =
reinterpret_cast<R (T::**)(A1, A2, A3)
>(member);
355 (o->**m)(a1, a2, a3);
359 R (*
function)(A1, A2, A3);
362 uintptr_t _member[2];
363 R (*_membercaller)(
void*, uintptr_t*, A1, A2, A3);
FP1(T *object, R(T::*member)(A1))
Definition: functionpointer.h:131
FP3(T *object, R(T::*member)(A1, A2, A3))
Definition: functionpointer.h:301
void attach(T *object, R(T::*member)(A1))
Definition: functionpointer.h:150
Definition: functionpointer.h:284
FP2(R(*function)(A1, A2)=0)
Definition: functionpointer.h:205
void attach(R(*function)(A1, A2))
Definition: functionpointer.h:224
Definition: functionpointer.h:27
void attach(R(*function)(A1, A2, A3))
Definition: functionpointer.h:309
void attach(R(*function)(A1))
Definition: functionpointer.h:139
FP2(T *object, R(T::*member)(A1, A2))
Definition: functionpointer.h:216
FP0(T *object, R(T::*member)(void))
Definition: functionpointer.h:44
FP1(R(*function)(A1)=0)
Definition: functionpointer.h:120
void attach(R(*function)(void))
Definition: functionpointer.h:52
FP3(R(*function)(A1, A2, A3)=0)
Definition: functionpointer.h:290
void attach(T *object, R(T::*member)(A1, A2))
Definition: functionpointer.h:235
R call()
Definition: functionpointer.h:71
Definition: functionpointer.h:199
R call(A1 a1, A2 a2)
Definition: functionpointer.h:243
R call(A1 a)
Definition: functionpointer.h:158
FP0(R(*function)(void)=0)
Definition: functionpointer.h:33
void attach(T *object, R(T::*member)(void))
Definition: functionpointer.h:63
R call(A1 a1, A2 a2, A3 a3)
Definition: functionpointer.h:328
void attach(T *object, R(T::*member)(A1, A2, A3))
Definition: functionpointer.h:320
Definition: functionpointer.h:114