Flexible templated function class and related utilities that avoid dynamic memory allocation without limiting functionality
FuncPtr provides a flexible templated function class and related utilities while avoiding dynamic memory allocation and avoiding limited functionality.
FuncPtr provides an intuitive template interface:
FuncPtr<void(const char *)> func(puts); func("hello!\n"); // prints hello!
Several function types are supported by FuncPtr:
// Simple C functions void func(); FuncPtr<void()> fp(func); // C++ Methods struct Thing { void func(); }; Thing thing; FuncPtr<void()> fp(&thing, &Thing::func); // C functions with context void func(Thing *); FuncPtr<void()> fp(&thing, func); // Function objects struct Thing { void operator()(); }; Thing thing; FuncPtr<void()> fp(&thing);
There is no dynamic memory allocation, managing memory is placed entirely on the user. More advanced function manipulation can be accomplished with statically allocated classes:
// Function binding Binder<void(const char *), const char *> bind(putc, "hi!"); bind(); // prints hi! // Function composition Composer<int(const char *), const char *(int)> comp(puts, itoa); comp(10); // prints 10 // Function chaining Chainer<void(const char *), 2> chain; chain.attach(puts); chain.attach(puts); chain("hi!\n"); // prints hi! twice
FuncPtr allows easy support of a large range of function types in C++ APIs with very few lines of code:
class Thing { public: // The following two methods are sufficient for supporting // every supported function type void attach(FuncPtr<void()> func) { _func.attach(func); } template<typename T, typename M> void attach(T *obj, M method) { attach(FuncPtr<void()>(obj, method)); } private: FuncPtr<void()> _func; }
Additionally, FuncPtrs have several utilities for easy integration with C APIs:
// C style callbacks void register_callback(void (*callback)(void *), void *data); register_callback(&FuncPtr<void()>::thunk, &func); // C style functions without context void register_callback(void (*callback)()); Thunker thunk(func); register_callback(thunk); // mbed style callbacks void register_callback(T *obj, void (T::*M)()); register_callback(&func, &FuncPtr<void()>::call);
Binder.h@18:a0fde14b6c39, 2016-04-17 (annotated)
- Committer:
- Christopher Haster
- Date:
- Sun Apr 17 23:38:04 2016 -0500
- Revision:
- 18:a0fde14b6c39
- Parent:
- 14:79be4e700cc9
Increase to 5 args
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
3:84b61e1b050c | 1 | /* Binder |
Christopher Haster |
3:84b61e1b050c | 2 | * Static function binding |
Christopher Haster |
3:84b61e1b050c | 3 | */ |
Christopher Haster |
3:84b61e1b050c | 4 | #ifndef BINDER_H |
Christopher Haster |
3:84b61e1b050c | 5 | #define BINDER_H |
Christopher Haster |
3:84b61e1b050c | 6 | |
Christopher Haster |
3:84b61e1b050c | 7 | #include "FuncPtr.h" |
Christopher Haster |
3:84b61e1b050c | 8 | |
Christopher Haster |
3:84b61e1b050c | 9 | |
Christopher Haster |
3:84b61e1b050c | 10 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 11 | */ |
Christopher Haster |
18:a0fde14b6c39 | 12 | template <typename F, typename B0=void, typename B1=void, typename B2=void, typename B3=void, typename B4=void> |
Christopher Haster |
3:84b61e1b050c | 13 | class Binder; |
Christopher Haster |
3:84b61e1b050c | 14 | |
Christopher Haster |
3:84b61e1b050c | 15 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 16 | */ |
Christopher Haster |
18:a0fde14b6c39 | 17 | template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4> |
Christopher Haster |
18:a0fde14b6c39 | 18 | class Binder<R(B0, B1, B2, B3, B4), B0, B1, B2, B3, B4> { |
Christopher Haster |
18:a0fde14b6c39 | 19 | public: |
Christopher Haster |
18:a0fde14b6c39 | 20 | /** Create an unbound Binder |
Christopher Haster |
18:a0fde14b6c39 | 21 | */ |
Christopher Haster |
18:a0fde14b6c39 | 22 | Binder() {} |
Christopher Haster |
18:a0fde14b6c39 | 23 | |
Christopher Haster |
18:a0fde14b6c39 | 24 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 25 | */ |
Christopher Haster |
18:a0fde14b6c39 | 26 | Binder(FuncPtr<R(B0, B1, B2, B3, B4)> func, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) { |
Christopher Haster |
18:a0fde14b6c39 | 27 | attach(func, b0, b1, b2, b3, b4); |
Christopher Haster |
18:a0fde14b6c39 | 28 | } |
Christopher Haster |
18:a0fde14b6c39 | 29 | |
Christopher Haster |
18:a0fde14b6c39 | 30 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 31 | */ |
Christopher Haster |
18:a0fde14b6c39 | 32 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 33 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) { |
Christopher Haster |
18:a0fde14b6c39 | 34 | attach(obj, method, b0, b1, b2, b3, b4); |
Christopher Haster |
18:a0fde14b6c39 | 35 | } |
Christopher Haster |
18:a0fde14b6c39 | 36 | |
Christopher Haster |
18:a0fde14b6c39 | 37 | /** Bind arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 38 | */ |
Christopher Haster |
18:a0fde14b6c39 | 39 | void attach(FuncPtr<R(B0, B1, B2, B3, B4)> func, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) { |
Christopher Haster |
18:a0fde14b6c39 | 40 | _func.attach(func); |
Christopher Haster |
18:a0fde14b6c39 | 41 | _b0 = b0; _b1 = b1; _b2 = b2; _b3 = b3; _b4 = b4; |
Christopher Haster |
18:a0fde14b6c39 | 42 | } |
Christopher Haster |
18:a0fde14b6c39 | 43 | |
Christopher Haster |
18:a0fde14b6c39 | 44 | /** Bind arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 45 | */ |
Christopher Haster |
18:a0fde14b6c39 | 46 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 47 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) { |
Christopher Haster |
18:a0fde14b6c39 | 48 | attach(FuncPtr<R(B0, B1, B2, B3, B4)>(obj, method), b0, b1, b2, b3, b4); |
Christopher Haster |
18:a0fde14b6c39 | 49 | } |
Christopher Haster |
18:a0fde14b6c39 | 50 | |
Christopher Haster |
18:a0fde14b6c39 | 51 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 52 | */ |
Christopher Haster |
18:a0fde14b6c39 | 53 | R call() { |
Christopher Haster |
18:a0fde14b6c39 | 54 | return _func(_b0, _b1, _b2, _b3, _b4); |
Christopher Haster |
18:a0fde14b6c39 | 55 | } |
Christopher Haster |
18:a0fde14b6c39 | 56 | |
Christopher Haster |
18:a0fde14b6c39 | 57 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 58 | */ |
Christopher Haster |
18:a0fde14b6c39 | 59 | R operator()() { |
Christopher Haster |
18:a0fde14b6c39 | 60 | return call(); |
Christopher Haster |
18:a0fde14b6c39 | 61 | } |
Christopher Haster |
18:a0fde14b6c39 | 62 | |
Christopher Haster |
18:a0fde14b6c39 | 63 | /** Test if function has been bound |
Christopher Haster |
18:a0fde14b6c39 | 64 | */ |
Christopher Haster |
18:a0fde14b6c39 | 65 | operator bool() const { |
Christopher Haster |
18:a0fde14b6c39 | 66 | return _func; |
Christopher Haster |
18:a0fde14b6c39 | 67 | } |
Christopher Haster |
18:a0fde14b6c39 | 68 | |
Christopher Haster |
18:a0fde14b6c39 | 69 | /** Static thunk for passing as C-style function |
Christopher Haster |
18:a0fde14b6c39 | 70 | * @param func Binder to call passed as void pointer |
Christopher Haster |
18:a0fde14b6c39 | 71 | */ |
Christopher Haster |
18:a0fde14b6c39 | 72 | static R thunk(void *func) { |
Christopher Haster |
18:a0fde14b6c39 | 73 | return static_cast<Binder<R(B0, B1, B2, B3, B4), B0, B1, B2, B3, B4>*>(func) |
Christopher Haster |
18:a0fde14b6c39 | 74 | ->call(); |
Christopher Haster |
18:a0fde14b6c39 | 75 | } |
Christopher Haster |
18:a0fde14b6c39 | 76 | |
Christopher Haster |
18:a0fde14b6c39 | 77 | private: |
Christopher Haster |
18:a0fde14b6c39 | 78 | FuncPtr<R(B0, B1, B2, B3, B4)> _func; |
Christopher Haster |
18:a0fde14b6c39 | 79 | B0 _b0; B1 _b1; B2 _b2; B3 _b3; B4 _b4; |
Christopher Haster |
18:a0fde14b6c39 | 80 | }; |
Christopher Haster |
18:a0fde14b6c39 | 81 | |
Christopher Haster |
18:a0fde14b6c39 | 82 | /** Static function binding |
Christopher Haster |
18:a0fde14b6c39 | 83 | */ |
Christopher Haster |
18:a0fde14b6c39 | 84 | template <typename R, typename B0, typename B1, typename B2, typename B3, typename A0> |
Christopher Haster |
18:a0fde14b6c39 | 85 | class Binder<R(B0, B1, B2, B3, A0), B0, B1, B2, B3> { |
Christopher Haster |
18:a0fde14b6c39 | 86 | public: |
Christopher Haster |
18:a0fde14b6c39 | 87 | /** Create an unbound Binder |
Christopher Haster |
18:a0fde14b6c39 | 88 | */ |
Christopher Haster |
18:a0fde14b6c39 | 89 | Binder() {} |
Christopher Haster |
18:a0fde14b6c39 | 90 | |
Christopher Haster |
18:a0fde14b6c39 | 91 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 92 | */ |
Christopher Haster |
18:a0fde14b6c39 | 93 | Binder(FuncPtr<R(B0, B1, B2, B3, A0)> func, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
18:a0fde14b6c39 | 94 | attach(func, b0, b1, b2, b3); |
Christopher Haster |
18:a0fde14b6c39 | 95 | } |
Christopher Haster |
18:a0fde14b6c39 | 96 | |
Christopher Haster |
18:a0fde14b6c39 | 97 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 98 | */ |
Christopher Haster |
18:a0fde14b6c39 | 99 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 100 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
18:a0fde14b6c39 | 101 | attach(obj, method, b0, b1, b2, b3); |
Christopher Haster |
18:a0fde14b6c39 | 102 | } |
Christopher Haster |
18:a0fde14b6c39 | 103 | |
Christopher Haster |
18:a0fde14b6c39 | 104 | /** Bind arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 105 | */ |
Christopher Haster |
18:a0fde14b6c39 | 106 | void attach(FuncPtr<R(B0, B1, B2, B3, A0)> func, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
18:a0fde14b6c39 | 107 | _func.attach(func); |
Christopher Haster |
18:a0fde14b6c39 | 108 | _b0 = b0; _b1 = b1; _b2 = b2; _b3 = b3; |
Christopher Haster |
18:a0fde14b6c39 | 109 | } |
Christopher Haster |
18:a0fde14b6c39 | 110 | |
Christopher Haster |
18:a0fde14b6c39 | 111 | /** Bind arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 112 | */ |
Christopher Haster |
18:a0fde14b6c39 | 113 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 114 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
18:a0fde14b6c39 | 115 | attach(FuncPtr<R(B0, B1, B2, B3, A0)>(obj, method), b0, b1, b2, b3); |
Christopher Haster |
18:a0fde14b6c39 | 116 | } |
Christopher Haster |
18:a0fde14b6c39 | 117 | |
Christopher Haster |
18:a0fde14b6c39 | 118 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 119 | */ |
Christopher Haster |
18:a0fde14b6c39 | 120 | R call(A0 a0) { |
Christopher Haster |
18:a0fde14b6c39 | 121 | return _func(_b0, _b1, _b2, _b3, a0); |
Christopher Haster |
18:a0fde14b6c39 | 122 | } |
Christopher Haster |
18:a0fde14b6c39 | 123 | |
Christopher Haster |
18:a0fde14b6c39 | 124 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 125 | */ |
Christopher Haster |
18:a0fde14b6c39 | 126 | R operator()(A0 a0) { |
Christopher Haster |
18:a0fde14b6c39 | 127 | return call(a0); |
Christopher Haster |
18:a0fde14b6c39 | 128 | } |
Christopher Haster |
18:a0fde14b6c39 | 129 | |
Christopher Haster |
18:a0fde14b6c39 | 130 | /** Test if function has been bound |
Christopher Haster |
18:a0fde14b6c39 | 131 | */ |
Christopher Haster |
18:a0fde14b6c39 | 132 | operator bool() const { |
Christopher Haster |
18:a0fde14b6c39 | 133 | return _func; |
Christopher Haster |
18:a0fde14b6c39 | 134 | } |
Christopher Haster |
18:a0fde14b6c39 | 135 | |
Christopher Haster |
18:a0fde14b6c39 | 136 | /** Static thunk for passing as C-style function |
Christopher Haster |
18:a0fde14b6c39 | 137 | * @param func Binder to call passed as void pointer |
Christopher Haster |
18:a0fde14b6c39 | 138 | */ |
Christopher Haster |
18:a0fde14b6c39 | 139 | static R thunk(void *func, A0 a0) { |
Christopher Haster |
18:a0fde14b6c39 | 140 | return static_cast<Binder<R(B0, B1, B2, B3, A0), B0, B1, B2, B3>*>(func) |
Christopher Haster |
18:a0fde14b6c39 | 141 | ->call(a0); |
Christopher Haster |
18:a0fde14b6c39 | 142 | } |
Christopher Haster |
18:a0fde14b6c39 | 143 | |
Christopher Haster |
18:a0fde14b6c39 | 144 | private: |
Christopher Haster |
18:a0fde14b6c39 | 145 | FuncPtr<R(B0, B1, B2, B3, A0)> _func; |
Christopher Haster |
18:a0fde14b6c39 | 146 | B0 _b0; B1 _b1; B2 _b2; B3 _b3; |
Christopher Haster |
18:a0fde14b6c39 | 147 | }; |
Christopher Haster |
18:a0fde14b6c39 | 148 | |
Christopher Haster |
18:a0fde14b6c39 | 149 | /** Static function binding |
Christopher Haster |
18:a0fde14b6c39 | 150 | */ |
Christopher Haster |
18:a0fde14b6c39 | 151 | template <typename R, typename B0, typename B1, typename B2, typename A0, typename A1> |
Christopher Haster |
18:a0fde14b6c39 | 152 | class Binder<R(B0, B1, B2, A0, A1), B0, B1, B2> { |
Christopher Haster |
18:a0fde14b6c39 | 153 | public: |
Christopher Haster |
18:a0fde14b6c39 | 154 | /** Create an unbound Binder |
Christopher Haster |
18:a0fde14b6c39 | 155 | */ |
Christopher Haster |
18:a0fde14b6c39 | 156 | Binder() {} |
Christopher Haster |
18:a0fde14b6c39 | 157 | |
Christopher Haster |
18:a0fde14b6c39 | 158 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 159 | */ |
Christopher Haster |
18:a0fde14b6c39 | 160 | Binder(FuncPtr<R(B0, B1, B2, A0, A1)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
18:a0fde14b6c39 | 161 | attach(func, b0, b1, b2); |
Christopher Haster |
18:a0fde14b6c39 | 162 | } |
Christopher Haster |
18:a0fde14b6c39 | 163 | |
Christopher Haster |
18:a0fde14b6c39 | 164 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 165 | */ |
Christopher Haster |
18:a0fde14b6c39 | 166 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 167 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
18:a0fde14b6c39 | 168 | attach(obj, method, b0, b1, b2); |
Christopher Haster |
18:a0fde14b6c39 | 169 | } |
Christopher Haster |
18:a0fde14b6c39 | 170 | |
Christopher Haster |
18:a0fde14b6c39 | 171 | /** Bind arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 172 | */ |
Christopher Haster |
18:a0fde14b6c39 | 173 | void attach(FuncPtr<R(B0, B1, B2, A0, A1)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
18:a0fde14b6c39 | 174 | _func.attach(func); |
Christopher Haster |
18:a0fde14b6c39 | 175 | _b0 = b0; _b1 = b1; _b2 = b2; |
Christopher Haster |
18:a0fde14b6c39 | 176 | } |
Christopher Haster |
18:a0fde14b6c39 | 177 | |
Christopher Haster |
18:a0fde14b6c39 | 178 | /** Bind arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 179 | */ |
Christopher Haster |
18:a0fde14b6c39 | 180 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 181 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
18:a0fde14b6c39 | 182 | attach(FuncPtr<R(B0, B1, B2, A0, A1)>(obj, method), b0, b1, b2); |
Christopher Haster |
18:a0fde14b6c39 | 183 | } |
Christopher Haster |
18:a0fde14b6c39 | 184 | |
Christopher Haster |
18:a0fde14b6c39 | 185 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 186 | */ |
Christopher Haster |
18:a0fde14b6c39 | 187 | R call(A0 a0, A1 a1) { |
Christopher Haster |
18:a0fde14b6c39 | 188 | return _func(_b0, _b1, _b2, a0, a1); |
Christopher Haster |
18:a0fde14b6c39 | 189 | } |
Christopher Haster |
18:a0fde14b6c39 | 190 | |
Christopher Haster |
18:a0fde14b6c39 | 191 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 192 | */ |
Christopher Haster |
18:a0fde14b6c39 | 193 | R operator()(A0 a0, A1 a1) { |
Christopher Haster |
18:a0fde14b6c39 | 194 | return call(a0, a1); |
Christopher Haster |
18:a0fde14b6c39 | 195 | } |
Christopher Haster |
18:a0fde14b6c39 | 196 | |
Christopher Haster |
18:a0fde14b6c39 | 197 | /** Test if function has been bound |
Christopher Haster |
18:a0fde14b6c39 | 198 | */ |
Christopher Haster |
18:a0fde14b6c39 | 199 | operator bool() const { |
Christopher Haster |
18:a0fde14b6c39 | 200 | return _func; |
Christopher Haster |
18:a0fde14b6c39 | 201 | } |
Christopher Haster |
18:a0fde14b6c39 | 202 | |
Christopher Haster |
18:a0fde14b6c39 | 203 | /** Static thunk for passing as C-style function |
Christopher Haster |
18:a0fde14b6c39 | 204 | * @param func Binder to call passed as void pointer |
Christopher Haster |
18:a0fde14b6c39 | 205 | */ |
Christopher Haster |
18:a0fde14b6c39 | 206 | static R thunk(void *func, A0 a0, A1 a1) { |
Christopher Haster |
18:a0fde14b6c39 | 207 | return static_cast<Binder<R(B0, B1, B2, A0, A1), B0, B1, B2>*>(func) |
Christopher Haster |
18:a0fde14b6c39 | 208 | ->call(a0, a1); |
Christopher Haster |
18:a0fde14b6c39 | 209 | } |
Christopher Haster |
18:a0fde14b6c39 | 210 | |
Christopher Haster |
18:a0fde14b6c39 | 211 | private: |
Christopher Haster |
18:a0fde14b6c39 | 212 | FuncPtr<R(B0, B1, B2, A0, A1)> _func; |
Christopher Haster |
18:a0fde14b6c39 | 213 | B0 _b0; B1 _b1; B2 _b2; |
Christopher Haster |
18:a0fde14b6c39 | 214 | }; |
Christopher Haster |
18:a0fde14b6c39 | 215 | |
Christopher Haster |
18:a0fde14b6c39 | 216 | /** Static function binding |
Christopher Haster |
18:a0fde14b6c39 | 217 | */ |
Christopher Haster |
18:a0fde14b6c39 | 218 | template <typename R, typename B0, typename B1, typename A0, typename A1, typename A2> |
Christopher Haster |
18:a0fde14b6c39 | 219 | class Binder<R(B0, B1, A0, A1, A2), B0, B1> { |
Christopher Haster |
18:a0fde14b6c39 | 220 | public: |
Christopher Haster |
18:a0fde14b6c39 | 221 | /** Create an unbound Binder |
Christopher Haster |
18:a0fde14b6c39 | 222 | */ |
Christopher Haster |
18:a0fde14b6c39 | 223 | Binder() {} |
Christopher Haster |
18:a0fde14b6c39 | 224 | |
Christopher Haster |
18:a0fde14b6c39 | 225 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 226 | */ |
Christopher Haster |
18:a0fde14b6c39 | 227 | Binder(FuncPtr<R(B0, B1, A0, A1, A2)> func, B0 b0, B1 b1) { |
Christopher Haster |
18:a0fde14b6c39 | 228 | attach(func, b0, b1); |
Christopher Haster |
18:a0fde14b6c39 | 229 | } |
Christopher Haster |
18:a0fde14b6c39 | 230 | |
Christopher Haster |
18:a0fde14b6c39 | 231 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 232 | */ |
Christopher Haster |
18:a0fde14b6c39 | 233 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 234 | Binder(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
18:a0fde14b6c39 | 235 | attach(obj, method, b0, b1); |
Christopher Haster |
18:a0fde14b6c39 | 236 | } |
Christopher Haster |
18:a0fde14b6c39 | 237 | |
Christopher Haster |
18:a0fde14b6c39 | 238 | /** Bind arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 239 | */ |
Christopher Haster |
18:a0fde14b6c39 | 240 | void attach(FuncPtr<R(B0, B1, A0, A1, A2)> func, B0 b0, B1 b1) { |
Christopher Haster |
18:a0fde14b6c39 | 241 | _func.attach(func); |
Christopher Haster |
18:a0fde14b6c39 | 242 | _b0 = b0; _b1 = b1; |
Christopher Haster |
18:a0fde14b6c39 | 243 | } |
Christopher Haster |
18:a0fde14b6c39 | 244 | |
Christopher Haster |
18:a0fde14b6c39 | 245 | /** Bind arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 246 | */ |
Christopher Haster |
18:a0fde14b6c39 | 247 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 248 | void attach(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
18:a0fde14b6c39 | 249 | attach(FuncPtr<R(B0, B1, A0, A1, A2)>(obj, method), b0, b1); |
Christopher Haster |
18:a0fde14b6c39 | 250 | } |
Christopher Haster |
18:a0fde14b6c39 | 251 | |
Christopher Haster |
18:a0fde14b6c39 | 252 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 253 | */ |
Christopher Haster |
18:a0fde14b6c39 | 254 | R call(A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
18:a0fde14b6c39 | 255 | return _func(_b0, _b1, a0, a1, a2); |
Christopher Haster |
18:a0fde14b6c39 | 256 | } |
Christopher Haster |
18:a0fde14b6c39 | 257 | |
Christopher Haster |
18:a0fde14b6c39 | 258 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 259 | */ |
Christopher Haster |
18:a0fde14b6c39 | 260 | R operator()(A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
18:a0fde14b6c39 | 261 | return call(a0, a1, a2); |
Christopher Haster |
18:a0fde14b6c39 | 262 | } |
Christopher Haster |
18:a0fde14b6c39 | 263 | |
Christopher Haster |
18:a0fde14b6c39 | 264 | /** Test if function has been bound |
Christopher Haster |
18:a0fde14b6c39 | 265 | */ |
Christopher Haster |
18:a0fde14b6c39 | 266 | operator bool() const { |
Christopher Haster |
18:a0fde14b6c39 | 267 | return _func; |
Christopher Haster |
18:a0fde14b6c39 | 268 | } |
Christopher Haster |
18:a0fde14b6c39 | 269 | |
Christopher Haster |
18:a0fde14b6c39 | 270 | /** Static thunk for passing as C-style function |
Christopher Haster |
18:a0fde14b6c39 | 271 | * @param func Binder to call passed as void pointer |
Christopher Haster |
18:a0fde14b6c39 | 272 | */ |
Christopher Haster |
18:a0fde14b6c39 | 273 | static R thunk(void *func, A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
18:a0fde14b6c39 | 274 | return static_cast<Binder<R(B0, B1, A0, A1, A2), B0, B1>*>(func) |
Christopher Haster |
18:a0fde14b6c39 | 275 | ->call(a0, a1, a2); |
Christopher Haster |
18:a0fde14b6c39 | 276 | } |
Christopher Haster |
18:a0fde14b6c39 | 277 | |
Christopher Haster |
18:a0fde14b6c39 | 278 | private: |
Christopher Haster |
18:a0fde14b6c39 | 279 | FuncPtr<R(B0, B1, A0, A1, A2)> _func; |
Christopher Haster |
18:a0fde14b6c39 | 280 | B0 _b0; B1 _b1; |
Christopher Haster |
18:a0fde14b6c39 | 281 | }; |
Christopher Haster |
18:a0fde14b6c39 | 282 | |
Christopher Haster |
18:a0fde14b6c39 | 283 | /** Static function binding |
Christopher Haster |
18:a0fde14b6c39 | 284 | */ |
Christopher Haster |
18:a0fde14b6c39 | 285 | template <typename R, typename B0, typename A0, typename A1, typename A2, typename A3> |
Christopher Haster |
18:a0fde14b6c39 | 286 | class Binder<R(B0, A0, A1, A2, A3), B0> { |
Christopher Haster |
18:a0fde14b6c39 | 287 | public: |
Christopher Haster |
18:a0fde14b6c39 | 288 | /** Create an unbound Binder |
Christopher Haster |
18:a0fde14b6c39 | 289 | */ |
Christopher Haster |
18:a0fde14b6c39 | 290 | Binder() {} |
Christopher Haster |
18:a0fde14b6c39 | 291 | |
Christopher Haster |
18:a0fde14b6c39 | 292 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 293 | */ |
Christopher Haster |
18:a0fde14b6c39 | 294 | Binder(FuncPtr<R(B0, A0, A1, A2, A3)> func, B0 b0) { |
Christopher Haster |
18:a0fde14b6c39 | 295 | attach(func, b0); |
Christopher Haster |
18:a0fde14b6c39 | 296 | } |
Christopher Haster |
18:a0fde14b6c39 | 297 | |
Christopher Haster |
18:a0fde14b6c39 | 298 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 299 | */ |
Christopher Haster |
18:a0fde14b6c39 | 300 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 301 | Binder(T *obj, M method, B0 b0) { |
Christopher Haster |
18:a0fde14b6c39 | 302 | attach(obj, method, b0); |
Christopher Haster |
18:a0fde14b6c39 | 303 | } |
Christopher Haster |
18:a0fde14b6c39 | 304 | |
Christopher Haster |
18:a0fde14b6c39 | 305 | /** Bind arguments to a function |
Christopher Haster |
18:a0fde14b6c39 | 306 | */ |
Christopher Haster |
18:a0fde14b6c39 | 307 | void attach(FuncPtr<R(B0, A0, A1, A2, A3)> func, B0 b0) { |
Christopher Haster |
18:a0fde14b6c39 | 308 | _func.attach(func); |
Christopher Haster |
18:a0fde14b6c39 | 309 | _b0 = b0; |
Christopher Haster |
18:a0fde14b6c39 | 310 | } |
Christopher Haster |
18:a0fde14b6c39 | 311 | |
Christopher Haster |
18:a0fde14b6c39 | 312 | /** Bind arguments to a method |
Christopher Haster |
18:a0fde14b6c39 | 313 | */ |
Christopher Haster |
18:a0fde14b6c39 | 314 | template <typename T, typename M> |
Christopher Haster |
18:a0fde14b6c39 | 315 | void attach(T *obj, M method, B0 b0) { |
Christopher Haster |
18:a0fde14b6c39 | 316 | attach(FuncPtr<R(B0, A0, A1, A2, A3)>(obj, method), b0); |
Christopher Haster |
18:a0fde14b6c39 | 317 | } |
Christopher Haster |
18:a0fde14b6c39 | 318 | |
Christopher Haster |
18:a0fde14b6c39 | 319 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 320 | */ |
Christopher Haster |
18:a0fde14b6c39 | 321 | R call(A0 a0, A1 a1, A2 a2, A3 a3) { |
Christopher Haster |
18:a0fde14b6c39 | 322 | return _func(_b0, a0, a1, a2, a3); |
Christopher Haster |
18:a0fde14b6c39 | 323 | } |
Christopher Haster |
18:a0fde14b6c39 | 324 | |
Christopher Haster |
18:a0fde14b6c39 | 325 | /** Call the bound function |
Christopher Haster |
18:a0fde14b6c39 | 326 | */ |
Christopher Haster |
18:a0fde14b6c39 | 327 | R operator()(A0 a0, A1 a1, A2 a2, A3 a3) { |
Christopher Haster |
18:a0fde14b6c39 | 328 | return call(a0, a1, a2, a3); |
Christopher Haster |
18:a0fde14b6c39 | 329 | } |
Christopher Haster |
18:a0fde14b6c39 | 330 | |
Christopher Haster |
18:a0fde14b6c39 | 331 | /** Test if function has been bound |
Christopher Haster |
18:a0fde14b6c39 | 332 | */ |
Christopher Haster |
18:a0fde14b6c39 | 333 | operator bool() const { |
Christopher Haster |
18:a0fde14b6c39 | 334 | return _func; |
Christopher Haster |
18:a0fde14b6c39 | 335 | } |
Christopher Haster |
18:a0fde14b6c39 | 336 | |
Christopher Haster |
18:a0fde14b6c39 | 337 | /** Static thunk for passing as C-style function |
Christopher Haster |
18:a0fde14b6c39 | 338 | * @param func Binder to call passed as void pointer |
Christopher Haster |
18:a0fde14b6c39 | 339 | */ |
Christopher Haster |
18:a0fde14b6c39 | 340 | static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
Christopher Haster |
18:a0fde14b6c39 | 341 | return static_cast<Binder<R(B0, A0, A1, A2, A3), B0>*>(func) |
Christopher Haster |
18:a0fde14b6c39 | 342 | ->call(a0, a1, a2, a3); |
Christopher Haster |
18:a0fde14b6c39 | 343 | } |
Christopher Haster |
18:a0fde14b6c39 | 344 | |
Christopher Haster |
18:a0fde14b6c39 | 345 | private: |
Christopher Haster |
18:a0fde14b6c39 | 346 | FuncPtr<R(B0, A0, A1, A2, A3)> _func; |
Christopher Haster |
18:a0fde14b6c39 | 347 | B0 _b0; |
Christopher Haster |
18:a0fde14b6c39 | 348 | }; |
Christopher Haster |
18:a0fde14b6c39 | 349 | |
Christopher Haster |
18:a0fde14b6c39 | 350 | /** Static function binding |
Christopher Haster |
18:a0fde14b6c39 | 351 | */ |
Christopher Haster |
3:84b61e1b050c | 352 | template <typename R, typename B0, typename B1, typename B2, typename B3> |
Christopher Haster |
3:84b61e1b050c | 353 | class Binder<R(B0, B1, B2, B3), B0, B1, B2, B3> { |
Christopher Haster |
3:84b61e1b050c | 354 | public: |
Christopher Haster |
3:84b61e1b050c | 355 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 356 | */ |
Christopher Haster |
3:84b61e1b050c | 357 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 358 | |
Christopher Haster |
3:84b61e1b050c | 359 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 360 | */ |
Christopher Haster |
3:84b61e1b050c | 361 | Binder(FuncPtr<R(B0, B1, B2, B3)> func, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
3:84b61e1b050c | 362 | attach(func, b0, b1, b2, b3); |
Christopher Haster |
3:84b61e1b050c | 363 | } |
Christopher Haster |
3:84b61e1b050c | 364 | |
Christopher Haster |
3:84b61e1b050c | 365 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 366 | */ |
Christopher Haster |
3:84b61e1b050c | 367 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 368 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
3:84b61e1b050c | 369 | attach(obj, method, b0, b1, b2, b3); |
Christopher Haster |
3:84b61e1b050c | 370 | } |
Christopher Haster |
3:84b61e1b050c | 371 | |
Christopher Haster |
3:84b61e1b050c | 372 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 373 | */ |
Christopher Haster |
3:84b61e1b050c | 374 | void attach(FuncPtr<R(B0, B1, B2, B3)> func, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
3:84b61e1b050c | 375 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 376 | _b0 = b0; _b1 = b1; _b2 = b2; _b3 = b3; |
Christopher Haster |
3:84b61e1b050c | 377 | } |
Christopher Haster |
3:84b61e1b050c | 378 | |
Christopher Haster |
3:84b61e1b050c | 379 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 380 | */ |
Christopher Haster |
3:84b61e1b050c | 381 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 382 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2, B3 b3) { |
Christopher Haster |
3:84b61e1b050c | 383 | attach(FuncPtr<R(B0, B1, B2, B3)>(obj, method), b0, b1, b2, b3); |
Christopher Haster |
3:84b61e1b050c | 384 | } |
Christopher Haster |
3:84b61e1b050c | 385 | |
Christopher Haster |
3:84b61e1b050c | 386 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 387 | */ |
Christopher Haster |
3:84b61e1b050c | 388 | R call() { |
Christopher Haster |
3:84b61e1b050c | 389 | return _func(_b0, _b1, _b2, _b3); |
Christopher Haster |
3:84b61e1b050c | 390 | } |
Christopher Haster |
3:84b61e1b050c | 391 | |
Christopher Haster |
3:84b61e1b050c | 392 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 393 | */ |
Christopher Haster |
3:84b61e1b050c | 394 | R operator()() { |
Christopher Haster |
3:84b61e1b050c | 395 | return call(); |
Christopher Haster |
3:84b61e1b050c | 396 | } |
Christopher Haster |
3:84b61e1b050c | 397 | |
Christopher Haster |
3:84b61e1b050c | 398 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 399 | */ |
Christopher Haster |
8:71037a47492d | 400 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 401 | return _func; |
Christopher Haster |
3:84b61e1b050c | 402 | } |
Christopher Haster |
3:84b61e1b050c | 403 | |
Christopher Haster |
3:84b61e1b050c | 404 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 405 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 406 | */ |
Christopher Haster |
3:84b61e1b050c | 407 | static R thunk(void *func) { |
Christopher Haster |
3:84b61e1b050c | 408 | return static_cast<Binder<R(B0, B1, B2, B3), B0, B1, B2, B3>*>(func) |
Christopher Haster |
3:84b61e1b050c | 409 | ->call(); |
Christopher Haster |
3:84b61e1b050c | 410 | } |
Christopher Haster |
3:84b61e1b050c | 411 | |
Christopher Haster |
3:84b61e1b050c | 412 | private: |
Christopher Haster |
3:84b61e1b050c | 413 | FuncPtr<R(B0, B1, B2, B3)> _func; |
Christopher Haster |
3:84b61e1b050c | 414 | B0 _b0; B1 _b1; B2 _b2; B3 _b3; |
Christopher Haster |
3:84b61e1b050c | 415 | }; |
Christopher Haster |
3:84b61e1b050c | 416 | |
Christopher Haster |
3:84b61e1b050c | 417 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 418 | */ |
Christopher Haster |
3:84b61e1b050c | 419 | template <typename R, typename B0, typename B1, typename B2, typename A0> |
Christopher Haster |
3:84b61e1b050c | 420 | class Binder<R(B0, B1, B2, A0), B0, B1, B2> { |
Christopher Haster |
3:84b61e1b050c | 421 | public: |
Christopher Haster |
3:84b61e1b050c | 422 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 423 | */ |
Christopher Haster |
3:84b61e1b050c | 424 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 425 | |
Christopher Haster |
3:84b61e1b050c | 426 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 427 | */ |
Christopher Haster |
3:84b61e1b050c | 428 | Binder(FuncPtr<R(B0, B1, B2, A0)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 429 | attach(func, b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 430 | } |
Christopher Haster |
3:84b61e1b050c | 431 | |
Christopher Haster |
3:84b61e1b050c | 432 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 433 | */ |
Christopher Haster |
3:84b61e1b050c | 434 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 435 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 436 | attach(obj, method, b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 437 | } |
Christopher Haster |
3:84b61e1b050c | 438 | |
Christopher Haster |
3:84b61e1b050c | 439 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 440 | */ |
Christopher Haster |
3:84b61e1b050c | 441 | void attach(FuncPtr<R(B0, B1, B2, A0)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 442 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 443 | _b0 = b0; _b1 = b1; _b2 = b2; |
Christopher Haster |
3:84b61e1b050c | 444 | } |
Christopher Haster |
3:84b61e1b050c | 445 | |
Christopher Haster |
3:84b61e1b050c | 446 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 447 | */ |
Christopher Haster |
3:84b61e1b050c | 448 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 449 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 450 | attach(FuncPtr<R(B0, B1, B2, A0)>(obj, method), b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 451 | } |
Christopher Haster |
3:84b61e1b050c | 452 | |
Christopher Haster |
3:84b61e1b050c | 453 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 454 | */ |
Christopher Haster |
3:84b61e1b050c | 455 | R call(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 456 | return _func(_b0, _b1, _b2, a0); |
Christopher Haster |
3:84b61e1b050c | 457 | } |
Christopher Haster |
3:84b61e1b050c | 458 | |
Christopher Haster |
3:84b61e1b050c | 459 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 460 | */ |
Christopher Haster |
3:84b61e1b050c | 461 | R operator()(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 462 | return call(a0); |
Christopher Haster |
3:84b61e1b050c | 463 | } |
Christopher Haster |
3:84b61e1b050c | 464 | |
Christopher Haster |
3:84b61e1b050c | 465 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 466 | */ |
Christopher Haster |
8:71037a47492d | 467 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 468 | return _func; |
Christopher Haster |
3:84b61e1b050c | 469 | } |
Christopher Haster |
3:84b61e1b050c | 470 | |
Christopher Haster |
3:84b61e1b050c | 471 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 472 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 473 | */ |
Christopher Haster |
3:84b61e1b050c | 474 | static R thunk(void *func, A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 475 | return static_cast<Binder<R(B0, B1, B2, A0), B0, B1, B2>*>(func) |
Christopher Haster |
3:84b61e1b050c | 476 | ->call(a0); |
Christopher Haster |
3:84b61e1b050c | 477 | } |
Christopher Haster |
3:84b61e1b050c | 478 | |
Christopher Haster |
3:84b61e1b050c | 479 | private: |
Christopher Haster |
3:84b61e1b050c | 480 | FuncPtr<R(B0, B1, B2, A0)> _func; |
Christopher Haster |
3:84b61e1b050c | 481 | B0 _b0; B1 _b1; B2 _b2; |
Christopher Haster |
3:84b61e1b050c | 482 | }; |
Christopher Haster |
3:84b61e1b050c | 483 | |
Christopher Haster |
3:84b61e1b050c | 484 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 485 | */ |
Christopher Haster |
3:84b61e1b050c | 486 | template <typename R, typename B0, typename B1, typename A0, typename A1> |
Christopher Haster |
3:84b61e1b050c | 487 | class Binder<R(B0, B1, A0, A1), B0, B1> { |
Christopher Haster |
3:84b61e1b050c | 488 | public: |
Christopher Haster |
3:84b61e1b050c | 489 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 490 | */ |
Christopher Haster |
3:84b61e1b050c | 491 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 492 | |
Christopher Haster |
3:84b61e1b050c | 493 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 494 | */ |
Christopher Haster |
3:84b61e1b050c | 495 | Binder(FuncPtr<R(B0, B1, A0, A1)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 496 | attach(func, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 497 | } |
Christopher Haster |
3:84b61e1b050c | 498 | |
Christopher Haster |
3:84b61e1b050c | 499 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 500 | */ |
Christopher Haster |
3:84b61e1b050c | 501 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 502 | Binder(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 503 | attach(obj, method, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 504 | } |
Christopher Haster |
3:84b61e1b050c | 505 | |
Christopher Haster |
3:84b61e1b050c | 506 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 507 | */ |
Christopher Haster |
3:84b61e1b050c | 508 | void attach(FuncPtr<R(B0, B1, A0, A1)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 509 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 510 | _b0 = b0; _b1 = b1; |
Christopher Haster |
3:84b61e1b050c | 511 | } |
Christopher Haster |
3:84b61e1b050c | 512 | |
Christopher Haster |
3:84b61e1b050c | 513 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 514 | */ |
Christopher Haster |
3:84b61e1b050c | 515 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 516 | void attach(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 517 | attach(FuncPtr<R(B0, B1, A0, A1)>(obj, method), b0, b1); |
Christopher Haster |
3:84b61e1b050c | 518 | } |
Christopher Haster |
3:84b61e1b050c | 519 | |
Christopher Haster |
3:84b61e1b050c | 520 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 521 | */ |
Christopher Haster |
3:84b61e1b050c | 522 | R call(A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 523 | return _func(_b0, _b1, a0, a1); |
Christopher Haster |
3:84b61e1b050c | 524 | } |
Christopher Haster |
3:84b61e1b050c | 525 | |
Christopher Haster |
3:84b61e1b050c | 526 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 527 | */ |
Christopher Haster |
3:84b61e1b050c | 528 | R operator()(A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 529 | return call(a0, a1); |
Christopher Haster |
3:84b61e1b050c | 530 | } |
Christopher Haster |
3:84b61e1b050c | 531 | |
Christopher Haster |
3:84b61e1b050c | 532 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 533 | */ |
Christopher Haster |
8:71037a47492d | 534 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 535 | return _func; |
Christopher Haster |
3:84b61e1b050c | 536 | } |
Christopher Haster |
3:84b61e1b050c | 537 | |
Christopher Haster |
3:84b61e1b050c | 538 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 539 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 540 | */ |
Christopher Haster |
3:84b61e1b050c | 541 | static R thunk(void *func, A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 542 | return static_cast<Binder<R(B0, B1, A0, A1), B0, B1>*>(func) |
Christopher Haster |
3:84b61e1b050c | 543 | ->call(a0, a1); |
Christopher Haster |
3:84b61e1b050c | 544 | } |
Christopher Haster |
3:84b61e1b050c | 545 | |
Christopher Haster |
3:84b61e1b050c | 546 | private: |
Christopher Haster |
3:84b61e1b050c | 547 | FuncPtr<R(B0, B1, A0, A1)> _func; |
Christopher Haster |
3:84b61e1b050c | 548 | B0 _b0; B1 _b1; |
Christopher Haster |
3:84b61e1b050c | 549 | }; |
Christopher Haster |
3:84b61e1b050c | 550 | |
Christopher Haster |
3:84b61e1b050c | 551 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 552 | */ |
Christopher Haster |
3:84b61e1b050c | 553 | template <typename R, typename B0, typename A0, typename A1, typename A2> |
Christopher Haster |
3:84b61e1b050c | 554 | class Binder<R(B0, A0, A1, A2), B0> { |
Christopher Haster |
3:84b61e1b050c | 555 | public: |
Christopher Haster |
3:84b61e1b050c | 556 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 557 | */ |
Christopher Haster |
3:84b61e1b050c | 558 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 559 | |
Christopher Haster |
3:84b61e1b050c | 560 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 561 | */ |
Christopher Haster |
3:84b61e1b050c | 562 | Binder(FuncPtr<R(B0, A0, A1, A2)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 563 | attach(func, b0); |
Christopher Haster |
3:84b61e1b050c | 564 | } |
Christopher Haster |
3:84b61e1b050c | 565 | |
Christopher Haster |
3:84b61e1b050c | 566 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 567 | */ |
Christopher Haster |
3:84b61e1b050c | 568 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 569 | Binder(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 570 | attach(obj, method, b0); |
Christopher Haster |
3:84b61e1b050c | 571 | } |
Christopher Haster |
3:84b61e1b050c | 572 | |
Christopher Haster |
3:84b61e1b050c | 573 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 574 | */ |
Christopher Haster |
3:84b61e1b050c | 575 | void attach(FuncPtr<R(B0, A0, A1, A2)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 576 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 577 | _b0 = b0; |
Christopher Haster |
3:84b61e1b050c | 578 | } |
Christopher Haster |
3:84b61e1b050c | 579 | |
Christopher Haster |
3:84b61e1b050c | 580 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 581 | */ |
Christopher Haster |
3:84b61e1b050c | 582 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 583 | void attach(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 584 | attach(FuncPtr<R(B0, A0, A1, A2)>(obj, method), b0); |
Christopher Haster |
3:84b61e1b050c | 585 | } |
Christopher Haster |
3:84b61e1b050c | 586 | |
Christopher Haster |
3:84b61e1b050c | 587 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 588 | */ |
Christopher Haster |
3:84b61e1b050c | 589 | R call(A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
3:84b61e1b050c | 590 | return _func(_b0, a0, a1, a2); |
Christopher Haster |
3:84b61e1b050c | 591 | } |
Christopher Haster |
3:84b61e1b050c | 592 | |
Christopher Haster |
3:84b61e1b050c | 593 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 594 | */ |
Christopher Haster |
3:84b61e1b050c | 595 | R operator()(A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
3:84b61e1b050c | 596 | return call(a0, a1, a2); |
Christopher Haster |
3:84b61e1b050c | 597 | } |
Christopher Haster |
3:84b61e1b050c | 598 | |
Christopher Haster |
3:84b61e1b050c | 599 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 600 | */ |
Christopher Haster |
8:71037a47492d | 601 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 602 | return _func; |
Christopher Haster |
3:84b61e1b050c | 603 | } |
Christopher Haster |
3:84b61e1b050c | 604 | |
Christopher Haster |
3:84b61e1b050c | 605 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 606 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 607 | */ |
Christopher Haster |
3:84b61e1b050c | 608 | static R thunk(void *func, A0 a0, A1 a1, A2 a2) { |
Christopher Haster |
3:84b61e1b050c | 609 | return static_cast<Binder<R(B0, A0, A1, A2), B0>*>(func) |
Christopher Haster |
3:84b61e1b050c | 610 | ->call(a0, a1, a2); |
Christopher Haster |
3:84b61e1b050c | 611 | } |
Christopher Haster |
3:84b61e1b050c | 612 | |
Christopher Haster |
3:84b61e1b050c | 613 | private: |
Christopher Haster |
3:84b61e1b050c | 614 | FuncPtr<R(B0, A0, A1, A2)> _func; |
Christopher Haster |
3:84b61e1b050c | 615 | B0 _b0; |
Christopher Haster |
3:84b61e1b050c | 616 | }; |
Christopher Haster |
3:84b61e1b050c | 617 | |
Christopher Haster |
3:84b61e1b050c | 618 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 619 | */ |
Christopher Haster |
3:84b61e1b050c | 620 | template <typename R, typename B0, typename B1, typename B2> |
Christopher Haster |
3:84b61e1b050c | 621 | class Binder<R(B0, B1, B2), B0, B1, B2> { |
Christopher Haster |
3:84b61e1b050c | 622 | public: |
Christopher Haster |
3:84b61e1b050c | 623 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 624 | */ |
Christopher Haster |
3:84b61e1b050c | 625 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 626 | |
Christopher Haster |
3:84b61e1b050c | 627 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 628 | */ |
Christopher Haster |
3:84b61e1b050c | 629 | Binder(FuncPtr<R(B0, B1, B2)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 630 | attach(func, b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 631 | } |
Christopher Haster |
3:84b61e1b050c | 632 | |
Christopher Haster |
3:84b61e1b050c | 633 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 634 | */ |
Christopher Haster |
3:84b61e1b050c | 635 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 636 | Binder(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 637 | attach(obj, method, b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 638 | } |
Christopher Haster |
3:84b61e1b050c | 639 | |
Christopher Haster |
3:84b61e1b050c | 640 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 641 | */ |
Christopher Haster |
3:84b61e1b050c | 642 | void attach(FuncPtr<R(B0, B1, B2)> func, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 643 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 644 | _b0 = b0; _b1 = b1; _b2 = b2; |
Christopher Haster |
3:84b61e1b050c | 645 | } |
Christopher Haster |
3:84b61e1b050c | 646 | |
Christopher Haster |
3:84b61e1b050c | 647 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 648 | */ |
Christopher Haster |
3:84b61e1b050c | 649 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 650 | void attach(T *obj, M method, B0 b0, B1 b1, B2 b2) { |
Christopher Haster |
3:84b61e1b050c | 651 | attach(FuncPtr<R(B0, B1, B2)>(obj, method), b0, b1, b2); |
Christopher Haster |
3:84b61e1b050c | 652 | } |
Christopher Haster |
3:84b61e1b050c | 653 | |
Christopher Haster |
3:84b61e1b050c | 654 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 655 | */ |
Christopher Haster |
3:84b61e1b050c | 656 | R call() { |
Christopher Haster |
3:84b61e1b050c | 657 | return _func(_b0, _b1, _b2); |
Christopher Haster |
3:84b61e1b050c | 658 | } |
Christopher Haster |
3:84b61e1b050c | 659 | |
Christopher Haster |
3:84b61e1b050c | 660 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 661 | */ |
Christopher Haster |
3:84b61e1b050c | 662 | R operator()() { |
Christopher Haster |
3:84b61e1b050c | 663 | return call(); |
Christopher Haster |
3:84b61e1b050c | 664 | } |
Christopher Haster |
3:84b61e1b050c | 665 | |
Christopher Haster |
3:84b61e1b050c | 666 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 667 | */ |
Christopher Haster |
8:71037a47492d | 668 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 669 | return _func; |
Christopher Haster |
3:84b61e1b050c | 670 | } |
Christopher Haster |
3:84b61e1b050c | 671 | |
Christopher Haster |
3:84b61e1b050c | 672 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 673 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 674 | */ |
Christopher Haster |
3:84b61e1b050c | 675 | static R thunk(void *func) { |
Christopher Haster |
3:84b61e1b050c | 676 | return static_cast<Binder<R(B0, B1, B2), B0, B1, B2>*>(func) |
Christopher Haster |
3:84b61e1b050c | 677 | ->call(); |
Christopher Haster |
3:84b61e1b050c | 678 | } |
Christopher Haster |
3:84b61e1b050c | 679 | |
Christopher Haster |
3:84b61e1b050c | 680 | private: |
Christopher Haster |
3:84b61e1b050c | 681 | FuncPtr<R(B0, B1, B2)> _func; |
Christopher Haster |
3:84b61e1b050c | 682 | B0 _b0; B1 _b1; B2 _b2; |
Christopher Haster |
3:84b61e1b050c | 683 | }; |
Christopher Haster |
3:84b61e1b050c | 684 | |
Christopher Haster |
3:84b61e1b050c | 685 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 686 | */ |
Christopher Haster |
3:84b61e1b050c | 687 | template <typename R, typename B0, typename B1, typename A0> |
Christopher Haster |
3:84b61e1b050c | 688 | class Binder<R(B0, B1, A0), B0, B1> { |
Christopher Haster |
3:84b61e1b050c | 689 | public: |
Christopher Haster |
3:84b61e1b050c | 690 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 691 | */ |
Christopher Haster |
3:84b61e1b050c | 692 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 693 | |
Christopher Haster |
3:84b61e1b050c | 694 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 695 | */ |
Christopher Haster |
3:84b61e1b050c | 696 | Binder(FuncPtr<R(B0, B1, A0)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 697 | attach(func, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 698 | } |
Christopher Haster |
3:84b61e1b050c | 699 | |
Christopher Haster |
3:84b61e1b050c | 700 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 701 | */ |
Christopher Haster |
3:84b61e1b050c | 702 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 703 | Binder(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 704 | attach(obj, method, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 705 | } |
Christopher Haster |
3:84b61e1b050c | 706 | |
Christopher Haster |
3:84b61e1b050c | 707 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 708 | */ |
Christopher Haster |
3:84b61e1b050c | 709 | void attach(FuncPtr<R(B0, B1, A0)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 710 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 711 | _b0 = b0; _b1 = b1; |
Christopher Haster |
3:84b61e1b050c | 712 | } |
Christopher Haster |
3:84b61e1b050c | 713 | |
Christopher Haster |
3:84b61e1b050c | 714 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 715 | */ |
Christopher Haster |
3:84b61e1b050c | 716 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 717 | void attach(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 718 | attach(FuncPtr<R(B0, B1, A0)>(obj, method), b0, b1); |
Christopher Haster |
3:84b61e1b050c | 719 | } |
Christopher Haster |
3:84b61e1b050c | 720 | |
Christopher Haster |
3:84b61e1b050c | 721 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 722 | */ |
Christopher Haster |
3:84b61e1b050c | 723 | R call(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 724 | return _func(_b0, _b1, a0); |
Christopher Haster |
3:84b61e1b050c | 725 | } |
Christopher Haster |
3:84b61e1b050c | 726 | |
Christopher Haster |
3:84b61e1b050c | 727 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 728 | */ |
Christopher Haster |
3:84b61e1b050c | 729 | R operator()(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 730 | return call(a0); |
Christopher Haster |
3:84b61e1b050c | 731 | } |
Christopher Haster |
3:84b61e1b050c | 732 | |
Christopher Haster |
3:84b61e1b050c | 733 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 734 | */ |
Christopher Haster |
8:71037a47492d | 735 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 736 | return _func; |
Christopher Haster |
3:84b61e1b050c | 737 | } |
Christopher Haster |
3:84b61e1b050c | 738 | |
Christopher Haster |
3:84b61e1b050c | 739 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 740 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 741 | */ |
Christopher Haster |
3:84b61e1b050c | 742 | static R thunk(void *func, A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 743 | return static_cast<Binder<R(B0, B1, A0), B0, B1>*>(func) |
Christopher Haster |
3:84b61e1b050c | 744 | ->call(a0); |
Christopher Haster |
3:84b61e1b050c | 745 | } |
Christopher Haster |
3:84b61e1b050c | 746 | |
Christopher Haster |
3:84b61e1b050c | 747 | private: |
Christopher Haster |
3:84b61e1b050c | 748 | FuncPtr<R(B0, B1, A0)> _func; |
Christopher Haster |
3:84b61e1b050c | 749 | B0 _b0; B1 _b1; |
Christopher Haster |
3:84b61e1b050c | 750 | }; |
Christopher Haster |
3:84b61e1b050c | 751 | |
Christopher Haster |
3:84b61e1b050c | 752 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 753 | */ |
Christopher Haster |
3:84b61e1b050c | 754 | template <typename R, typename B0, typename A0, typename A1> |
Christopher Haster |
3:84b61e1b050c | 755 | class Binder<R(B0, A0, A1), B0> { |
Christopher Haster |
3:84b61e1b050c | 756 | public: |
Christopher Haster |
3:84b61e1b050c | 757 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 758 | */ |
Christopher Haster |
3:84b61e1b050c | 759 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 760 | |
Christopher Haster |
3:84b61e1b050c | 761 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 762 | */ |
Christopher Haster |
3:84b61e1b050c | 763 | Binder(FuncPtr<R(B0, A0, A1)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 764 | attach(func, b0); |
Christopher Haster |
3:84b61e1b050c | 765 | } |
Christopher Haster |
3:84b61e1b050c | 766 | |
Christopher Haster |
3:84b61e1b050c | 767 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 768 | */ |
Christopher Haster |
3:84b61e1b050c | 769 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 770 | Binder(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 771 | attach(obj, method, b0); |
Christopher Haster |
3:84b61e1b050c | 772 | } |
Christopher Haster |
3:84b61e1b050c | 773 | |
Christopher Haster |
3:84b61e1b050c | 774 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 775 | */ |
Christopher Haster |
3:84b61e1b050c | 776 | void attach(FuncPtr<R(B0, A0, A1)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 777 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 778 | _b0 = b0; |
Christopher Haster |
3:84b61e1b050c | 779 | } |
Christopher Haster |
3:84b61e1b050c | 780 | |
Christopher Haster |
3:84b61e1b050c | 781 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 782 | */ |
Christopher Haster |
3:84b61e1b050c | 783 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 784 | void attach(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 785 | attach(FuncPtr<R(B0, A0, A1)>(obj, method), b0); |
Christopher Haster |
3:84b61e1b050c | 786 | } |
Christopher Haster |
3:84b61e1b050c | 787 | |
Christopher Haster |
3:84b61e1b050c | 788 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 789 | */ |
Christopher Haster |
3:84b61e1b050c | 790 | R call(A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 791 | return _func(_b0, a0, a1); |
Christopher Haster |
3:84b61e1b050c | 792 | } |
Christopher Haster |
3:84b61e1b050c | 793 | |
Christopher Haster |
3:84b61e1b050c | 794 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 795 | */ |
Christopher Haster |
3:84b61e1b050c | 796 | R operator()(A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 797 | return call(a0, a1); |
Christopher Haster |
3:84b61e1b050c | 798 | } |
Christopher Haster |
3:84b61e1b050c | 799 | |
Christopher Haster |
3:84b61e1b050c | 800 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 801 | */ |
Christopher Haster |
8:71037a47492d | 802 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 803 | return _func; |
Christopher Haster |
3:84b61e1b050c | 804 | } |
Christopher Haster |
3:84b61e1b050c | 805 | |
Christopher Haster |
3:84b61e1b050c | 806 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 807 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 808 | */ |
Christopher Haster |
3:84b61e1b050c | 809 | static R thunk(void *func, A0 a0, A1 a1) { |
Christopher Haster |
3:84b61e1b050c | 810 | return static_cast<Binder<R(B0, A0, A1), B0>*>(func) |
Christopher Haster |
3:84b61e1b050c | 811 | ->call(a0, a1); |
Christopher Haster |
3:84b61e1b050c | 812 | } |
Christopher Haster |
3:84b61e1b050c | 813 | |
Christopher Haster |
3:84b61e1b050c | 814 | private: |
Christopher Haster |
3:84b61e1b050c | 815 | FuncPtr<R(B0, A0, A1)> _func; |
Christopher Haster |
3:84b61e1b050c | 816 | B0 _b0; |
Christopher Haster |
3:84b61e1b050c | 817 | }; |
Christopher Haster |
3:84b61e1b050c | 818 | |
Christopher Haster |
3:84b61e1b050c | 819 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 820 | */ |
Christopher Haster |
3:84b61e1b050c | 821 | template <typename R, typename B0, typename B1> |
Christopher Haster |
3:84b61e1b050c | 822 | class Binder<R(B0, B1), B0, B1> { |
Christopher Haster |
3:84b61e1b050c | 823 | public: |
Christopher Haster |
3:84b61e1b050c | 824 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 825 | */ |
Christopher Haster |
3:84b61e1b050c | 826 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 827 | |
Christopher Haster |
3:84b61e1b050c | 828 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 829 | */ |
Christopher Haster |
3:84b61e1b050c | 830 | Binder(FuncPtr<R(B0, B1)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 831 | attach(func, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 832 | } |
Christopher Haster |
3:84b61e1b050c | 833 | |
Christopher Haster |
3:84b61e1b050c | 834 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 835 | */ |
Christopher Haster |
3:84b61e1b050c | 836 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 837 | Binder(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 838 | attach(obj, method, b0, b1); |
Christopher Haster |
3:84b61e1b050c | 839 | } |
Christopher Haster |
3:84b61e1b050c | 840 | |
Christopher Haster |
3:84b61e1b050c | 841 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 842 | */ |
Christopher Haster |
3:84b61e1b050c | 843 | void attach(FuncPtr<R(B0, B1)> func, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 844 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 845 | _b0 = b0; _b1 = b1; |
Christopher Haster |
3:84b61e1b050c | 846 | } |
Christopher Haster |
3:84b61e1b050c | 847 | |
Christopher Haster |
3:84b61e1b050c | 848 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 849 | */ |
Christopher Haster |
3:84b61e1b050c | 850 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 851 | void attach(T *obj, M method, B0 b0, B1 b1) { |
Christopher Haster |
3:84b61e1b050c | 852 | attach(FuncPtr<R(B0, B1)>(obj, method), b0, b1); |
Christopher Haster |
3:84b61e1b050c | 853 | } |
Christopher Haster |
3:84b61e1b050c | 854 | |
Christopher Haster |
3:84b61e1b050c | 855 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 856 | */ |
Christopher Haster |
3:84b61e1b050c | 857 | R call() { |
Christopher Haster |
3:84b61e1b050c | 858 | return _func(_b0, _b1); |
Christopher Haster |
3:84b61e1b050c | 859 | } |
Christopher Haster |
3:84b61e1b050c | 860 | |
Christopher Haster |
3:84b61e1b050c | 861 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 862 | */ |
Christopher Haster |
3:84b61e1b050c | 863 | R operator()() { |
Christopher Haster |
3:84b61e1b050c | 864 | return call(); |
Christopher Haster |
3:84b61e1b050c | 865 | } |
Christopher Haster |
3:84b61e1b050c | 866 | |
Christopher Haster |
3:84b61e1b050c | 867 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 868 | */ |
Christopher Haster |
8:71037a47492d | 869 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 870 | return _func; |
Christopher Haster |
3:84b61e1b050c | 871 | } |
Christopher Haster |
3:84b61e1b050c | 872 | |
Christopher Haster |
3:84b61e1b050c | 873 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 874 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 875 | */ |
Christopher Haster |
3:84b61e1b050c | 876 | static R thunk(void *func) { |
Christopher Haster |
3:84b61e1b050c | 877 | return static_cast<Binder<R(B0, B1), B0, B1>*>(func) |
Christopher Haster |
3:84b61e1b050c | 878 | ->call(); |
Christopher Haster |
3:84b61e1b050c | 879 | } |
Christopher Haster |
3:84b61e1b050c | 880 | |
Christopher Haster |
3:84b61e1b050c | 881 | private: |
Christopher Haster |
3:84b61e1b050c | 882 | FuncPtr<R(B0, B1)> _func; |
Christopher Haster |
3:84b61e1b050c | 883 | B0 _b0; B1 _b1; |
Christopher Haster |
3:84b61e1b050c | 884 | }; |
Christopher Haster |
3:84b61e1b050c | 885 | |
Christopher Haster |
3:84b61e1b050c | 886 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 887 | */ |
Christopher Haster |
3:84b61e1b050c | 888 | template <typename R, typename B0, typename A0> |
Christopher Haster |
3:84b61e1b050c | 889 | class Binder<R(B0, A0), B0> { |
Christopher Haster |
3:84b61e1b050c | 890 | public: |
Christopher Haster |
3:84b61e1b050c | 891 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 892 | */ |
Christopher Haster |
3:84b61e1b050c | 893 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 894 | |
Christopher Haster |
3:84b61e1b050c | 895 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 896 | */ |
Christopher Haster |
3:84b61e1b050c | 897 | Binder(FuncPtr<R(B0, A0)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 898 | attach(func, b0); |
Christopher Haster |
3:84b61e1b050c | 899 | } |
Christopher Haster |
3:84b61e1b050c | 900 | |
Christopher Haster |
3:84b61e1b050c | 901 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 902 | */ |
Christopher Haster |
3:84b61e1b050c | 903 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 904 | Binder(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 905 | attach(obj, method, b0); |
Christopher Haster |
3:84b61e1b050c | 906 | } |
Christopher Haster |
3:84b61e1b050c | 907 | |
Christopher Haster |
3:84b61e1b050c | 908 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 909 | */ |
Christopher Haster |
3:84b61e1b050c | 910 | void attach(FuncPtr<R(B0, A0)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 911 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 912 | _b0 = b0; |
Christopher Haster |
3:84b61e1b050c | 913 | } |
Christopher Haster |
3:84b61e1b050c | 914 | |
Christopher Haster |
3:84b61e1b050c | 915 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 916 | */ |
Christopher Haster |
3:84b61e1b050c | 917 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 918 | void attach(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 919 | attach(FuncPtr<R(B0, A0)>(obj, method), b0); |
Christopher Haster |
3:84b61e1b050c | 920 | } |
Christopher Haster |
3:84b61e1b050c | 921 | |
Christopher Haster |
3:84b61e1b050c | 922 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 923 | */ |
Christopher Haster |
3:84b61e1b050c | 924 | R call(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 925 | return _func(_b0, a0); |
Christopher Haster |
3:84b61e1b050c | 926 | } |
Christopher Haster |
3:84b61e1b050c | 927 | |
Christopher Haster |
3:84b61e1b050c | 928 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 929 | */ |
Christopher Haster |
3:84b61e1b050c | 930 | R operator()(A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 931 | return call(a0); |
Christopher Haster |
3:84b61e1b050c | 932 | } |
Christopher Haster |
3:84b61e1b050c | 933 | |
Christopher Haster |
3:84b61e1b050c | 934 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 935 | */ |
Christopher Haster |
8:71037a47492d | 936 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 937 | return _func; |
Christopher Haster |
3:84b61e1b050c | 938 | } |
Christopher Haster |
3:84b61e1b050c | 939 | |
Christopher Haster |
3:84b61e1b050c | 940 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 941 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 942 | */ |
Christopher Haster |
3:84b61e1b050c | 943 | static R thunk(void *func, A0 a0) { |
Christopher Haster |
3:84b61e1b050c | 944 | return static_cast<Binder<R(B0, A0), B0>*>(func) |
Christopher Haster |
3:84b61e1b050c | 945 | ->call(a0); |
Christopher Haster |
3:84b61e1b050c | 946 | } |
Christopher Haster |
3:84b61e1b050c | 947 | |
Christopher Haster |
3:84b61e1b050c | 948 | private: |
Christopher Haster |
3:84b61e1b050c | 949 | FuncPtr<R(B0, A0)> _func; |
Christopher Haster |
3:84b61e1b050c | 950 | B0 _b0; |
Christopher Haster |
3:84b61e1b050c | 951 | }; |
Christopher Haster |
3:84b61e1b050c | 952 | |
Christopher Haster |
3:84b61e1b050c | 953 | /** Static function binding |
Christopher Haster |
3:84b61e1b050c | 954 | */ |
Christopher Haster |
3:84b61e1b050c | 955 | template <typename R, typename B0> |
Christopher Haster |
3:84b61e1b050c | 956 | class Binder<R(B0), B0> { |
Christopher Haster |
3:84b61e1b050c | 957 | public: |
Christopher Haster |
3:84b61e1b050c | 958 | /** Create an unbound Binder |
Christopher Haster |
3:84b61e1b050c | 959 | */ |
Christopher Haster |
3:84b61e1b050c | 960 | Binder() {} |
Christopher Haster |
3:84b61e1b050c | 961 | |
Christopher Haster |
3:84b61e1b050c | 962 | /** Create a Binder, binding arguments to a function |
Christopher Haster |
3:84b61e1b050c | 963 | */ |
Christopher Haster |
3:84b61e1b050c | 964 | Binder(FuncPtr<R(B0)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 965 | attach(func, b0); |
Christopher Haster |
3:84b61e1b050c | 966 | } |
Christopher Haster |
3:84b61e1b050c | 967 | |
Christopher Haster |
3:84b61e1b050c | 968 | /** Create a Binder, binding arguments to a method |
Christopher Haster |
3:84b61e1b050c | 969 | */ |
Christopher Haster |
3:84b61e1b050c | 970 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 971 | Binder(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 972 | attach(obj, method, b0); |
Christopher Haster |
3:84b61e1b050c | 973 | } |
Christopher Haster |
3:84b61e1b050c | 974 | |
Christopher Haster |
3:84b61e1b050c | 975 | /** Bind arguments to a function |
Christopher Haster |
3:84b61e1b050c | 976 | */ |
Christopher Haster |
3:84b61e1b050c | 977 | void attach(FuncPtr<R(B0)> func, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 978 | _func.attach(func); |
Christopher Haster |
3:84b61e1b050c | 979 | _b0 = b0; |
Christopher Haster |
3:84b61e1b050c | 980 | } |
Christopher Haster |
3:84b61e1b050c | 981 | |
Christopher Haster |
3:84b61e1b050c | 982 | /** Bind arguments to a method |
Christopher Haster |
3:84b61e1b050c | 983 | */ |
Christopher Haster |
3:84b61e1b050c | 984 | template <typename T, typename M> |
Christopher Haster |
3:84b61e1b050c | 985 | void attach(T *obj, M method, B0 b0) { |
Christopher Haster |
3:84b61e1b050c | 986 | attach(FuncPtr<R(B0)>(obj, method), b0); |
Christopher Haster |
3:84b61e1b050c | 987 | } |
Christopher Haster |
3:84b61e1b050c | 988 | |
Christopher Haster |
3:84b61e1b050c | 989 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 990 | */ |
Christopher Haster |
3:84b61e1b050c | 991 | R call() { |
Christopher Haster |
3:84b61e1b050c | 992 | return _func(_b0); |
Christopher Haster |
3:84b61e1b050c | 993 | } |
Christopher Haster |
3:84b61e1b050c | 994 | |
Christopher Haster |
3:84b61e1b050c | 995 | /** Call the bound function |
Christopher Haster |
3:84b61e1b050c | 996 | */ |
Christopher Haster |
3:84b61e1b050c | 997 | R operator()() { |
Christopher Haster |
3:84b61e1b050c | 998 | return call(); |
Christopher Haster |
3:84b61e1b050c | 999 | } |
Christopher Haster |
3:84b61e1b050c | 1000 | |
Christopher Haster |
3:84b61e1b050c | 1001 | /** Test if function has been bound |
Christopher Haster |
3:84b61e1b050c | 1002 | */ |
Christopher Haster |
8:71037a47492d | 1003 | operator bool() const { |
Christopher Haster |
4:627e19790dd9 | 1004 | return _func; |
Christopher Haster |
3:84b61e1b050c | 1005 | } |
Christopher Haster |
3:84b61e1b050c | 1006 | |
Christopher Haster |
3:84b61e1b050c | 1007 | /** Static thunk for passing as C-style function |
Christopher Haster |
3:84b61e1b050c | 1008 | * @param func Binder to call passed as void pointer |
Christopher Haster |
3:84b61e1b050c | 1009 | */ |
Christopher Haster |
3:84b61e1b050c | 1010 | static R thunk(void *func) { |
Christopher Haster |
3:84b61e1b050c | 1011 | return static_cast<Binder<R(B0), B0>*>(func) |
Christopher Haster |
3:84b61e1b050c | 1012 | ->call(); |
Christopher Haster |
3:84b61e1b050c | 1013 | } |
Christopher Haster |
3:84b61e1b050c | 1014 | |
Christopher Haster |
3:84b61e1b050c | 1015 | private: |
Christopher Haster |
3:84b61e1b050c | 1016 | FuncPtr<R(B0)> _func; |
Christopher Haster |
3:84b61e1b050c | 1017 | B0 _b0; |
Christopher Haster |
3:84b61e1b050c | 1018 | }; |
Christopher Haster |
3:84b61e1b050c | 1019 | |
Christopher Haster |
3:84b61e1b050c | 1020 | |
Christopher Haster |
3:84b61e1b050c | 1021 | #endif |