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*);
112 template <
typename R,
typename A1>
119 FP1(R (*
function)(A1) = 0) {
120 memset(_member,0,
sizeof(_member));
130 FP1(T *
object, R (T::*member)(A1)) {
139 _p.function =
function;
149 void attach(T *
object, R (T::*member)(A1)) {
150 _p.object =
static_cast<void*
>(object);
151 *
reinterpret_cast<R (T::**)(A1)
>(_member) = member;
152 _membercaller = &FP1::membercaller<T>;
158 if (_membercaller == 0 && _p.function) {
159 return _p.function(a);
160 }
else if (_membercaller && _p.object) {
161 return _membercaller(_p.object, _member, a);
166 typedef R (*static_fp)();
167 static_fp get_function()
const {
168 return (R(*)())_p.function;
171 R operator ()(A1 a) {
176 void *q = &_p.function;
177 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
181 static void membercaller(
void *
object, uintptr_t *member, A1 a) {
182 T* o =
static_cast<T*
>(object);
183 R (T::**m)(A1) =
reinterpret_cast<R (T::**)(A1)
>(member);
191 uintptr_t _member[2];
192 R (*_membercaller)(
void*, uintptr_t*, A1);
196 template <
typename R,
typename A1,
typename A2>
203 FP2(R (*
function)(A1, A2) = 0) {
204 memset(_member,0,
sizeof(_member));
214 FP2(T *
object, R (T::*member)(A1, A2)) {
223 _p.function =
function;
233 void attach(T *
object, R (T::*member)(A1, A2)) {
234 _p.object =
static_cast<void*
>(object);
235 *
reinterpret_cast<R (T::**)(A1, A2)
>(_member) = member;
236 _membercaller = &FP2::membercaller<T>;
242 if (_membercaller == 0 && _p.function) {
243 return _p.function(a1, a2);
244 }
else if (_membercaller && _p.object) {
245 return _membercaller(_p.object, _member, a1, a2);
250 typedef R (*static_fp)();
251 static_fp get_function()
const {
252 return (R(*)())_p.function;
255 R operator ()(A1 a1, A2 a2) {
260 void *q = &_p.function;
261 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
265 static void membercaller(
void *
object, uintptr_t *member, A1 a1, A2 a2) {
266 T* o =
static_cast<T*
>(object);
267 R (T::**m)(A1, A2) =
reinterpret_cast<R (T::**)(A1, A2)
>(member);
272 R (*
function)(A1, A2);
275 uintptr_t _member[2];
276 R (*_membercaller)(
void*, uintptr_t*, A1, A2);
280 template <
typename R,
typename A1,
typename A2,
typename A3>
287 FP3(R (*
function)(A1, A2, A3) = 0) {
288 memset(_member,0,
sizeof(_member));
298 FP3(T *
object, R (T::*member)(A1, A2, A3)) {
307 _p.function =
function;
317 void attach(T *
object, R (T::*member)(A1, A2, A3)) {
318 _p.object =
static_cast<void*
>(object);
319 *
reinterpret_cast<R (T::**)(A1, A2, A3)
>(_member) = member;
320 _membercaller = &FP3::membercaller<T>;
326 if (_membercaller == 0 && _p.function) {
327 return _p.function(a1, a2, a3);
328 }
else if (_membercaller && _p.object) {
329 return _membercaller(_p.object, _member, a1, a2, a3);
334 typedef R (*static_fp)();
335 static_fp get_function()
const {
336 return (R(*)())_p.function;
339 R operator ()(A1 a1, A2 a2, A3 a3) {
340 return call(a1, a2, a3);
344 void *q = &_p.function;
345 return (_membercaller != NULL) && _p.object != NULL && (*
static_cast<void **
>(q) != NULL);
349 static void membercaller(
void *
object, uintptr_t *member, A1 a1, A2 a2, A3 a3) {
350 T* o =
static_cast<T*
>(object);
351 R (T::**m)(A1, A2, A3) =
reinterpret_cast<R (T::**)(A1, A2, A3)
>(member);
352 (o->**m)(a1, a2, a3);
356 R (*
function)(A1, A2, A3);
359 uintptr_t _member[2];
360 R (*_membercaller)(
void*, uintptr_t*, A1, A2, A3);
FP1(T *object, R(T::*member)(A1))
Definition: functionpointer.h:130
FP3(T *object, R(T::*member)(A1, A2, A3))
Definition: functionpointer.h:298
void attach(T *object, R(T::*member)(A1))
Definition: functionpointer.h:149
Definition: functionpointer.h:281
FP2(R(*function)(A1, A2)=0)
Definition: functionpointer.h:203
void attach(R(*function)(A1, A2))
Definition: functionpointer.h:222
Definition: functionpointer.h:27
void attach(R(*function)(A1, A2, A3))
Definition: functionpointer.h:306
void attach(R(*function)(A1))
Definition: functionpointer.h:138
FP2(T *object, R(T::*member)(A1, A2))
Definition: functionpointer.h:214
FP0(T *object, R(T::*member)(void))
Definition: functionpointer.h:44
FP1(R(*function)(A1)=0)
Definition: functionpointer.h:119
void attach(R(*function)(void))
Definition: functionpointer.h:52
FP3(R(*function)(A1, A2, A3)=0)
Definition: functionpointer.h:287
void attach(T *object, R(T::*member)(A1, A2))
Definition: functionpointer.h:233
R call()
Definition: functionpointer.h:71
Definition: functionpointer.h:197
R call(A1 a1, A2 a2)
Definition: functionpointer.h:241
R call(A1 a)
Definition: functionpointer.h:157
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:325
void attach(T *object, R(T::*member)(A1, A2, A3))
Definition: functionpointer.h:317
Definition: functionpointer.h:113