Preliminary main mbed library for nexpaq development
hal/api/Callback.h@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | /* mbed Microcontroller Library |
nexpaq | 0:6c56fb4bc5f0 | 2 | * Copyright (c) 2006-2015 ARM Limited |
nexpaq | 0:6c56fb4bc5f0 | 3 | * |
nexpaq | 0:6c56fb4bc5f0 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
nexpaq | 0:6c56fb4bc5f0 | 5 | * you may not use this file except in compliance with the License. |
nexpaq | 0:6c56fb4bc5f0 | 6 | * You may obtain a copy of the License at |
nexpaq | 0:6c56fb4bc5f0 | 7 | * |
nexpaq | 0:6c56fb4bc5f0 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
nexpaq | 0:6c56fb4bc5f0 | 9 | * |
nexpaq | 0:6c56fb4bc5f0 | 10 | * Unless required by applicable law or agreed to in writing, software |
nexpaq | 0:6c56fb4bc5f0 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
nexpaq | 0:6c56fb4bc5f0 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
nexpaq | 0:6c56fb4bc5f0 | 13 | * See the License for the specific language governing permissions and |
nexpaq | 0:6c56fb4bc5f0 | 14 | * limitations under the License. |
nexpaq | 0:6c56fb4bc5f0 | 15 | */ |
nexpaq | 0:6c56fb4bc5f0 | 16 | #ifndef MBED_CALLBACK_H |
nexpaq | 0:6c56fb4bc5f0 | 17 | #define MBED_CALLBACK_H |
nexpaq | 0:6c56fb4bc5f0 | 18 | |
nexpaq | 0:6c56fb4bc5f0 | 19 | #include <string.h> |
nexpaq | 0:6c56fb4bc5f0 | 20 | #include <stdint.h> |
nexpaq | 0:6c56fb4bc5f0 | 21 | #include "mbed_assert.h" |
nexpaq | 0:6c56fb4bc5f0 | 22 | |
nexpaq | 0:6c56fb4bc5f0 | 23 | namespace mbed { |
nexpaq | 0:6c56fb4bc5f0 | 24 | |
nexpaq | 0:6c56fb4bc5f0 | 25 | |
nexpaq | 0:6c56fb4bc5f0 | 26 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 27 | * |
nexpaq | 0:6c56fb4bc5f0 | 28 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 29 | */ |
nexpaq | 0:6c56fb4bc5f0 | 30 | template <typename F> |
nexpaq | 0:6c56fb4bc5f0 | 31 | class Callback; |
nexpaq | 0:6c56fb4bc5f0 | 32 | |
nexpaq | 0:6c56fb4bc5f0 | 33 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 34 | * |
nexpaq | 0:6c56fb4bc5f0 | 35 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 36 | */ |
nexpaq | 0:6c56fb4bc5f0 | 37 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 38 | class Callback<R()> { |
nexpaq | 0:6c56fb4bc5f0 | 39 | public: |
nexpaq | 0:6c56fb4bc5f0 | 40 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 41 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 42 | */ |
nexpaq | 0:6c56fb4bc5f0 | 43 | Callback(R (*func)() = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 44 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 45 | } |
nexpaq | 0:6c56fb4bc5f0 | 46 | |
nexpaq | 0:6c56fb4bc5f0 | 47 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 48 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 49 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 50 | */ |
nexpaq | 0:6c56fb4bc5f0 | 51 | Callback(void *obj, R (*func)(void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 52 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 53 | } |
nexpaq | 0:6c56fb4bc5f0 | 54 | |
nexpaq | 0:6c56fb4bc5f0 | 55 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 56 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 57 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 58 | */ |
nexpaq | 0:6c56fb4bc5f0 | 59 | Callback(const void *obj, R (*func)(const void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 60 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 61 | } |
nexpaq | 0:6c56fb4bc5f0 | 62 | |
nexpaq | 0:6c56fb4bc5f0 | 63 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 64 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 65 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 66 | */ |
nexpaq | 0:6c56fb4bc5f0 | 67 | Callback(volatile void *obj, R (*func)(volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 68 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 69 | } |
nexpaq | 0:6c56fb4bc5f0 | 70 | |
nexpaq | 0:6c56fb4bc5f0 | 71 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 72 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 73 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 74 | */ |
nexpaq | 0:6c56fb4bc5f0 | 75 | Callback(const volatile void *obj, R (*func)(const volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 76 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 77 | } |
nexpaq | 0:6c56fb4bc5f0 | 78 | |
nexpaq | 0:6c56fb4bc5f0 | 79 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 80 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 81 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 82 | */ |
nexpaq | 0:6c56fb4bc5f0 | 83 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 84 | Callback(T *obj, R (*func)(T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 85 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 86 | } |
nexpaq | 0:6c56fb4bc5f0 | 87 | |
nexpaq | 0:6c56fb4bc5f0 | 88 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 89 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 90 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 91 | */ |
nexpaq | 0:6c56fb4bc5f0 | 92 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 93 | Callback(const T *obj, R (*func)(const T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 94 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 95 | } |
nexpaq | 0:6c56fb4bc5f0 | 96 | |
nexpaq | 0:6c56fb4bc5f0 | 97 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 98 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 99 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 100 | */ |
nexpaq | 0:6c56fb4bc5f0 | 101 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 102 | Callback(volatile T *obj, R (*func)(volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 103 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 104 | } |
nexpaq | 0:6c56fb4bc5f0 | 105 | |
nexpaq | 0:6c56fb4bc5f0 | 106 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 107 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 108 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 109 | */ |
nexpaq | 0:6c56fb4bc5f0 | 110 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 111 | Callback(const volatile T *obj, R (*func)(const volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 112 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 113 | } |
nexpaq | 0:6c56fb4bc5f0 | 114 | |
nexpaq | 0:6c56fb4bc5f0 | 115 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 116 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 117 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 118 | */ |
nexpaq | 0:6c56fb4bc5f0 | 119 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 120 | Callback(T *obj, R (T::*func)()) { |
nexpaq | 0:6c56fb4bc5f0 | 121 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 122 | } |
nexpaq | 0:6c56fb4bc5f0 | 123 | |
nexpaq | 0:6c56fb4bc5f0 | 124 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 125 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 126 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 127 | */ |
nexpaq | 0:6c56fb4bc5f0 | 128 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 129 | Callback(const T *obj, R (T::*func)() const) { |
nexpaq | 0:6c56fb4bc5f0 | 130 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 131 | } |
nexpaq | 0:6c56fb4bc5f0 | 132 | |
nexpaq | 0:6c56fb4bc5f0 | 133 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 134 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 135 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 136 | */ |
nexpaq | 0:6c56fb4bc5f0 | 137 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 138 | Callback(volatile T *obj, R (T::*func)() volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 139 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 140 | } |
nexpaq | 0:6c56fb4bc5f0 | 141 | |
nexpaq | 0:6c56fb4bc5f0 | 142 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 143 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 144 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 145 | */ |
nexpaq | 0:6c56fb4bc5f0 | 146 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 147 | Callback(const volatile T *obj, R (T::*func)() const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 148 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 149 | } |
nexpaq | 0:6c56fb4bc5f0 | 150 | |
nexpaq | 0:6c56fb4bc5f0 | 151 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 152 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 153 | */ |
nexpaq | 0:6c56fb4bc5f0 | 154 | void attach(R (*func)()) { |
nexpaq | 0:6c56fb4bc5f0 | 155 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 156 | static R _thunk(void*, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 157 | return (*static_cast<R (*const *)()>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 158 | ); |
nexpaq | 0:6c56fb4bc5f0 | 159 | } |
nexpaq | 0:6c56fb4bc5f0 | 160 | }; |
nexpaq | 0:6c56fb4bc5f0 | 161 | |
nexpaq | 0:6c56fb4bc5f0 | 162 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 163 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 164 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 165 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 166 | } |
nexpaq | 0:6c56fb4bc5f0 | 167 | |
nexpaq | 0:6c56fb4bc5f0 | 168 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 169 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 170 | */ |
nexpaq | 0:6c56fb4bc5f0 | 171 | void attach(const Callback<R()> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 172 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 173 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 174 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 175 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 176 | } |
nexpaq | 0:6c56fb4bc5f0 | 177 | |
nexpaq | 0:6c56fb4bc5f0 | 178 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 179 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 180 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 181 | */ |
nexpaq | 0:6c56fb4bc5f0 | 182 | void attach(void *obj, R (*func)(void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 183 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 184 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 185 | return (*static_cast<R (*const *)(void*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 186 | (void*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 187 | } |
nexpaq | 0:6c56fb4bc5f0 | 188 | }; |
nexpaq | 0:6c56fb4bc5f0 | 189 | |
nexpaq | 0:6c56fb4bc5f0 | 190 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 191 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 192 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 193 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 194 | } |
nexpaq | 0:6c56fb4bc5f0 | 195 | |
nexpaq | 0:6c56fb4bc5f0 | 196 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 197 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 198 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 199 | */ |
nexpaq | 0:6c56fb4bc5f0 | 200 | void attach(const void *obj, R (*func)(const void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 201 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 202 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 203 | return (*static_cast<R (*const *)(const void*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 204 | (const void*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 205 | } |
nexpaq | 0:6c56fb4bc5f0 | 206 | }; |
nexpaq | 0:6c56fb4bc5f0 | 207 | |
nexpaq | 0:6c56fb4bc5f0 | 208 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 209 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 210 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 211 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 212 | } |
nexpaq | 0:6c56fb4bc5f0 | 213 | |
nexpaq | 0:6c56fb4bc5f0 | 214 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 215 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 216 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 217 | */ |
nexpaq | 0:6c56fb4bc5f0 | 218 | void attach(volatile void *obj, R (*func)(volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 219 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 220 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 221 | return (*static_cast<R (*const *)(volatile void*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 222 | (volatile void*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 223 | } |
nexpaq | 0:6c56fb4bc5f0 | 224 | }; |
nexpaq | 0:6c56fb4bc5f0 | 225 | |
nexpaq | 0:6c56fb4bc5f0 | 226 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 227 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 228 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 229 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 230 | } |
nexpaq | 0:6c56fb4bc5f0 | 231 | |
nexpaq | 0:6c56fb4bc5f0 | 232 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 233 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 234 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 235 | */ |
nexpaq | 0:6c56fb4bc5f0 | 236 | void attach(const volatile void *obj, R (*func)(const volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 237 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 238 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 239 | return (*static_cast<R (*const *)(const volatile void*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 240 | (const volatile void*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 241 | } |
nexpaq | 0:6c56fb4bc5f0 | 242 | }; |
nexpaq | 0:6c56fb4bc5f0 | 243 | |
nexpaq | 0:6c56fb4bc5f0 | 244 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 245 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 246 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 247 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 248 | } |
nexpaq | 0:6c56fb4bc5f0 | 249 | |
nexpaq | 0:6c56fb4bc5f0 | 250 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 251 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 252 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 253 | */ |
nexpaq | 0:6c56fb4bc5f0 | 254 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 255 | void attach(T *obj, R (*func)(T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 256 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 257 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 258 | return (*static_cast<R (*const *)(T*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 259 | (T*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 260 | } |
nexpaq | 0:6c56fb4bc5f0 | 261 | }; |
nexpaq | 0:6c56fb4bc5f0 | 262 | |
nexpaq | 0:6c56fb4bc5f0 | 263 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 264 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 265 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 266 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 267 | } |
nexpaq | 0:6c56fb4bc5f0 | 268 | |
nexpaq | 0:6c56fb4bc5f0 | 269 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 270 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 271 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 272 | */ |
nexpaq | 0:6c56fb4bc5f0 | 273 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 274 | void attach(const T *obj, R (*func)(const T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 275 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 276 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 277 | return (*static_cast<R (*const *)(const T*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 278 | (const T*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 279 | } |
nexpaq | 0:6c56fb4bc5f0 | 280 | }; |
nexpaq | 0:6c56fb4bc5f0 | 281 | |
nexpaq | 0:6c56fb4bc5f0 | 282 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 283 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 284 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 285 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 286 | } |
nexpaq | 0:6c56fb4bc5f0 | 287 | |
nexpaq | 0:6c56fb4bc5f0 | 288 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 289 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 290 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 291 | */ |
nexpaq | 0:6c56fb4bc5f0 | 292 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 293 | void attach(volatile T *obj, R (*func)(volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 294 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 295 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 296 | return (*static_cast<R (*const *)(volatile T*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 297 | (volatile T*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 298 | } |
nexpaq | 0:6c56fb4bc5f0 | 299 | }; |
nexpaq | 0:6c56fb4bc5f0 | 300 | |
nexpaq | 0:6c56fb4bc5f0 | 301 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 302 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 303 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 304 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 305 | } |
nexpaq | 0:6c56fb4bc5f0 | 306 | |
nexpaq | 0:6c56fb4bc5f0 | 307 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 308 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 309 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 310 | */ |
nexpaq | 0:6c56fb4bc5f0 | 311 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 312 | void attach(const volatile T *obj, R (*func)(const volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 313 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 314 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 315 | return (*static_cast<R (*const *)(const volatile T*)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 316 | (const volatile T*)obj); |
nexpaq | 0:6c56fb4bc5f0 | 317 | } |
nexpaq | 0:6c56fb4bc5f0 | 318 | }; |
nexpaq | 0:6c56fb4bc5f0 | 319 | |
nexpaq | 0:6c56fb4bc5f0 | 320 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 321 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 322 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 323 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 324 | } |
nexpaq | 0:6c56fb4bc5f0 | 325 | |
nexpaq | 0:6c56fb4bc5f0 | 326 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 327 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 328 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 329 | */ |
nexpaq | 0:6c56fb4bc5f0 | 330 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 331 | void attach(T *obj, R (T::*func)()) { |
nexpaq | 0:6c56fb4bc5f0 | 332 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 333 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 334 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 335 | (*static_cast<R (T::*const *)()>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 336 | ); |
nexpaq | 0:6c56fb4bc5f0 | 337 | } |
nexpaq | 0:6c56fb4bc5f0 | 338 | }; |
nexpaq | 0:6c56fb4bc5f0 | 339 | |
nexpaq | 0:6c56fb4bc5f0 | 340 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 341 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 342 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 343 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 344 | } |
nexpaq | 0:6c56fb4bc5f0 | 345 | |
nexpaq | 0:6c56fb4bc5f0 | 346 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 347 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 348 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 349 | */ |
nexpaq | 0:6c56fb4bc5f0 | 350 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 351 | void attach(const T *obj, R (T::*func)() const) { |
nexpaq | 0:6c56fb4bc5f0 | 352 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 353 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 354 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 355 | (*static_cast<R (T::*const *)() const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 356 | ); |
nexpaq | 0:6c56fb4bc5f0 | 357 | } |
nexpaq | 0:6c56fb4bc5f0 | 358 | }; |
nexpaq | 0:6c56fb4bc5f0 | 359 | |
nexpaq | 0:6c56fb4bc5f0 | 360 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 361 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 362 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 363 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 364 | } |
nexpaq | 0:6c56fb4bc5f0 | 365 | |
nexpaq | 0:6c56fb4bc5f0 | 366 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 367 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 368 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 369 | */ |
nexpaq | 0:6c56fb4bc5f0 | 370 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 371 | void attach(volatile T *obj, R (T::*func)() volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 372 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 373 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 374 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 375 | (*static_cast<R (T::*const *)() volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 376 | ); |
nexpaq | 0:6c56fb4bc5f0 | 377 | } |
nexpaq | 0:6c56fb4bc5f0 | 378 | }; |
nexpaq | 0:6c56fb4bc5f0 | 379 | |
nexpaq | 0:6c56fb4bc5f0 | 380 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 381 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 382 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 383 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 384 | } |
nexpaq | 0:6c56fb4bc5f0 | 385 | |
nexpaq | 0:6c56fb4bc5f0 | 386 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 387 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 388 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 389 | */ |
nexpaq | 0:6c56fb4bc5f0 | 390 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 391 | void attach(const volatile T *obj, R (T::*func)() const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 392 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 393 | static R _thunk(void *obj, const void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 394 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 395 | (*static_cast<R (T::*const *)() const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 396 | ); |
nexpaq | 0:6c56fb4bc5f0 | 397 | } |
nexpaq | 0:6c56fb4bc5f0 | 398 | }; |
nexpaq | 0:6c56fb4bc5f0 | 399 | |
nexpaq | 0:6c56fb4bc5f0 | 400 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 401 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 402 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 403 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 404 | } |
nexpaq | 0:6c56fb4bc5f0 | 405 | |
nexpaq | 0:6c56fb4bc5f0 | 406 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 407 | */ |
nexpaq | 0:6c56fb4bc5f0 | 408 | R call() const { |
nexpaq | 0:6c56fb4bc5f0 | 409 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 410 | return _thunk(_obj, &_func); |
nexpaq | 0:6c56fb4bc5f0 | 411 | } |
nexpaq | 0:6c56fb4bc5f0 | 412 | |
nexpaq | 0:6c56fb4bc5f0 | 413 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 414 | */ |
nexpaq | 0:6c56fb4bc5f0 | 415 | R operator()() const { |
nexpaq | 0:6c56fb4bc5f0 | 416 | return call(); |
nexpaq | 0:6c56fb4bc5f0 | 417 | } |
nexpaq | 0:6c56fb4bc5f0 | 418 | |
nexpaq | 0:6c56fb4bc5f0 | 419 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 420 | */ |
nexpaq | 0:6c56fb4bc5f0 | 421 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 422 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 423 | } |
nexpaq | 0:6c56fb4bc5f0 | 424 | |
nexpaq | 0:6c56fb4bc5f0 | 425 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 426 | */ |
nexpaq | 0:6c56fb4bc5f0 | 427 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 428 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 429 | } |
nexpaq | 0:6c56fb4bc5f0 | 430 | |
nexpaq | 0:6c56fb4bc5f0 | 431 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 432 | */ |
nexpaq | 0:6c56fb4bc5f0 | 433 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 434 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 435 | } |
nexpaq | 0:6c56fb4bc5f0 | 436 | |
nexpaq | 0:6c56fb4bc5f0 | 437 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 438 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 439 | */ |
nexpaq | 0:6c56fb4bc5f0 | 440 | static R thunk(void *func) { |
nexpaq | 0:6c56fb4bc5f0 | 441 | return static_cast<Callback<R()>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 442 | ); |
nexpaq | 0:6c56fb4bc5f0 | 443 | } |
nexpaq | 0:6c56fb4bc5f0 | 444 | |
nexpaq | 0:6c56fb4bc5f0 | 445 | private: |
nexpaq | 0:6c56fb4bc5f0 | 446 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 447 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 448 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 449 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 450 | union { |
nexpaq | 0:6c56fb4bc5f0 | 451 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 452 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 453 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 454 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 455 | |
nexpaq | 0:6c56fb4bc5f0 | 456 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 457 | |
nexpaq | 0:6c56fb4bc5f0 | 458 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 459 | R (*_thunk)(void*, const void*); |
nexpaq | 0:6c56fb4bc5f0 | 460 | }; |
nexpaq | 0:6c56fb4bc5f0 | 461 | |
nexpaq | 0:6c56fb4bc5f0 | 462 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 463 | * |
nexpaq | 0:6c56fb4bc5f0 | 464 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 465 | */ |
nexpaq | 0:6c56fb4bc5f0 | 466 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 467 | class Callback<R(A0)> { |
nexpaq | 0:6c56fb4bc5f0 | 468 | public: |
nexpaq | 0:6c56fb4bc5f0 | 469 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 470 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 471 | */ |
nexpaq | 0:6c56fb4bc5f0 | 472 | Callback(R (*func)(A0) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 473 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 474 | } |
nexpaq | 0:6c56fb4bc5f0 | 475 | |
nexpaq | 0:6c56fb4bc5f0 | 476 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 477 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 478 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 479 | */ |
nexpaq | 0:6c56fb4bc5f0 | 480 | Callback(void *obj, R (*func)(void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 481 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 482 | } |
nexpaq | 0:6c56fb4bc5f0 | 483 | |
nexpaq | 0:6c56fb4bc5f0 | 484 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 485 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 486 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 487 | */ |
nexpaq | 0:6c56fb4bc5f0 | 488 | Callback(const void *obj, R (*func)(const void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 489 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 490 | } |
nexpaq | 0:6c56fb4bc5f0 | 491 | |
nexpaq | 0:6c56fb4bc5f0 | 492 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 493 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 494 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 495 | */ |
nexpaq | 0:6c56fb4bc5f0 | 496 | Callback(volatile void *obj, R (*func)(volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 497 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 498 | } |
nexpaq | 0:6c56fb4bc5f0 | 499 | |
nexpaq | 0:6c56fb4bc5f0 | 500 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 501 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 502 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 503 | */ |
nexpaq | 0:6c56fb4bc5f0 | 504 | Callback(const volatile void *obj, R (*func)(const volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 505 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 506 | } |
nexpaq | 0:6c56fb4bc5f0 | 507 | |
nexpaq | 0:6c56fb4bc5f0 | 508 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 509 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 510 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 511 | */ |
nexpaq | 0:6c56fb4bc5f0 | 512 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 513 | Callback(T *obj, R (*func)(T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 514 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 515 | } |
nexpaq | 0:6c56fb4bc5f0 | 516 | |
nexpaq | 0:6c56fb4bc5f0 | 517 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 518 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 519 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 520 | */ |
nexpaq | 0:6c56fb4bc5f0 | 521 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 522 | Callback(const T *obj, R (*func)(const T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 523 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 524 | } |
nexpaq | 0:6c56fb4bc5f0 | 525 | |
nexpaq | 0:6c56fb4bc5f0 | 526 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 527 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 528 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 529 | */ |
nexpaq | 0:6c56fb4bc5f0 | 530 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 531 | Callback(volatile T *obj, R (*func)(volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 532 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 533 | } |
nexpaq | 0:6c56fb4bc5f0 | 534 | |
nexpaq | 0:6c56fb4bc5f0 | 535 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 536 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 537 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 538 | */ |
nexpaq | 0:6c56fb4bc5f0 | 539 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 540 | Callback(const volatile T *obj, R (*func)(const volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 541 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 542 | } |
nexpaq | 0:6c56fb4bc5f0 | 543 | |
nexpaq | 0:6c56fb4bc5f0 | 544 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 545 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 546 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 547 | */ |
nexpaq | 0:6c56fb4bc5f0 | 548 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 549 | Callback(T *obj, R (T::*func)(A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 550 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 551 | } |
nexpaq | 0:6c56fb4bc5f0 | 552 | |
nexpaq | 0:6c56fb4bc5f0 | 553 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 554 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 555 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 556 | */ |
nexpaq | 0:6c56fb4bc5f0 | 557 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 558 | Callback(const T *obj, R (T::*func)(A0) const) { |
nexpaq | 0:6c56fb4bc5f0 | 559 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 560 | } |
nexpaq | 0:6c56fb4bc5f0 | 561 | |
nexpaq | 0:6c56fb4bc5f0 | 562 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 563 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 564 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 565 | */ |
nexpaq | 0:6c56fb4bc5f0 | 566 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 567 | Callback(volatile T *obj, R (T::*func)(A0) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 568 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 569 | } |
nexpaq | 0:6c56fb4bc5f0 | 570 | |
nexpaq | 0:6c56fb4bc5f0 | 571 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 572 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 573 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 574 | */ |
nexpaq | 0:6c56fb4bc5f0 | 575 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 576 | Callback(const volatile T *obj, R (T::*func)(A0) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 577 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 578 | } |
nexpaq | 0:6c56fb4bc5f0 | 579 | |
nexpaq | 0:6c56fb4bc5f0 | 580 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 581 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 582 | */ |
nexpaq | 0:6c56fb4bc5f0 | 583 | void attach(R (*func)(A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 584 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 585 | static R _thunk(void*, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 586 | return (*static_cast<R (*const *)(A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 587 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 588 | } |
nexpaq | 0:6c56fb4bc5f0 | 589 | }; |
nexpaq | 0:6c56fb4bc5f0 | 590 | |
nexpaq | 0:6c56fb4bc5f0 | 591 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 592 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 593 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 594 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 595 | } |
nexpaq | 0:6c56fb4bc5f0 | 596 | |
nexpaq | 0:6c56fb4bc5f0 | 597 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 598 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 599 | */ |
nexpaq | 0:6c56fb4bc5f0 | 600 | void attach(const Callback<R(A0)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 601 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 602 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 603 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 604 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 605 | } |
nexpaq | 0:6c56fb4bc5f0 | 606 | |
nexpaq | 0:6c56fb4bc5f0 | 607 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 608 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 609 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 610 | */ |
nexpaq | 0:6c56fb4bc5f0 | 611 | void attach(void *obj, R (*func)(void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 612 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 613 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 614 | return (*static_cast<R (*const *)(void*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 615 | (void*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 616 | } |
nexpaq | 0:6c56fb4bc5f0 | 617 | }; |
nexpaq | 0:6c56fb4bc5f0 | 618 | |
nexpaq | 0:6c56fb4bc5f0 | 619 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 620 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 621 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 622 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 623 | } |
nexpaq | 0:6c56fb4bc5f0 | 624 | |
nexpaq | 0:6c56fb4bc5f0 | 625 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 626 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 627 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 628 | */ |
nexpaq | 0:6c56fb4bc5f0 | 629 | void attach(const void *obj, R (*func)(const void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 630 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 631 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 632 | return (*static_cast<R (*const *)(const void*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 633 | (const void*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 634 | } |
nexpaq | 0:6c56fb4bc5f0 | 635 | }; |
nexpaq | 0:6c56fb4bc5f0 | 636 | |
nexpaq | 0:6c56fb4bc5f0 | 637 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 638 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 639 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 640 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 641 | } |
nexpaq | 0:6c56fb4bc5f0 | 642 | |
nexpaq | 0:6c56fb4bc5f0 | 643 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 644 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 645 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 646 | */ |
nexpaq | 0:6c56fb4bc5f0 | 647 | void attach(volatile void *obj, R (*func)(volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 648 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 649 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 650 | return (*static_cast<R (*const *)(volatile void*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 651 | (volatile void*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 652 | } |
nexpaq | 0:6c56fb4bc5f0 | 653 | }; |
nexpaq | 0:6c56fb4bc5f0 | 654 | |
nexpaq | 0:6c56fb4bc5f0 | 655 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 656 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 657 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 658 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 659 | } |
nexpaq | 0:6c56fb4bc5f0 | 660 | |
nexpaq | 0:6c56fb4bc5f0 | 661 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 662 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 663 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 664 | */ |
nexpaq | 0:6c56fb4bc5f0 | 665 | void attach(const volatile void *obj, R (*func)(const volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 666 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 667 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 668 | return (*static_cast<R (*const *)(const volatile void*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 669 | (const volatile void*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 670 | } |
nexpaq | 0:6c56fb4bc5f0 | 671 | }; |
nexpaq | 0:6c56fb4bc5f0 | 672 | |
nexpaq | 0:6c56fb4bc5f0 | 673 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 674 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 675 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 676 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 677 | } |
nexpaq | 0:6c56fb4bc5f0 | 678 | |
nexpaq | 0:6c56fb4bc5f0 | 679 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 680 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 681 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 682 | */ |
nexpaq | 0:6c56fb4bc5f0 | 683 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 684 | void attach(T *obj, R (*func)(T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 685 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 686 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 687 | return (*static_cast<R (*const *)(T*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 688 | (T*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 689 | } |
nexpaq | 0:6c56fb4bc5f0 | 690 | }; |
nexpaq | 0:6c56fb4bc5f0 | 691 | |
nexpaq | 0:6c56fb4bc5f0 | 692 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 693 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 694 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 695 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 696 | } |
nexpaq | 0:6c56fb4bc5f0 | 697 | |
nexpaq | 0:6c56fb4bc5f0 | 698 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 699 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 700 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 701 | */ |
nexpaq | 0:6c56fb4bc5f0 | 702 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 703 | void attach(const T *obj, R (*func)(const T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 704 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 705 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 706 | return (*static_cast<R (*const *)(const T*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 707 | (const T*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 708 | } |
nexpaq | 0:6c56fb4bc5f0 | 709 | }; |
nexpaq | 0:6c56fb4bc5f0 | 710 | |
nexpaq | 0:6c56fb4bc5f0 | 711 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 712 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 713 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 714 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 715 | } |
nexpaq | 0:6c56fb4bc5f0 | 716 | |
nexpaq | 0:6c56fb4bc5f0 | 717 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 718 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 719 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 720 | */ |
nexpaq | 0:6c56fb4bc5f0 | 721 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 722 | void attach(volatile T *obj, R (*func)(volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 723 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 724 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 725 | return (*static_cast<R (*const *)(volatile T*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 726 | (volatile T*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 727 | } |
nexpaq | 0:6c56fb4bc5f0 | 728 | }; |
nexpaq | 0:6c56fb4bc5f0 | 729 | |
nexpaq | 0:6c56fb4bc5f0 | 730 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 731 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 732 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 733 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 734 | } |
nexpaq | 0:6c56fb4bc5f0 | 735 | |
nexpaq | 0:6c56fb4bc5f0 | 736 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 737 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 738 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 739 | */ |
nexpaq | 0:6c56fb4bc5f0 | 740 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 741 | void attach(const volatile T *obj, R (*func)(const volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 742 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 743 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 744 | return (*static_cast<R (*const *)(const volatile T*, A0)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 745 | (const volatile T*)obj, a0); |
nexpaq | 0:6c56fb4bc5f0 | 746 | } |
nexpaq | 0:6c56fb4bc5f0 | 747 | }; |
nexpaq | 0:6c56fb4bc5f0 | 748 | |
nexpaq | 0:6c56fb4bc5f0 | 749 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 750 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 751 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 752 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 753 | } |
nexpaq | 0:6c56fb4bc5f0 | 754 | |
nexpaq | 0:6c56fb4bc5f0 | 755 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 756 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 757 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 758 | */ |
nexpaq | 0:6c56fb4bc5f0 | 759 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 760 | void attach(T *obj, R (T::*func)(A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 761 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 762 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 763 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 764 | (*static_cast<R (T::*const *)(A0)>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 765 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 766 | } |
nexpaq | 0:6c56fb4bc5f0 | 767 | }; |
nexpaq | 0:6c56fb4bc5f0 | 768 | |
nexpaq | 0:6c56fb4bc5f0 | 769 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 770 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 771 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 772 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 773 | } |
nexpaq | 0:6c56fb4bc5f0 | 774 | |
nexpaq | 0:6c56fb4bc5f0 | 775 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 776 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 777 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 778 | */ |
nexpaq | 0:6c56fb4bc5f0 | 779 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 780 | void attach(const T *obj, R (T::*func)(A0) const) { |
nexpaq | 0:6c56fb4bc5f0 | 781 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 782 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 783 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 784 | (*static_cast<R (T::*const *)(A0) const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 785 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 786 | } |
nexpaq | 0:6c56fb4bc5f0 | 787 | }; |
nexpaq | 0:6c56fb4bc5f0 | 788 | |
nexpaq | 0:6c56fb4bc5f0 | 789 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 790 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 791 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 792 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 793 | } |
nexpaq | 0:6c56fb4bc5f0 | 794 | |
nexpaq | 0:6c56fb4bc5f0 | 795 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 796 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 797 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 798 | */ |
nexpaq | 0:6c56fb4bc5f0 | 799 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 800 | void attach(volatile T *obj, R (T::*func)(A0) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 801 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 802 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 803 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 804 | (*static_cast<R (T::*const *)(A0) volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 805 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 806 | } |
nexpaq | 0:6c56fb4bc5f0 | 807 | }; |
nexpaq | 0:6c56fb4bc5f0 | 808 | |
nexpaq | 0:6c56fb4bc5f0 | 809 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 810 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 811 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 812 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 813 | } |
nexpaq | 0:6c56fb4bc5f0 | 814 | |
nexpaq | 0:6c56fb4bc5f0 | 815 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 816 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 817 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 818 | */ |
nexpaq | 0:6c56fb4bc5f0 | 819 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 820 | void attach(const volatile T *obj, R (T::*func)(A0) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 821 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 822 | static R _thunk(void *obj, const void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 823 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 824 | (*static_cast<R (T::*const *)(A0) const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 825 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 826 | } |
nexpaq | 0:6c56fb4bc5f0 | 827 | }; |
nexpaq | 0:6c56fb4bc5f0 | 828 | |
nexpaq | 0:6c56fb4bc5f0 | 829 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 830 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 831 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 832 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 833 | } |
nexpaq | 0:6c56fb4bc5f0 | 834 | |
nexpaq | 0:6c56fb4bc5f0 | 835 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 836 | */ |
nexpaq | 0:6c56fb4bc5f0 | 837 | R call(A0 a0) const { |
nexpaq | 0:6c56fb4bc5f0 | 838 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 839 | return _thunk(_obj, &_func, a0); |
nexpaq | 0:6c56fb4bc5f0 | 840 | } |
nexpaq | 0:6c56fb4bc5f0 | 841 | |
nexpaq | 0:6c56fb4bc5f0 | 842 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 843 | */ |
nexpaq | 0:6c56fb4bc5f0 | 844 | R operator()(A0 a0) const { |
nexpaq | 0:6c56fb4bc5f0 | 845 | return call(a0); |
nexpaq | 0:6c56fb4bc5f0 | 846 | } |
nexpaq | 0:6c56fb4bc5f0 | 847 | |
nexpaq | 0:6c56fb4bc5f0 | 848 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 849 | */ |
nexpaq | 0:6c56fb4bc5f0 | 850 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 851 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 852 | } |
nexpaq | 0:6c56fb4bc5f0 | 853 | |
nexpaq | 0:6c56fb4bc5f0 | 854 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 855 | */ |
nexpaq | 0:6c56fb4bc5f0 | 856 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 857 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 858 | } |
nexpaq | 0:6c56fb4bc5f0 | 859 | |
nexpaq | 0:6c56fb4bc5f0 | 860 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 861 | */ |
nexpaq | 0:6c56fb4bc5f0 | 862 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 863 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 864 | } |
nexpaq | 0:6c56fb4bc5f0 | 865 | |
nexpaq | 0:6c56fb4bc5f0 | 866 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 867 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 868 | */ |
nexpaq | 0:6c56fb4bc5f0 | 869 | static R thunk(void *func, A0 a0) { |
nexpaq | 0:6c56fb4bc5f0 | 870 | return static_cast<Callback<R(A0)>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 871 | a0); |
nexpaq | 0:6c56fb4bc5f0 | 872 | } |
nexpaq | 0:6c56fb4bc5f0 | 873 | |
nexpaq | 0:6c56fb4bc5f0 | 874 | private: |
nexpaq | 0:6c56fb4bc5f0 | 875 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 876 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 877 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 878 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 879 | union { |
nexpaq | 0:6c56fb4bc5f0 | 880 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 881 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 882 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 883 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 884 | |
nexpaq | 0:6c56fb4bc5f0 | 885 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 886 | |
nexpaq | 0:6c56fb4bc5f0 | 887 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 888 | R (*_thunk)(void*, const void*, A0); |
nexpaq | 0:6c56fb4bc5f0 | 889 | }; |
nexpaq | 0:6c56fb4bc5f0 | 890 | |
nexpaq | 0:6c56fb4bc5f0 | 891 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 892 | * |
nexpaq | 0:6c56fb4bc5f0 | 893 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 894 | */ |
nexpaq | 0:6c56fb4bc5f0 | 895 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 896 | class Callback<R(A0, A1)> { |
nexpaq | 0:6c56fb4bc5f0 | 897 | public: |
nexpaq | 0:6c56fb4bc5f0 | 898 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 899 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 900 | */ |
nexpaq | 0:6c56fb4bc5f0 | 901 | Callback(R (*func)(A0, A1) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 902 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 903 | } |
nexpaq | 0:6c56fb4bc5f0 | 904 | |
nexpaq | 0:6c56fb4bc5f0 | 905 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 906 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 907 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 908 | */ |
nexpaq | 0:6c56fb4bc5f0 | 909 | Callback(void *obj, R (*func)(void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 910 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 911 | } |
nexpaq | 0:6c56fb4bc5f0 | 912 | |
nexpaq | 0:6c56fb4bc5f0 | 913 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 914 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 915 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 916 | */ |
nexpaq | 0:6c56fb4bc5f0 | 917 | Callback(const void *obj, R (*func)(const void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 918 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 919 | } |
nexpaq | 0:6c56fb4bc5f0 | 920 | |
nexpaq | 0:6c56fb4bc5f0 | 921 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 922 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 923 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 924 | */ |
nexpaq | 0:6c56fb4bc5f0 | 925 | Callback(volatile void *obj, R (*func)(volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 926 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 927 | } |
nexpaq | 0:6c56fb4bc5f0 | 928 | |
nexpaq | 0:6c56fb4bc5f0 | 929 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 930 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 931 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 932 | */ |
nexpaq | 0:6c56fb4bc5f0 | 933 | Callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 934 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 935 | } |
nexpaq | 0:6c56fb4bc5f0 | 936 | |
nexpaq | 0:6c56fb4bc5f0 | 937 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 938 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 939 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 940 | */ |
nexpaq | 0:6c56fb4bc5f0 | 941 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 942 | Callback(T *obj, R (*func)(T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 943 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 944 | } |
nexpaq | 0:6c56fb4bc5f0 | 945 | |
nexpaq | 0:6c56fb4bc5f0 | 946 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 947 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 948 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 949 | */ |
nexpaq | 0:6c56fb4bc5f0 | 950 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 951 | Callback(const T *obj, R (*func)(const T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 952 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 953 | } |
nexpaq | 0:6c56fb4bc5f0 | 954 | |
nexpaq | 0:6c56fb4bc5f0 | 955 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 956 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 957 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 958 | */ |
nexpaq | 0:6c56fb4bc5f0 | 959 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 960 | Callback(volatile T *obj, R (*func)(volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 961 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 962 | } |
nexpaq | 0:6c56fb4bc5f0 | 963 | |
nexpaq | 0:6c56fb4bc5f0 | 964 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 965 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 966 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 967 | */ |
nexpaq | 0:6c56fb4bc5f0 | 968 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 969 | Callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 970 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 971 | } |
nexpaq | 0:6c56fb4bc5f0 | 972 | |
nexpaq | 0:6c56fb4bc5f0 | 973 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 974 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 975 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 976 | */ |
nexpaq | 0:6c56fb4bc5f0 | 977 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 978 | Callback(T *obj, R (T::*func)(A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 979 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 980 | } |
nexpaq | 0:6c56fb4bc5f0 | 981 | |
nexpaq | 0:6c56fb4bc5f0 | 982 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 983 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 984 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 985 | */ |
nexpaq | 0:6c56fb4bc5f0 | 986 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 987 | Callback(const T *obj, R (T::*func)(A0, A1) const) { |
nexpaq | 0:6c56fb4bc5f0 | 988 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 989 | } |
nexpaq | 0:6c56fb4bc5f0 | 990 | |
nexpaq | 0:6c56fb4bc5f0 | 991 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 992 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 993 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 994 | */ |
nexpaq | 0:6c56fb4bc5f0 | 995 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 996 | Callback(volatile T *obj, R (T::*func)(A0, A1) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 997 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 998 | } |
nexpaq | 0:6c56fb4bc5f0 | 999 | |
nexpaq | 0:6c56fb4bc5f0 | 1000 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1001 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1002 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1003 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1004 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1005 | Callback(const volatile T *obj, R (T::*func)(A0, A1) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1006 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1007 | } |
nexpaq | 0:6c56fb4bc5f0 | 1008 | |
nexpaq | 0:6c56fb4bc5f0 | 1009 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 1010 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1011 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1012 | void attach(R (*func)(A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1013 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1014 | static R _thunk(void*, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1015 | return (*static_cast<R (*const *)(A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1016 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1017 | } |
nexpaq | 0:6c56fb4bc5f0 | 1018 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1019 | |
nexpaq | 0:6c56fb4bc5f0 | 1020 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1021 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1022 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 1023 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 1024 | } |
nexpaq | 0:6c56fb4bc5f0 | 1025 | |
nexpaq | 0:6c56fb4bc5f0 | 1026 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 1027 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 1028 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1029 | void attach(const Callback<R(A0, A1)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 1030 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1031 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1032 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 1033 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1034 | } |
nexpaq | 0:6c56fb4bc5f0 | 1035 | |
nexpaq | 0:6c56fb4bc5f0 | 1036 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1037 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1038 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1039 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1040 | void attach(void *obj, R (*func)(void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1041 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1042 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1043 | return (*static_cast<R (*const *)(void*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1044 | (void*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1045 | } |
nexpaq | 0:6c56fb4bc5f0 | 1046 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1047 | |
nexpaq | 0:6c56fb4bc5f0 | 1048 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1049 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1050 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1051 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1052 | } |
nexpaq | 0:6c56fb4bc5f0 | 1053 | |
nexpaq | 0:6c56fb4bc5f0 | 1054 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1055 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1056 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1057 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1058 | void attach(const void *obj, R (*func)(const void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1059 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1060 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1061 | return (*static_cast<R (*const *)(const void*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1062 | (const void*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1063 | } |
nexpaq | 0:6c56fb4bc5f0 | 1064 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1065 | |
nexpaq | 0:6c56fb4bc5f0 | 1066 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1067 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1068 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1069 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1070 | } |
nexpaq | 0:6c56fb4bc5f0 | 1071 | |
nexpaq | 0:6c56fb4bc5f0 | 1072 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1073 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1074 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1075 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1076 | void attach(volatile void *obj, R (*func)(volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1077 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1078 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1079 | return (*static_cast<R (*const *)(volatile void*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1080 | (volatile void*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1081 | } |
nexpaq | 0:6c56fb4bc5f0 | 1082 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1083 | |
nexpaq | 0:6c56fb4bc5f0 | 1084 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1085 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1086 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1087 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1088 | } |
nexpaq | 0:6c56fb4bc5f0 | 1089 | |
nexpaq | 0:6c56fb4bc5f0 | 1090 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1091 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1092 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1093 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1094 | void attach(const volatile void *obj, R (*func)(const volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1095 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1096 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1097 | return (*static_cast<R (*const *)(const volatile void*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1098 | (const volatile void*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1099 | } |
nexpaq | 0:6c56fb4bc5f0 | 1100 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1101 | |
nexpaq | 0:6c56fb4bc5f0 | 1102 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1103 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1104 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1105 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1106 | } |
nexpaq | 0:6c56fb4bc5f0 | 1107 | |
nexpaq | 0:6c56fb4bc5f0 | 1108 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1109 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1110 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1111 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1112 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1113 | void attach(T *obj, R (*func)(T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1114 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1115 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1116 | return (*static_cast<R (*const *)(T*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1117 | (T*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1118 | } |
nexpaq | 0:6c56fb4bc5f0 | 1119 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1120 | |
nexpaq | 0:6c56fb4bc5f0 | 1121 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1122 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1123 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1124 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1125 | } |
nexpaq | 0:6c56fb4bc5f0 | 1126 | |
nexpaq | 0:6c56fb4bc5f0 | 1127 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1128 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1129 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1130 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1131 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1132 | void attach(const T *obj, R (*func)(const T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1133 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1134 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1135 | return (*static_cast<R (*const *)(const T*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1136 | (const T*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1137 | } |
nexpaq | 0:6c56fb4bc5f0 | 1138 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1139 | |
nexpaq | 0:6c56fb4bc5f0 | 1140 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1141 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1142 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1143 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1144 | } |
nexpaq | 0:6c56fb4bc5f0 | 1145 | |
nexpaq | 0:6c56fb4bc5f0 | 1146 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1147 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1148 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1149 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1150 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1151 | void attach(volatile T *obj, R (*func)(volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1152 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1153 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1154 | return (*static_cast<R (*const *)(volatile T*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1155 | (volatile T*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1156 | } |
nexpaq | 0:6c56fb4bc5f0 | 1157 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1158 | |
nexpaq | 0:6c56fb4bc5f0 | 1159 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1160 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1161 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1162 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1163 | } |
nexpaq | 0:6c56fb4bc5f0 | 1164 | |
nexpaq | 0:6c56fb4bc5f0 | 1165 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1166 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1167 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1168 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1169 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1170 | void attach(const volatile T *obj, R (*func)(const volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1171 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1172 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1173 | return (*static_cast<R (*const *)(const volatile T*, A0, A1)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1174 | (const volatile T*)obj, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1175 | } |
nexpaq | 0:6c56fb4bc5f0 | 1176 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1177 | |
nexpaq | 0:6c56fb4bc5f0 | 1178 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1179 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1180 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1181 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1182 | } |
nexpaq | 0:6c56fb4bc5f0 | 1183 | |
nexpaq | 0:6c56fb4bc5f0 | 1184 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1185 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1186 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1187 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1188 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1189 | void attach(T *obj, R (T::*func)(A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 1190 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1191 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1192 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1193 | (*static_cast<R (T::*const *)(A0, A1)>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1194 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1195 | } |
nexpaq | 0:6c56fb4bc5f0 | 1196 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1197 | |
nexpaq | 0:6c56fb4bc5f0 | 1198 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1199 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1200 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1201 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1202 | } |
nexpaq | 0:6c56fb4bc5f0 | 1203 | |
nexpaq | 0:6c56fb4bc5f0 | 1204 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1205 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1206 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1207 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1208 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1209 | void attach(const T *obj, R (T::*func)(A0, A1) const) { |
nexpaq | 0:6c56fb4bc5f0 | 1210 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1211 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1212 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1213 | (*static_cast<R (T::*const *)(A0, A1) const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1214 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1215 | } |
nexpaq | 0:6c56fb4bc5f0 | 1216 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1217 | |
nexpaq | 0:6c56fb4bc5f0 | 1218 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1219 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1220 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1221 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1222 | } |
nexpaq | 0:6c56fb4bc5f0 | 1223 | |
nexpaq | 0:6c56fb4bc5f0 | 1224 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1225 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1226 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1227 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1228 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1229 | void attach(volatile T *obj, R (T::*func)(A0, A1) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1230 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1231 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1232 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1233 | (*static_cast<R (T::*const *)(A0, A1) volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1234 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1235 | } |
nexpaq | 0:6c56fb4bc5f0 | 1236 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1237 | |
nexpaq | 0:6c56fb4bc5f0 | 1238 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1239 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1240 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1241 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1242 | } |
nexpaq | 0:6c56fb4bc5f0 | 1243 | |
nexpaq | 0:6c56fb4bc5f0 | 1244 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1245 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1246 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1247 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1248 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1249 | void attach(const volatile T *obj, R (T::*func)(A0, A1) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1250 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1251 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1252 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1253 | (*static_cast<R (T::*const *)(A0, A1) const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1254 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1255 | } |
nexpaq | 0:6c56fb4bc5f0 | 1256 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1257 | |
nexpaq | 0:6c56fb4bc5f0 | 1258 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1259 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1260 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1261 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1262 | } |
nexpaq | 0:6c56fb4bc5f0 | 1263 | |
nexpaq | 0:6c56fb4bc5f0 | 1264 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 1265 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1266 | R call(A0 a0, A1 a1) const { |
nexpaq | 0:6c56fb4bc5f0 | 1267 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 1268 | return _thunk(_obj, &_func, a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1269 | } |
nexpaq | 0:6c56fb4bc5f0 | 1270 | |
nexpaq | 0:6c56fb4bc5f0 | 1271 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 1272 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1273 | R operator()(A0 a0, A1 a1) const { |
nexpaq | 0:6c56fb4bc5f0 | 1274 | return call(a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1275 | } |
nexpaq | 0:6c56fb4bc5f0 | 1276 | |
nexpaq | 0:6c56fb4bc5f0 | 1277 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 1278 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1279 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 1280 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1281 | } |
nexpaq | 0:6c56fb4bc5f0 | 1282 | |
nexpaq | 0:6c56fb4bc5f0 | 1283 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 1284 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1285 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 1286 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 1287 | } |
nexpaq | 0:6c56fb4bc5f0 | 1288 | |
nexpaq | 0:6c56fb4bc5f0 | 1289 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 1290 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1291 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 1292 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 1293 | } |
nexpaq | 0:6c56fb4bc5f0 | 1294 | |
nexpaq | 0:6c56fb4bc5f0 | 1295 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 1296 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 1297 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1298 | static R thunk(void *func, A0 a0, A1 a1) { |
nexpaq | 0:6c56fb4bc5f0 | 1299 | return static_cast<Callback<R(A0, A1)>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 1300 | a0, a1); |
nexpaq | 0:6c56fb4bc5f0 | 1301 | } |
nexpaq | 0:6c56fb4bc5f0 | 1302 | |
nexpaq | 0:6c56fb4bc5f0 | 1303 | private: |
nexpaq | 0:6c56fb4bc5f0 | 1304 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 1305 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 1306 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 1307 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 1308 | union { |
nexpaq | 0:6c56fb4bc5f0 | 1309 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 1310 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 1311 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 1312 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 1313 | |
nexpaq | 0:6c56fb4bc5f0 | 1314 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 1315 | |
nexpaq | 0:6c56fb4bc5f0 | 1316 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 1317 | R (*_thunk)(void*, const void*, A0, A1); |
nexpaq | 0:6c56fb4bc5f0 | 1318 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1319 | |
nexpaq | 0:6c56fb4bc5f0 | 1320 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 1321 | * |
nexpaq | 0:6c56fb4bc5f0 | 1322 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 1323 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1324 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 1325 | class Callback<R(A0, A1, A2)> { |
nexpaq | 0:6c56fb4bc5f0 | 1326 | public: |
nexpaq | 0:6c56fb4bc5f0 | 1327 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 1328 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1329 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1330 | Callback(R (*func)(A0, A1, A2) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 1331 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 1332 | } |
nexpaq | 0:6c56fb4bc5f0 | 1333 | |
nexpaq | 0:6c56fb4bc5f0 | 1334 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1335 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1336 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1337 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1338 | Callback(void *obj, R (*func)(void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1339 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1340 | } |
nexpaq | 0:6c56fb4bc5f0 | 1341 | |
nexpaq | 0:6c56fb4bc5f0 | 1342 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1343 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1344 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1345 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1346 | Callback(const void *obj, R (*func)(const void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1347 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1348 | } |
nexpaq | 0:6c56fb4bc5f0 | 1349 | |
nexpaq | 0:6c56fb4bc5f0 | 1350 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1351 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1352 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1353 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1354 | Callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1355 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1356 | } |
nexpaq | 0:6c56fb4bc5f0 | 1357 | |
nexpaq | 0:6c56fb4bc5f0 | 1358 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1359 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1360 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1361 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1362 | Callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1363 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1364 | } |
nexpaq | 0:6c56fb4bc5f0 | 1365 | |
nexpaq | 0:6c56fb4bc5f0 | 1366 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1367 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1368 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1369 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1370 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1371 | Callback(T *obj, R (*func)(T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1372 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1373 | } |
nexpaq | 0:6c56fb4bc5f0 | 1374 | |
nexpaq | 0:6c56fb4bc5f0 | 1375 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1376 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1377 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1378 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1379 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1380 | Callback(const T *obj, R (*func)(const T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1381 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1382 | } |
nexpaq | 0:6c56fb4bc5f0 | 1383 | |
nexpaq | 0:6c56fb4bc5f0 | 1384 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1385 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1386 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1387 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1388 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1389 | Callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1390 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1391 | } |
nexpaq | 0:6c56fb4bc5f0 | 1392 | |
nexpaq | 0:6c56fb4bc5f0 | 1393 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1394 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1395 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1396 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1397 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1398 | Callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1399 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1400 | } |
nexpaq | 0:6c56fb4bc5f0 | 1401 | |
nexpaq | 0:6c56fb4bc5f0 | 1402 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1403 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1404 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1405 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1406 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1407 | Callback(T *obj, R (T::*func)(A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1408 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1409 | } |
nexpaq | 0:6c56fb4bc5f0 | 1410 | |
nexpaq | 0:6c56fb4bc5f0 | 1411 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1412 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1413 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1414 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1415 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1416 | Callback(const T *obj, R (T::*func)(A0, A1, A2) const) { |
nexpaq | 0:6c56fb4bc5f0 | 1417 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1418 | } |
nexpaq | 0:6c56fb4bc5f0 | 1419 | |
nexpaq | 0:6c56fb4bc5f0 | 1420 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1421 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1422 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1423 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1424 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1425 | Callback(volatile T *obj, R (T::*func)(A0, A1, A2) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1426 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1427 | } |
nexpaq | 0:6c56fb4bc5f0 | 1428 | |
nexpaq | 0:6c56fb4bc5f0 | 1429 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1430 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1431 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1432 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1433 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1434 | Callback(const volatile T *obj, R (T::*func)(A0, A1, A2) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1435 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1436 | } |
nexpaq | 0:6c56fb4bc5f0 | 1437 | |
nexpaq | 0:6c56fb4bc5f0 | 1438 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 1439 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1440 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1441 | void attach(R (*func)(A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1442 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1443 | static R _thunk(void*, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1444 | return (*static_cast<R (*const *)(A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1445 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1446 | } |
nexpaq | 0:6c56fb4bc5f0 | 1447 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1448 | |
nexpaq | 0:6c56fb4bc5f0 | 1449 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1450 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1451 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 1452 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 1453 | } |
nexpaq | 0:6c56fb4bc5f0 | 1454 | |
nexpaq | 0:6c56fb4bc5f0 | 1455 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 1456 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 1457 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1458 | void attach(const Callback<R(A0, A1, A2)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 1459 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1460 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1461 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 1462 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1463 | } |
nexpaq | 0:6c56fb4bc5f0 | 1464 | |
nexpaq | 0:6c56fb4bc5f0 | 1465 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1466 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1467 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1468 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1469 | void attach(void *obj, R (*func)(void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1470 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1471 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1472 | return (*static_cast<R (*const *)(void*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1473 | (void*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1474 | } |
nexpaq | 0:6c56fb4bc5f0 | 1475 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1476 | |
nexpaq | 0:6c56fb4bc5f0 | 1477 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1478 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1479 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1480 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1481 | } |
nexpaq | 0:6c56fb4bc5f0 | 1482 | |
nexpaq | 0:6c56fb4bc5f0 | 1483 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1484 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1485 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1486 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1487 | void attach(const void *obj, R (*func)(const void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1488 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1489 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1490 | return (*static_cast<R (*const *)(const void*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1491 | (const void*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1492 | } |
nexpaq | 0:6c56fb4bc5f0 | 1493 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1494 | |
nexpaq | 0:6c56fb4bc5f0 | 1495 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1496 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1497 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1498 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1499 | } |
nexpaq | 0:6c56fb4bc5f0 | 1500 | |
nexpaq | 0:6c56fb4bc5f0 | 1501 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1502 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1503 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1504 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1505 | void attach(volatile void *obj, R (*func)(volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1506 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1507 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1508 | return (*static_cast<R (*const *)(volatile void*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1509 | (volatile void*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1510 | } |
nexpaq | 0:6c56fb4bc5f0 | 1511 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1512 | |
nexpaq | 0:6c56fb4bc5f0 | 1513 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1514 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1515 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1516 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1517 | } |
nexpaq | 0:6c56fb4bc5f0 | 1518 | |
nexpaq | 0:6c56fb4bc5f0 | 1519 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1520 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1521 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1522 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1523 | void attach(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1524 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1525 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1526 | return (*static_cast<R (*const *)(const volatile void*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1527 | (const volatile void*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1528 | } |
nexpaq | 0:6c56fb4bc5f0 | 1529 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1530 | |
nexpaq | 0:6c56fb4bc5f0 | 1531 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1532 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1533 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1534 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1535 | } |
nexpaq | 0:6c56fb4bc5f0 | 1536 | |
nexpaq | 0:6c56fb4bc5f0 | 1537 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1538 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1539 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1540 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1541 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1542 | void attach(T *obj, R (*func)(T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1543 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1544 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1545 | return (*static_cast<R (*const *)(T*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1546 | (T*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1547 | } |
nexpaq | 0:6c56fb4bc5f0 | 1548 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1549 | |
nexpaq | 0:6c56fb4bc5f0 | 1550 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1551 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1552 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1553 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1554 | } |
nexpaq | 0:6c56fb4bc5f0 | 1555 | |
nexpaq | 0:6c56fb4bc5f0 | 1556 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1557 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1558 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1559 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1560 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1561 | void attach(const T *obj, R (*func)(const T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1562 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1563 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1564 | return (*static_cast<R (*const *)(const T*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1565 | (const T*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1566 | } |
nexpaq | 0:6c56fb4bc5f0 | 1567 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1568 | |
nexpaq | 0:6c56fb4bc5f0 | 1569 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1570 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1571 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1572 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1573 | } |
nexpaq | 0:6c56fb4bc5f0 | 1574 | |
nexpaq | 0:6c56fb4bc5f0 | 1575 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1576 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1577 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1578 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1579 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1580 | void attach(volatile T *obj, R (*func)(volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1581 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1582 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1583 | return (*static_cast<R (*const *)(volatile T*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1584 | (volatile T*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1585 | } |
nexpaq | 0:6c56fb4bc5f0 | 1586 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1587 | |
nexpaq | 0:6c56fb4bc5f0 | 1588 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1589 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1590 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1591 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1592 | } |
nexpaq | 0:6c56fb4bc5f0 | 1593 | |
nexpaq | 0:6c56fb4bc5f0 | 1594 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1595 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1596 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1597 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1598 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1599 | void attach(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1600 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1601 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1602 | return (*static_cast<R (*const *)(const volatile T*, A0, A1, A2)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1603 | (const volatile T*)obj, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1604 | } |
nexpaq | 0:6c56fb4bc5f0 | 1605 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1606 | |
nexpaq | 0:6c56fb4bc5f0 | 1607 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1608 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1609 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1610 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1611 | } |
nexpaq | 0:6c56fb4bc5f0 | 1612 | |
nexpaq | 0:6c56fb4bc5f0 | 1613 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1614 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1615 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1616 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1617 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1618 | void attach(T *obj, R (T::*func)(A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 1619 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1620 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1621 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1622 | (*static_cast<R (T::*const *)(A0, A1, A2)>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1623 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1624 | } |
nexpaq | 0:6c56fb4bc5f0 | 1625 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1626 | |
nexpaq | 0:6c56fb4bc5f0 | 1627 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1628 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1629 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1630 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1631 | } |
nexpaq | 0:6c56fb4bc5f0 | 1632 | |
nexpaq | 0:6c56fb4bc5f0 | 1633 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1634 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1635 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1636 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1637 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1638 | void attach(const T *obj, R (T::*func)(A0, A1, A2) const) { |
nexpaq | 0:6c56fb4bc5f0 | 1639 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1640 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1641 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1642 | (*static_cast<R (T::*const *)(A0, A1, A2) const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1643 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1644 | } |
nexpaq | 0:6c56fb4bc5f0 | 1645 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1646 | |
nexpaq | 0:6c56fb4bc5f0 | 1647 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1648 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1649 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1650 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1651 | } |
nexpaq | 0:6c56fb4bc5f0 | 1652 | |
nexpaq | 0:6c56fb4bc5f0 | 1653 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1654 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1655 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1656 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1657 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1658 | void attach(volatile T *obj, R (T::*func)(A0, A1, A2) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1659 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1660 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1661 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1662 | (*static_cast<R (T::*const *)(A0, A1, A2) volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1663 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1664 | } |
nexpaq | 0:6c56fb4bc5f0 | 1665 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1666 | |
nexpaq | 0:6c56fb4bc5f0 | 1667 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1668 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1669 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1670 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1671 | } |
nexpaq | 0:6c56fb4bc5f0 | 1672 | |
nexpaq | 0:6c56fb4bc5f0 | 1673 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 1674 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1675 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1676 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1677 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1678 | void attach(const volatile T *obj, R (T::*func)(A0, A1, A2) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1679 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1680 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1681 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 1682 | (*static_cast<R (T::*const *)(A0, A1, A2) const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 1683 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1684 | } |
nexpaq | 0:6c56fb4bc5f0 | 1685 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1686 | |
nexpaq | 0:6c56fb4bc5f0 | 1687 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1688 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1689 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1690 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1691 | } |
nexpaq | 0:6c56fb4bc5f0 | 1692 | |
nexpaq | 0:6c56fb4bc5f0 | 1693 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 1694 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1695 | R call(A0 a0, A1 a1, A2 a2) const { |
nexpaq | 0:6c56fb4bc5f0 | 1696 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 1697 | return _thunk(_obj, &_func, a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1698 | } |
nexpaq | 0:6c56fb4bc5f0 | 1699 | |
nexpaq | 0:6c56fb4bc5f0 | 1700 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 1701 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1702 | R operator()(A0 a0, A1 a1, A2 a2) const { |
nexpaq | 0:6c56fb4bc5f0 | 1703 | return call(a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1704 | } |
nexpaq | 0:6c56fb4bc5f0 | 1705 | |
nexpaq | 0:6c56fb4bc5f0 | 1706 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 1707 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1708 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 1709 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1710 | } |
nexpaq | 0:6c56fb4bc5f0 | 1711 | |
nexpaq | 0:6c56fb4bc5f0 | 1712 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 1713 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1714 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 1715 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 1716 | } |
nexpaq | 0:6c56fb4bc5f0 | 1717 | |
nexpaq | 0:6c56fb4bc5f0 | 1718 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 1719 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1720 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 1721 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 1722 | } |
nexpaq | 0:6c56fb4bc5f0 | 1723 | |
nexpaq | 0:6c56fb4bc5f0 | 1724 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 1725 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 1726 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1727 | static R thunk(void *func, A0 a0, A1 a1, A2 a2) { |
nexpaq | 0:6c56fb4bc5f0 | 1728 | return static_cast<Callback<R(A0, A1, A2)>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 1729 | a0, a1, a2); |
nexpaq | 0:6c56fb4bc5f0 | 1730 | } |
nexpaq | 0:6c56fb4bc5f0 | 1731 | |
nexpaq | 0:6c56fb4bc5f0 | 1732 | private: |
nexpaq | 0:6c56fb4bc5f0 | 1733 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 1734 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 1735 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 1736 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 1737 | union { |
nexpaq | 0:6c56fb4bc5f0 | 1738 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 1739 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 1740 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 1741 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 1742 | |
nexpaq | 0:6c56fb4bc5f0 | 1743 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 1744 | |
nexpaq | 0:6c56fb4bc5f0 | 1745 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 1746 | R (*_thunk)(void*, const void*, A0, A1, A2); |
nexpaq | 0:6c56fb4bc5f0 | 1747 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1748 | |
nexpaq | 0:6c56fb4bc5f0 | 1749 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 1750 | * |
nexpaq | 0:6c56fb4bc5f0 | 1751 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 1752 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1753 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 1754 | class Callback<R(A0, A1, A2, A3)> { |
nexpaq | 0:6c56fb4bc5f0 | 1755 | public: |
nexpaq | 0:6c56fb4bc5f0 | 1756 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 1757 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1758 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1759 | Callback(R (*func)(A0, A1, A2, A3) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 1760 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 1761 | } |
nexpaq | 0:6c56fb4bc5f0 | 1762 | |
nexpaq | 0:6c56fb4bc5f0 | 1763 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1764 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1765 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1766 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1767 | Callback(void *obj, R (*func)(void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1768 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1769 | } |
nexpaq | 0:6c56fb4bc5f0 | 1770 | |
nexpaq | 0:6c56fb4bc5f0 | 1771 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1772 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1773 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1774 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1775 | Callback(const void *obj, R (*func)(const void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1776 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1777 | } |
nexpaq | 0:6c56fb4bc5f0 | 1778 | |
nexpaq | 0:6c56fb4bc5f0 | 1779 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1780 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1781 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1782 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1783 | Callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1784 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1785 | } |
nexpaq | 0:6c56fb4bc5f0 | 1786 | |
nexpaq | 0:6c56fb4bc5f0 | 1787 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1788 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1789 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1790 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1791 | Callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1792 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1793 | } |
nexpaq | 0:6c56fb4bc5f0 | 1794 | |
nexpaq | 0:6c56fb4bc5f0 | 1795 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1796 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1797 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1798 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1799 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1800 | Callback(T *obj, R (*func)(T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1801 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1802 | } |
nexpaq | 0:6c56fb4bc5f0 | 1803 | |
nexpaq | 0:6c56fb4bc5f0 | 1804 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1805 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1806 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1807 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1808 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1809 | Callback(const T *obj, R (*func)(const T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1810 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1811 | } |
nexpaq | 0:6c56fb4bc5f0 | 1812 | |
nexpaq | 0:6c56fb4bc5f0 | 1813 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1814 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1815 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1816 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1817 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1818 | Callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1819 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1820 | } |
nexpaq | 0:6c56fb4bc5f0 | 1821 | |
nexpaq | 0:6c56fb4bc5f0 | 1822 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1823 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1824 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1825 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1826 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1827 | Callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1828 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1829 | } |
nexpaq | 0:6c56fb4bc5f0 | 1830 | |
nexpaq | 0:6c56fb4bc5f0 | 1831 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1832 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1833 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1834 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1835 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1836 | Callback(T *obj, R (T::*func)(A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1837 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1838 | } |
nexpaq | 0:6c56fb4bc5f0 | 1839 | |
nexpaq | 0:6c56fb4bc5f0 | 1840 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1841 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1842 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1843 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1844 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1845 | Callback(const T *obj, R (T::*func)(A0, A1, A2, A3) const) { |
nexpaq | 0:6c56fb4bc5f0 | 1846 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1847 | } |
nexpaq | 0:6c56fb4bc5f0 | 1848 | |
nexpaq | 0:6c56fb4bc5f0 | 1849 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1850 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1851 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1852 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1853 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1854 | Callback(volatile T *obj, R (T::*func)(A0, A1, A2, A3) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1855 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1856 | } |
nexpaq | 0:6c56fb4bc5f0 | 1857 | |
nexpaq | 0:6c56fb4bc5f0 | 1858 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 1859 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 1860 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1861 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1862 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1863 | Callback(const volatile T *obj, R (T::*func)(A0, A1, A2, A3) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 1864 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 1865 | } |
nexpaq | 0:6c56fb4bc5f0 | 1866 | |
nexpaq | 0:6c56fb4bc5f0 | 1867 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 1868 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1869 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1870 | void attach(R (*func)(A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1871 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1872 | static R _thunk(void*, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1873 | return (*static_cast<R (*const *)(A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1874 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1875 | } |
nexpaq | 0:6c56fb4bc5f0 | 1876 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1877 | |
nexpaq | 0:6c56fb4bc5f0 | 1878 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1879 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1880 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 1881 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 1882 | } |
nexpaq | 0:6c56fb4bc5f0 | 1883 | |
nexpaq | 0:6c56fb4bc5f0 | 1884 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 1885 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 1886 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1887 | void attach(const Callback<R(A0, A1, A2, A3)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 1888 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1889 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1890 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 1891 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1892 | } |
nexpaq | 0:6c56fb4bc5f0 | 1893 | |
nexpaq | 0:6c56fb4bc5f0 | 1894 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1895 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1896 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1897 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1898 | void attach(void *obj, R (*func)(void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1899 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1900 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1901 | return (*static_cast<R (*const *)(void*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1902 | (void*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1903 | } |
nexpaq | 0:6c56fb4bc5f0 | 1904 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1905 | |
nexpaq | 0:6c56fb4bc5f0 | 1906 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1907 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1908 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1909 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1910 | } |
nexpaq | 0:6c56fb4bc5f0 | 1911 | |
nexpaq | 0:6c56fb4bc5f0 | 1912 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1913 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1914 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1915 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1916 | void attach(const void *obj, R (*func)(const void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1917 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1918 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1919 | return (*static_cast<R (*const *)(const void*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1920 | (const void*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1921 | } |
nexpaq | 0:6c56fb4bc5f0 | 1922 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1923 | |
nexpaq | 0:6c56fb4bc5f0 | 1924 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1925 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1926 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1927 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1928 | } |
nexpaq | 0:6c56fb4bc5f0 | 1929 | |
nexpaq | 0:6c56fb4bc5f0 | 1930 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1931 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1932 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1933 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1934 | void attach(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1935 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1936 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1937 | return (*static_cast<R (*const *)(volatile void*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1938 | (volatile void*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1939 | } |
nexpaq | 0:6c56fb4bc5f0 | 1940 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1941 | |
nexpaq | 0:6c56fb4bc5f0 | 1942 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1943 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1944 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1945 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1946 | } |
nexpaq | 0:6c56fb4bc5f0 | 1947 | |
nexpaq | 0:6c56fb4bc5f0 | 1948 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1949 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1950 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1951 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1952 | void attach(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1953 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1954 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1955 | return (*static_cast<R (*const *)(const volatile void*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1956 | (const volatile void*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1957 | } |
nexpaq | 0:6c56fb4bc5f0 | 1958 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1959 | |
nexpaq | 0:6c56fb4bc5f0 | 1960 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1961 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1962 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1963 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1964 | } |
nexpaq | 0:6c56fb4bc5f0 | 1965 | |
nexpaq | 0:6c56fb4bc5f0 | 1966 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1967 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1968 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1969 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1970 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1971 | void attach(T *obj, R (*func)(T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1972 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1973 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1974 | return (*static_cast<R (*const *)(T*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1975 | (T*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1976 | } |
nexpaq | 0:6c56fb4bc5f0 | 1977 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1978 | |
nexpaq | 0:6c56fb4bc5f0 | 1979 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1980 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 1981 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 1982 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 1983 | } |
nexpaq | 0:6c56fb4bc5f0 | 1984 | |
nexpaq | 0:6c56fb4bc5f0 | 1985 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 1986 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 1987 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 1988 | */ |
nexpaq | 0:6c56fb4bc5f0 | 1989 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 1990 | void attach(const T *obj, R (*func)(const T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 1991 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 1992 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 1993 | return (*static_cast<R (*const *)(const T*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 1994 | (const T*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 1995 | } |
nexpaq | 0:6c56fb4bc5f0 | 1996 | }; |
nexpaq | 0:6c56fb4bc5f0 | 1997 | |
nexpaq | 0:6c56fb4bc5f0 | 1998 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 1999 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2000 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2001 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2002 | } |
nexpaq | 0:6c56fb4bc5f0 | 2003 | |
nexpaq | 0:6c56fb4bc5f0 | 2004 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2005 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2006 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2007 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2008 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2009 | void attach(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 2010 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2011 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2012 | return (*static_cast<R (*const *)(volatile T*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2013 | (volatile T*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2014 | } |
nexpaq | 0:6c56fb4bc5f0 | 2015 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2016 | |
nexpaq | 0:6c56fb4bc5f0 | 2017 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2018 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2019 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2020 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2021 | } |
nexpaq | 0:6c56fb4bc5f0 | 2022 | |
nexpaq | 0:6c56fb4bc5f0 | 2023 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2024 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2025 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2026 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2027 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2028 | void attach(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 2029 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2030 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2031 | return (*static_cast<R (*const *)(const volatile T*, A0, A1, A2, A3)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2032 | (const volatile T*)obj, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2033 | } |
nexpaq | 0:6c56fb4bc5f0 | 2034 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2035 | |
nexpaq | 0:6c56fb4bc5f0 | 2036 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2037 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2038 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2039 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2040 | } |
nexpaq | 0:6c56fb4bc5f0 | 2041 | |
nexpaq | 0:6c56fb4bc5f0 | 2042 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2043 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2044 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2045 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2046 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2047 | void attach(T *obj, R (T::*func)(A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 2048 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2049 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2050 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2051 | (*static_cast<R (T::*const *)(A0, A1, A2, A3)>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2052 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2053 | } |
nexpaq | 0:6c56fb4bc5f0 | 2054 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2055 | |
nexpaq | 0:6c56fb4bc5f0 | 2056 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2057 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2058 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2059 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2060 | } |
nexpaq | 0:6c56fb4bc5f0 | 2061 | |
nexpaq | 0:6c56fb4bc5f0 | 2062 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2063 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2064 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2065 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2066 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2067 | void attach(const T *obj, R (T::*func)(A0, A1, A2, A3) const) { |
nexpaq | 0:6c56fb4bc5f0 | 2068 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2069 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2070 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2071 | (*static_cast<R (T::*const *)(A0, A1, A2, A3) const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2072 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2073 | } |
nexpaq | 0:6c56fb4bc5f0 | 2074 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2075 | |
nexpaq | 0:6c56fb4bc5f0 | 2076 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2077 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2078 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2079 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2080 | } |
nexpaq | 0:6c56fb4bc5f0 | 2081 | |
nexpaq | 0:6c56fb4bc5f0 | 2082 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2083 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2084 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2085 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2086 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2087 | void attach(volatile T *obj, R (T::*func)(A0, A1, A2, A3) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2088 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2089 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2090 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2091 | (*static_cast<R (T::*const *)(A0, A1, A2, A3) volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2092 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2093 | } |
nexpaq | 0:6c56fb4bc5f0 | 2094 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2095 | |
nexpaq | 0:6c56fb4bc5f0 | 2096 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2097 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2098 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2099 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2100 | } |
nexpaq | 0:6c56fb4bc5f0 | 2101 | |
nexpaq | 0:6c56fb4bc5f0 | 2102 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2103 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2104 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2105 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2106 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2107 | void attach(const volatile T *obj, R (T::*func)(A0, A1, A2, A3) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2108 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2109 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2110 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2111 | (*static_cast<R (T::*const *)(A0, A1, A2, A3) const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2112 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2113 | } |
nexpaq | 0:6c56fb4bc5f0 | 2114 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2115 | |
nexpaq | 0:6c56fb4bc5f0 | 2116 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2117 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2118 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2119 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2120 | } |
nexpaq | 0:6c56fb4bc5f0 | 2121 | |
nexpaq | 0:6c56fb4bc5f0 | 2122 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 2123 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2124 | R call(A0 a0, A1 a1, A2 a2, A3 a3) const { |
nexpaq | 0:6c56fb4bc5f0 | 2125 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 2126 | return _thunk(_obj, &_func, a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2127 | } |
nexpaq | 0:6c56fb4bc5f0 | 2128 | |
nexpaq | 0:6c56fb4bc5f0 | 2129 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 2130 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2131 | R operator()(A0 a0, A1 a1, A2 a2, A3 a3) const { |
nexpaq | 0:6c56fb4bc5f0 | 2132 | return call(a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2133 | } |
nexpaq | 0:6c56fb4bc5f0 | 2134 | |
nexpaq | 0:6c56fb4bc5f0 | 2135 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 2136 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2137 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 2138 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2139 | } |
nexpaq | 0:6c56fb4bc5f0 | 2140 | |
nexpaq | 0:6c56fb4bc5f0 | 2141 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 2142 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2143 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 2144 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 2145 | } |
nexpaq | 0:6c56fb4bc5f0 | 2146 | |
nexpaq | 0:6c56fb4bc5f0 | 2147 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 2148 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2149 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 2150 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 2151 | } |
nexpaq | 0:6c56fb4bc5f0 | 2152 | |
nexpaq | 0:6c56fb4bc5f0 | 2153 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 2154 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 2155 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2156 | static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) { |
nexpaq | 0:6c56fb4bc5f0 | 2157 | return static_cast<Callback<R(A0, A1, A2, A3)>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 2158 | a0, a1, a2, a3); |
nexpaq | 0:6c56fb4bc5f0 | 2159 | } |
nexpaq | 0:6c56fb4bc5f0 | 2160 | |
nexpaq | 0:6c56fb4bc5f0 | 2161 | private: |
nexpaq | 0:6c56fb4bc5f0 | 2162 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 2163 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 2164 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 2165 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 2166 | union { |
nexpaq | 0:6c56fb4bc5f0 | 2167 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 2168 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 2169 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 2170 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 2171 | |
nexpaq | 0:6c56fb4bc5f0 | 2172 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 2173 | |
nexpaq | 0:6c56fb4bc5f0 | 2174 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 2175 | R (*_thunk)(void*, const void*, A0, A1, A2, A3); |
nexpaq | 0:6c56fb4bc5f0 | 2176 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2177 | |
nexpaq | 0:6c56fb4bc5f0 | 2178 | /** Callback class based on template specialization |
nexpaq | 0:6c56fb4bc5f0 | 2179 | * |
nexpaq | 0:6c56fb4bc5f0 | 2180 | * @Note Synchronization level: Not protected |
nexpaq | 0:6c56fb4bc5f0 | 2181 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2182 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 2183 | class Callback<R(A0, A1, A2, A3, A4)> { |
nexpaq | 0:6c56fb4bc5f0 | 2184 | public: |
nexpaq | 0:6c56fb4bc5f0 | 2185 | /** Create a Callback with a static function |
nexpaq | 0:6c56fb4bc5f0 | 2186 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2187 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2188 | Callback(R (*func)(A0, A1, A2, A3, A4) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 2189 | attach(func); |
nexpaq | 0:6c56fb4bc5f0 | 2190 | } |
nexpaq | 0:6c56fb4bc5f0 | 2191 | |
nexpaq | 0:6c56fb4bc5f0 | 2192 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2193 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2194 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2195 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2196 | Callback(void *obj, R (*func)(void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2197 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2198 | } |
nexpaq | 0:6c56fb4bc5f0 | 2199 | |
nexpaq | 0:6c56fb4bc5f0 | 2200 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2201 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2202 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2203 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2204 | Callback(const void *obj, R (*func)(const void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2205 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2206 | } |
nexpaq | 0:6c56fb4bc5f0 | 2207 | |
nexpaq | 0:6c56fb4bc5f0 | 2208 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2209 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2210 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2211 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2212 | Callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2213 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2214 | } |
nexpaq | 0:6c56fb4bc5f0 | 2215 | |
nexpaq | 0:6c56fb4bc5f0 | 2216 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2217 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2218 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2219 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2220 | Callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2221 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2222 | } |
nexpaq | 0:6c56fb4bc5f0 | 2223 | |
nexpaq | 0:6c56fb4bc5f0 | 2224 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2225 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2226 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2227 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2228 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2229 | Callback(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2230 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2231 | } |
nexpaq | 0:6c56fb4bc5f0 | 2232 | |
nexpaq | 0:6c56fb4bc5f0 | 2233 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2234 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2235 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2236 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2237 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2238 | Callback(const T *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2239 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2240 | } |
nexpaq | 0:6c56fb4bc5f0 | 2241 | |
nexpaq | 0:6c56fb4bc5f0 | 2242 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2243 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2244 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2245 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2246 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2247 | Callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2248 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2249 | } |
nexpaq | 0:6c56fb4bc5f0 | 2250 | |
nexpaq | 0:6c56fb4bc5f0 | 2251 | /** Create a Callback with a static function and bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2252 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2253 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2254 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2255 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2256 | Callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2257 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2258 | } |
nexpaq | 0:6c56fb4bc5f0 | 2259 | |
nexpaq | 0:6c56fb4bc5f0 | 2260 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 2261 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2262 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2263 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2264 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2265 | Callback(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2266 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2267 | } |
nexpaq | 0:6c56fb4bc5f0 | 2268 | |
nexpaq | 0:6c56fb4bc5f0 | 2269 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 2270 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2271 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2272 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2273 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2274 | Callback(const T *obj, R (T::*func)(A0, A1, A2, A3, A4) const) { |
nexpaq | 0:6c56fb4bc5f0 | 2275 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2276 | } |
nexpaq | 0:6c56fb4bc5f0 | 2277 | |
nexpaq | 0:6c56fb4bc5f0 | 2278 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 2279 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2280 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2281 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2282 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2283 | Callback(volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2284 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2285 | } |
nexpaq | 0:6c56fb4bc5f0 | 2286 | |
nexpaq | 0:6c56fb4bc5f0 | 2287 | /** Create a Callback with a member function |
nexpaq | 0:6c56fb4bc5f0 | 2288 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2289 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2290 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2291 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2292 | Callback(const volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2293 | attach(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2294 | } |
nexpaq | 0:6c56fb4bc5f0 | 2295 | |
nexpaq | 0:6c56fb4bc5f0 | 2296 | /** Attach a static function |
nexpaq | 0:6c56fb4bc5f0 | 2297 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2298 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2299 | void attach(R (*func)(A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2300 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2301 | static R _thunk(void*, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2302 | return (*static_cast<R (*const *)(A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2303 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2304 | } |
nexpaq | 0:6c56fb4bc5f0 | 2305 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2306 | |
nexpaq | 0:6c56fb4bc5f0 | 2307 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2308 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2309 | _obj = 0; |
nexpaq | 0:6c56fb4bc5f0 | 2310 | _thunk = func ? &local::_thunk : 0; |
nexpaq | 0:6c56fb4bc5f0 | 2311 | } |
nexpaq | 0:6c56fb4bc5f0 | 2312 | |
nexpaq | 0:6c56fb4bc5f0 | 2313 | /** Attach a Callback |
nexpaq | 0:6c56fb4bc5f0 | 2314 | * @param func The Callback to attach |
nexpaq | 0:6c56fb4bc5f0 | 2315 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2316 | void attach(const Callback<R(A0, A1, A2, A3, A4)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 2317 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2318 | memcpy(&_func, &func._func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2319 | _obj = func._obj; |
nexpaq | 0:6c56fb4bc5f0 | 2320 | _thunk = func._thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2321 | } |
nexpaq | 0:6c56fb4bc5f0 | 2322 | |
nexpaq | 0:6c56fb4bc5f0 | 2323 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2324 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2325 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2326 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2327 | void attach(void *obj, R (*func)(void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2328 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2329 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2330 | return (*static_cast<R (*const *)(void*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2331 | (void*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2332 | } |
nexpaq | 0:6c56fb4bc5f0 | 2333 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2334 | |
nexpaq | 0:6c56fb4bc5f0 | 2335 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2336 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2337 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2338 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2339 | } |
nexpaq | 0:6c56fb4bc5f0 | 2340 | |
nexpaq | 0:6c56fb4bc5f0 | 2341 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2342 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2343 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2344 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2345 | void attach(const void *obj, R (*func)(const void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2346 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2347 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2348 | return (*static_cast<R (*const *)(const void*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2349 | (const void*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2350 | } |
nexpaq | 0:6c56fb4bc5f0 | 2351 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2352 | |
nexpaq | 0:6c56fb4bc5f0 | 2353 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2354 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2355 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2356 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2357 | } |
nexpaq | 0:6c56fb4bc5f0 | 2358 | |
nexpaq | 0:6c56fb4bc5f0 | 2359 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2360 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2361 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2362 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2363 | void attach(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2364 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2365 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2366 | return (*static_cast<R (*const *)(volatile void*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2367 | (volatile void*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2368 | } |
nexpaq | 0:6c56fb4bc5f0 | 2369 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2370 | |
nexpaq | 0:6c56fb4bc5f0 | 2371 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2372 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2373 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2374 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2375 | } |
nexpaq | 0:6c56fb4bc5f0 | 2376 | |
nexpaq | 0:6c56fb4bc5f0 | 2377 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2378 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2379 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2380 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2381 | void attach(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2382 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2383 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2384 | return (*static_cast<R (*const *)(const volatile void*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2385 | (const volatile void*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2386 | } |
nexpaq | 0:6c56fb4bc5f0 | 2387 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2388 | |
nexpaq | 0:6c56fb4bc5f0 | 2389 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2390 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2391 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2392 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2393 | } |
nexpaq | 0:6c56fb4bc5f0 | 2394 | |
nexpaq | 0:6c56fb4bc5f0 | 2395 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2396 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2397 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2398 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2399 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2400 | void attach(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2401 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2402 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2403 | return (*static_cast<R (*const *)(T*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2404 | (T*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2405 | } |
nexpaq | 0:6c56fb4bc5f0 | 2406 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2407 | |
nexpaq | 0:6c56fb4bc5f0 | 2408 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2409 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2410 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2411 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2412 | } |
nexpaq | 0:6c56fb4bc5f0 | 2413 | |
nexpaq | 0:6c56fb4bc5f0 | 2414 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2415 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2416 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2417 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2418 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2419 | void attach(const T *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2420 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2421 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2422 | return (*static_cast<R (*const *)(const T*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2423 | (const T*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2424 | } |
nexpaq | 0:6c56fb4bc5f0 | 2425 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2426 | |
nexpaq | 0:6c56fb4bc5f0 | 2427 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2428 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2429 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2430 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2431 | } |
nexpaq | 0:6c56fb4bc5f0 | 2432 | |
nexpaq | 0:6c56fb4bc5f0 | 2433 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2434 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2435 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2436 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2437 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2438 | void attach(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2439 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2440 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2441 | return (*static_cast<R (*const *)(volatile T*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2442 | (volatile T*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2443 | } |
nexpaq | 0:6c56fb4bc5f0 | 2444 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2445 | |
nexpaq | 0:6c56fb4bc5f0 | 2446 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2447 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2448 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2449 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2450 | } |
nexpaq | 0:6c56fb4bc5f0 | 2451 | |
nexpaq | 0:6c56fb4bc5f0 | 2452 | /** Attach a static function with a bound pointer |
nexpaq | 0:6c56fb4bc5f0 | 2453 | * @param obj Pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2454 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2455 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2456 | template <typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2457 | void attach(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2458 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2459 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2460 | return (*static_cast<R (*const *)(const volatile T*, A0, A1, A2, A3, A4)>(func))( |
nexpaq | 0:6c56fb4bc5f0 | 2461 | (const volatile T*)obj, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2462 | } |
nexpaq | 0:6c56fb4bc5f0 | 2463 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2464 | |
nexpaq | 0:6c56fb4bc5f0 | 2465 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2466 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2467 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2468 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2469 | } |
nexpaq | 0:6c56fb4bc5f0 | 2470 | |
nexpaq | 0:6c56fb4bc5f0 | 2471 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2472 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2473 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2474 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2475 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2476 | void attach(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 2477 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2478 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2479 | return (((T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2480 | (*static_cast<R (T::*const *)(A0, A1, A2, A3, A4)>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2481 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2482 | } |
nexpaq | 0:6c56fb4bc5f0 | 2483 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2484 | |
nexpaq | 0:6c56fb4bc5f0 | 2485 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2486 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2487 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2488 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2489 | } |
nexpaq | 0:6c56fb4bc5f0 | 2490 | |
nexpaq | 0:6c56fb4bc5f0 | 2491 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2492 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2493 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2494 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2495 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2496 | void attach(const T *obj, R (T::*func)(A0, A1, A2, A3, A4) const) { |
nexpaq | 0:6c56fb4bc5f0 | 2497 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2498 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2499 | return (((const T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2500 | (*static_cast<R (T::*const *)(A0, A1, A2, A3, A4) const>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2501 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2502 | } |
nexpaq | 0:6c56fb4bc5f0 | 2503 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2504 | |
nexpaq | 0:6c56fb4bc5f0 | 2505 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2506 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2507 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2508 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2509 | } |
nexpaq | 0:6c56fb4bc5f0 | 2510 | |
nexpaq | 0:6c56fb4bc5f0 | 2511 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2512 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2513 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2514 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2515 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2516 | void attach(volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2517 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2518 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2519 | return (((volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2520 | (*static_cast<R (T::*const *)(A0, A1, A2, A3, A4) volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2521 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2522 | } |
nexpaq | 0:6c56fb4bc5f0 | 2523 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2524 | |
nexpaq | 0:6c56fb4bc5f0 | 2525 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2526 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2527 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2528 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2529 | } |
nexpaq | 0:6c56fb4bc5f0 | 2530 | |
nexpaq | 0:6c56fb4bc5f0 | 2531 | /** Attach a member function |
nexpaq | 0:6c56fb4bc5f0 | 2532 | * @param obj Pointer to object to invoke member function on |
nexpaq | 0:6c56fb4bc5f0 | 2533 | * @param func Member function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2534 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2535 | template<typename T> |
nexpaq | 0:6c56fb4bc5f0 | 2536 | void attach(const volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2537 | struct local { |
nexpaq | 0:6c56fb4bc5f0 | 2538 | static R _thunk(void *obj, const void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2539 | return (((const volatile T*)obj)->* |
nexpaq | 0:6c56fb4bc5f0 | 2540 | (*static_cast<R (T::*const *)(A0, A1, A2, A3, A4) const volatile>(func)))( |
nexpaq | 0:6c56fb4bc5f0 | 2541 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2542 | } |
nexpaq | 0:6c56fb4bc5f0 | 2543 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2544 | |
nexpaq | 0:6c56fb4bc5f0 | 2545 | memset(&_func, 0, sizeof _func); |
nexpaq | 0:6c56fb4bc5f0 | 2546 | memcpy(&_func, &func, sizeof func); |
nexpaq | 0:6c56fb4bc5f0 | 2547 | _obj = (void*)obj; |
nexpaq | 0:6c56fb4bc5f0 | 2548 | _thunk = &local::_thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2549 | } |
nexpaq | 0:6c56fb4bc5f0 | 2550 | |
nexpaq | 0:6c56fb4bc5f0 | 2551 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 2552 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2553 | R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const { |
nexpaq | 0:6c56fb4bc5f0 | 2554 | MBED_ASSERT(_thunk); |
nexpaq | 0:6c56fb4bc5f0 | 2555 | return _thunk(_obj, &_func, a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2556 | } |
nexpaq | 0:6c56fb4bc5f0 | 2557 | |
nexpaq | 0:6c56fb4bc5f0 | 2558 | /** Call the attached function |
nexpaq | 0:6c56fb4bc5f0 | 2559 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2560 | R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const { |
nexpaq | 0:6c56fb4bc5f0 | 2561 | return call(a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2562 | } |
nexpaq | 0:6c56fb4bc5f0 | 2563 | |
nexpaq | 0:6c56fb4bc5f0 | 2564 | /** Test if function has been attached |
nexpaq | 0:6c56fb4bc5f0 | 2565 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2566 | operator bool() const { |
nexpaq | 0:6c56fb4bc5f0 | 2567 | return _thunk; |
nexpaq | 0:6c56fb4bc5f0 | 2568 | } |
nexpaq | 0:6c56fb4bc5f0 | 2569 | |
nexpaq | 0:6c56fb4bc5f0 | 2570 | /** Test for equality |
nexpaq | 0:6c56fb4bc5f0 | 2571 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2572 | friend bool operator==(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 2573 | return memcmp(&l, &r, sizeof(Callback)) == 0; |
nexpaq | 0:6c56fb4bc5f0 | 2574 | } |
nexpaq | 0:6c56fb4bc5f0 | 2575 | |
nexpaq | 0:6c56fb4bc5f0 | 2576 | /** Test for inequality |
nexpaq | 0:6c56fb4bc5f0 | 2577 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2578 | friend bool operator!=(const Callback &l, const Callback &r) { |
nexpaq | 0:6c56fb4bc5f0 | 2579 | return !(l == r); |
nexpaq | 0:6c56fb4bc5f0 | 2580 | } |
nexpaq | 0:6c56fb4bc5f0 | 2581 | |
nexpaq | 0:6c56fb4bc5f0 | 2582 | /** Static thunk for passing as C-style function |
nexpaq | 0:6c56fb4bc5f0 | 2583 | * @param func Callback to call passed as void pointer |
nexpaq | 0:6c56fb4bc5f0 | 2584 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2585 | static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { |
nexpaq | 0:6c56fb4bc5f0 | 2586 | return static_cast<Callback<R(A0, A1, A2, A3, A4)>*>(func)->call( |
nexpaq | 0:6c56fb4bc5f0 | 2587 | a0, a1, a2, a3, a4); |
nexpaq | 0:6c56fb4bc5f0 | 2588 | } |
nexpaq | 0:6c56fb4bc5f0 | 2589 | |
nexpaq | 0:6c56fb4bc5f0 | 2590 | private: |
nexpaq | 0:6c56fb4bc5f0 | 2591 | // Stored as pointer to function and pointer to optional object |
nexpaq | 0:6c56fb4bc5f0 | 2592 | // Function pointer is stored as union of possible function types |
nexpaq | 0:6c56fb4bc5f0 | 2593 | // to garuntee proper size and alignment |
nexpaq | 0:6c56fb4bc5f0 | 2594 | struct _class; |
nexpaq | 0:6c56fb4bc5f0 | 2595 | union { |
nexpaq | 0:6c56fb4bc5f0 | 2596 | void (*_staticfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 2597 | void (*_boundfunc)(_class *); |
nexpaq | 0:6c56fb4bc5f0 | 2598 | void (_class::*_methodfunc)(); |
nexpaq | 0:6c56fb4bc5f0 | 2599 | } _func; |
nexpaq | 0:6c56fb4bc5f0 | 2600 | |
nexpaq | 0:6c56fb4bc5f0 | 2601 | void *_obj; |
nexpaq | 0:6c56fb4bc5f0 | 2602 | |
nexpaq | 0:6c56fb4bc5f0 | 2603 | // Thunk registered on attach to dispatch calls |
nexpaq | 0:6c56fb4bc5f0 | 2604 | R (*_thunk)(void*, const void*, A0, A1, A2, A3, A4); |
nexpaq | 0:6c56fb4bc5f0 | 2605 | }; |
nexpaq | 0:6c56fb4bc5f0 | 2606 | |
nexpaq | 0:6c56fb4bc5f0 | 2607 | // Internally used event type |
nexpaq | 0:6c56fb4bc5f0 | 2608 | typedef Callback<void(int)> event_callback_t; |
nexpaq | 0:6c56fb4bc5f0 | 2609 | |
nexpaq | 0:6c56fb4bc5f0 | 2610 | |
nexpaq | 0:6c56fb4bc5f0 | 2611 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2612 | * |
nexpaq | 0:6c56fb4bc5f0 | 2613 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2614 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2615 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2616 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2617 | Callback<R()> callback(R (*func)() = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 2618 | return Callback<R()>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2619 | } |
nexpaq | 0:6c56fb4bc5f0 | 2620 | |
nexpaq | 0:6c56fb4bc5f0 | 2621 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2622 | * |
nexpaq | 0:6c56fb4bc5f0 | 2623 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2624 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2625 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2626 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2627 | Callback<R()> callback(const Callback<R()> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 2628 | return Callback<R()>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2629 | } |
nexpaq | 0:6c56fb4bc5f0 | 2630 | |
nexpaq | 0:6c56fb4bc5f0 | 2631 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2632 | * |
nexpaq | 0:6c56fb4bc5f0 | 2633 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2634 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2635 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2636 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2637 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2638 | Callback<R()> callback(void *obj, R (*func)(void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2639 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2640 | } |
nexpaq | 0:6c56fb4bc5f0 | 2641 | |
nexpaq | 0:6c56fb4bc5f0 | 2642 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2643 | * |
nexpaq | 0:6c56fb4bc5f0 | 2644 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2645 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2646 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2647 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2648 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2649 | Callback<R()> callback(const void *obj, R (*func)(const void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2650 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2651 | } |
nexpaq | 0:6c56fb4bc5f0 | 2652 | |
nexpaq | 0:6c56fb4bc5f0 | 2653 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2654 | * |
nexpaq | 0:6c56fb4bc5f0 | 2655 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2656 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2657 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2658 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2659 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2660 | Callback<R()> callback(volatile void *obj, R (*func)(volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2661 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2662 | } |
nexpaq | 0:6c56fb4bc5f0 | 2663 | |
nexpaq | 0:6c56fb4bc5f0 | 2664 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2665 | * |
nexpaq | 0:6c56fb4bc5f0 | 2666 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2667 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2668 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2669 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2670 | template <typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2671 | Callback<R()> callback(const volatile void *obj, R (*func)(const volatile void*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2672 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2673 | } |
nexpaq | 0:6c56fb4bc5f0 | 2674 | |
nexpaq | 0:6c56fb4bc5f0 | 2675 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2676 | * |
nexpaq | 0:6c56fb4bc5f0 | 2677 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2678 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2679 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2680 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2681 | template <typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2682 | Callback<R()> callback(T *obj, R (*func)(T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2683 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2684 | } |
nexpaq | 0:6c56fb4bc5f0 | 2685 | |
nexpaq | 0:6c56fb4bc5f0 | 2686 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2687 | * |
nexpaq | 0:6c56fb4bc5f0 | 2688 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2689 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2690 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2691 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2692 | template <typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2693 | Callback<R()> callback(const T *obj, R (*func)(const T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2694 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2695 | } |
nexpaq | 0:6c56fb4bc5f0 | 2696 | |
nexpaq | 0:6c56fb4bc5f0 | 2697 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2698 | * |
nexpaq | 0:6c56fb4bc5f0 | 2699 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2700 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2701 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2702 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2703 | template <typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2704 | Callback<R()> callback(volatile T *obj, R (*func)(volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2705 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2706 | } |
nexpaq | 0:6c56fb4bc5f0 | 2707 | |
nexpaq | 0:6c56fb4bc5f0 | 2708 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2709 | * |
nexpaq | 0:6c56fb4bc5f0 | 2710 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2711 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2712 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2713 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2714 | template <typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2715 | Callback<R()> callback(const volatile T *obj, R (*func)(const volatile T*)) { |
nexpaq | 0:6c56fb4bc5f0 | 2716 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2717 | } |
nexpaq | 0:6c56fb4bc5f0 | 2718 | |
nexpaq | 0:6c56fb4bc5f0 | 2719 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2720 | * |
nexpaq | 0:6c56fb4bc5f0 | 2721 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2722 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2723 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2724 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2725 | template<typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2726 | Callback<R()> callback(T *obj, R (T::*func)()) { |
nexpaq | 0:6c56fb4bc5f0 | 2727 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2728 | } |
nexpaq | 0:6c56fb4bc5f0 | 2729 | |
nexpaq | 0:6c56fb4bc5f0 | 2730 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2731 | * |
nexpaq | 0:6c56fb4bc5f0 | 2732 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2733 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2734 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2735 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2736 | template<typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2737 | Callback<R()> callback(const T *obj, R (T::*func)() const) { |
nexpaq | 0:6c56fb4bc5f0 | 2738 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2739 | } |
nexpaq | 0:6c56fb4bc5f0 | 2740 | |
nexpaq | 0:6c56fb4bc5f0 | 2741 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2742 | * |
nexpaq | 0:6c56fb4bc5f0 | 2743 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2744 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2745 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2746 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2747 | template<typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2748 | Callback<R()> callback(volatile T *obj, R (T::*func)() volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2749 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2750 | } |
nexpaq | 0:6c56fb4bc5f0 | 2751 | |
nexpaq | 0:6c56fb4bc5f0 | 2752 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2753 | * |
nexpaq | 0:6c56fb4bc5f0 | 2754 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2755 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2756 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2757 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2758 | template<typename T, typename R> |
nexpaq | 0:6c56fb4bc5f0 | 2759 | Callback<R()> callback(const volatile T *obj, R (T::*func)() const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2760 | return Callback<R()>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2761 | } |
nexpaq | 0:6c56fb4bc5f0 | 2762 | |
nexpaq | 0:6c56fb4bc5f0 | 2763 | |
nexpaq | 0:6c56fb4bc5f0 | 2764 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2765 | * |
nexpaq | 0:6c56fb4bc5f0 | 2766 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2767 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2768 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2769 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2770 | Callback<R(A0)> callback(R (*func)(A0) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 2771 | return Callback<R(A0)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2772 | } |
nexpaq | 0:6c56fb4bc5f0 | 2773 | |
nexpaq | 0:6c56fb4bc5f0 | 2774 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2775 | * |
nexpaq | 0:6c56fb4bc5f0 | 2776 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2777 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2778 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2779 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2780 | Callback<R(A0)> callback(const Callback<R(A0)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 2781 | return Callback<R(A0)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2782 | } |
nexpaq | 0:6c56fb4bc5f0 | 2783 | |
nexpaq | 0:6c56fb4bc5f0 | 2784 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2785 | * |
nexpaq | 0:6c56fb4bc5f0 | 2786 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2787 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2788 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2789 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2790 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2791 | Callback<R(A0)> callback(void *obj, R (*func)(void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2792 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2793 | } |
nexpaq | 0:6c56fb4bc5f0 | 2794 | |
nexpaq | 0:6c56fb4bc5f0 | 2795 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2796 | * |
nexpaq | 0:6c56fb4bc5f0 | 2797 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2798 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2799 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2800 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2801 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2802 | Callback<R(A0)> callback(const void *obj, R (*func)(const void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2803 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2804 | } |
nexpaq | 0:6c56fb4bc5f0 | 2805 | |
nexpaq | 0:6c56fb4bc5f0 | 2806 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2807 | * |
nexpaq | 0:6c56fb4bc5f0 | 2808 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2809 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2810 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2811 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2812 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2813 | Callback<R(A0)> callback(volatile void *obj, R (*func)(volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2814 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2815 | } |
nexpaq | 0:6c56fb4bc5f0 | 2816 | |
nexpaq | 0:6c56fb4bc5f0 | 2817 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2818 | * |
nexpaq | 0:6c56fb4bc5f0 | 2819 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2820 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2821 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2822 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2823 | template <typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2824 | Callback<R(A0)> callback(const volatile void *obj, R (*func)(const volatile void*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2825 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2826 | } |
nexpaq | 0:6c56fb4bc5f0 | 2827 | |
nexpaq | 0:6c56fb4bc5f0 | 2828 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2829 | * |
nexpaq | 0:6c56fb4bc5f0 | 2830 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2831 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2832 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2833 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2834 | template <typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2835 | Callback<R(A0)> callback(T *obj, R (*func)(T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2836 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2837 | } |
nexpaq | 0:6c56fb4bc5f0 | 2838 | |
nexpaq | 0:6c56fb4bc5f0 | 2839 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2840 | * |
nexpaq | 0:6c56fb4bc5f0 | 2841 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2842 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2843 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2844 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2845 | template <typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2846 | Callback<R(A0)> callback(const T *obj, R (*func)(const T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2847 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2848 | } |
nexpaq | 0:6c56fb4bc5f0 | 2849 | |
nexpaq | 0:6c56fb4bc5f0 | 2850 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2851 | * |
nexpaq | 0:6c56fb4bc5f0 | 2852 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2853 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2854 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2855 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2856 | template <typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2857 | Callback<R(A0)> callback(volatile T *obj, R (*func)(volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2858 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2859 | } |
nexpaq | 0:6c56fb4bc5f0 | 2860 | |
nexpaq | 0:6c56fb4bc5f0 | 2861 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2862 | * |
nexpaq | 0:6c56fb4bc5f0 | 2863 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2864 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2865 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2866 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2867 | template <typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2868 | Callback<R(A0)> callback(const volatile T *obj, R (*func)(const volatile T*, A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2869 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2870 | } |
nexpaq | 0:6c56fb4bc5f0 | 2871 | |
nexpaq | 0:6c56fb4bc5f0 | 2872 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2873 | * |
nexpaq | 0:6c56fb4bc5f0 | 2874 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2875 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2876 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2877 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2878 | template<typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2879 | Callback<R(A0)> callback(T *obj, R (T::*func)(A0)) { |
nexpaq | 0:6c56fb4bc5f0 | 2880 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2881 | } |
nexpaq | 0:6c56fb4bc5f0 | 2882 | |
nexpaq | 0:6c56fb4bc5f0 | 2883 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2884 | * |
nexpaq | 0:6c56fb4bc5f0 | 2885 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2886 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2887 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2888 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2889 | template<typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2890 | Callback<R(A0)> callback(const T *obj, R (T::*func)(A0) const) { |
nexpaq | 0:6c56fb4bc5f0 | 2891 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2892 | } |
nexpaq | 0:6c56fb4bc5f0 | 2893 | |
nexpaq | 0:6c56fb4bc5f0 | 2894 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2895 | * |
nexpaq | 0:6c56fb4bc5f0 | 2896 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2897 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2898 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2899 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2900 | template<typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2901 | Callback<R(A0)> callback(volatile T *obj, R (T::*func)(A0) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2902 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2903 | } |
nexpaq | 0:6c56fb4bc5f0 | 2904 | |
nexpaq | 0:6c56fb4bc5f0 | 2905 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2906 | * |
nexpaq | 0:6c56fb4bc5f0 | 2907 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2908 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2909 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2910 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2911 | template<typename T, typename R, typename A0> |
nexpaq | 0:6c56fb4bc5f0 | 2912 | Callback<R(A0)> callback(const volatile T *obj, R (T::*func)(A0) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 2913 | return Callback<R(A0)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2914 | } |
nexpaq | 0:6c56fb4bc5f0 | 2915 | |
nexpaq | 0:6c56fb4bc5f0 | 2916 | |
nexpaq | 0:6c56fb4bc5f0 | 2917 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2918 | * |
nexpaq | 0:6c56fb4bc5f0 | 2919 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2920 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2921 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2922 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2923 | Callback<R(A0, A1)> callback(R (*func)(A0, A1) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 2924 | return Callback<R(A0, A1)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2925 | } |
nexpaq | 0:6c56fb4bc5f0 | 2926 | |
nexpaq | 0:6c56fb4bc5f0 | 2927 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2928 | * |
nexpaq | 0:6c56fb4bc5f0 | 2929 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2930 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2931 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2932 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2933 | Callback<R(A0, A1)> callback(const Callback<R(A0, A1)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 2934 | return Callback<R(A0, A1)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 2935 | } |
nexpaq | 0:6c56fb4bc5f0 | 2936 | |
nexpaq | 0:6c56fb4bc5f0 | 2937 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2938 | * |
nexpaq | 0:6c56fb4bc5f0 | 2939 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2940 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2941 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2942 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2943 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2944 | Callback<R(A0, A1)> callback(void *obj, R (*func)(void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 2945 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2946 | } |
nexpaq | 0:6c56fb4bc5f0 | 2947 | |
nexpaq | 0:6c56fb4bc5f0 | 2948 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2949 | * |
nexpaq | 0:6c56fb4bc5f0 | 2950 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2951 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2952 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2953 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2954 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2955 | Callback<R(A0, A1)> callback(const void *obj, R (*func)(const void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 2956 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2957 | } |
nexpaq | 0:6c56fb4bc5f0 | 2958 | |
nexpaq | 0:6c56fb4bc5f0 | 2959 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2960 | * |
nexpaq | 0:6c56fb4bc5f0 | 2961 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2962 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2963 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2964 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2965 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2966 | Callback<R(A0, A1)> callback(volatile void *obj, R (*func)(volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 2967 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2968 | } |
nexpaq | 0:6c56fb4bc5f0 | 2969 | |
nexpaq | 0:6c56fb4bc5f0 | 2970 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2971 | * |
nexpaq | 0:6c56fb4bc5f0 | 2972 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2973 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2974 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2975 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2976 | template <typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2977 | Callback<R(A0, A1)> callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 2978 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2979 | } |
nexpaq | 0:6c56fb4bc5f0 | 2980 | |
nexpaq | 0:6c56fb4bc5f0 | 2981 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2982 | * |
nexpaq | 0:6c56fb4bc5f0 | 2983 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2984 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2985 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2986 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2987 | template <typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2988 | Callback<R(A0, A1)> callback(T *obj, R (*func)(T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 2989 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 2990 | } |
nexpaq | 0:6c56fb4bc5f0 | 2991 | |
nexpaq | 0:6c56fb4bc5f0 | 2992 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 2993 | * |
nexpaq | 0:6c56fb4bc5f0 | 2994 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 2995 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 2996 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 2997 | */ |
nexpaq | 0:6c56fb4bc5f0 | 2998 | template <typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 2999 | Callback<R(A0, A1)> callback(const T *obj, R (*func)(const T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 3000 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3001 | } |
nexpaq | 0:6c56fb4bc5f0 | 3002 | |
nexpaq | 0:6c56fb4bc5f0 | 3003 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3004 | * |
nexpaq | 0:6c56fb4bc5f0 | 3005 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3006 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3007 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3008 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3009 | template <typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3010 | Callback<R(A0, A1)> callback(volatile T *obj, R (*func)(volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 3011 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3012 | } |
nexpaq | 0:6c56fb4bc5f0 | 3013 | |
nexpaq | 0:6c56fb4bc5f0 | 3014 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3015 | * |
nexpaq | 0:6c56fb4bc5f0 | 3016 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3017 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3018 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3019 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3020 | template <typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3021 | Callback<R(A0, A1)> callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 3022 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3023 | } |
nexpaq | 0:6c56fb4bc5f0 | 3024 | |
nexpaq | 0:6c56fb4bc5f0 | 3025 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3026 | * |
nexpaq | 0:6c56fb4bc5f0 | 3027 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3028 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3029 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3030 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3031 | template<typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3032 | Callback<R(A0, A1)> callback(T *obj, R (T::*func)(A0, A1)) { |
nexpaq | 0:6c56fb4bc5f0 | 3033 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3034 | } |
nexpaq | 0:6c56fb4bc5f0 | 3035 | |
nexpaq | 0:6c56fb4bc5f0 | 3036 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3037 | * |
nexpaq | 0:6c56fb4bc5f0 | 3038 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3039 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3040 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3041 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3042 | template<typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3043 | Callback<R(A0, A1)> callback(const T *obj, R (T::*func)(A0, A1) const) { |
nexpaq | 0:6c56fb4bc5f0 | 3044 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3045 | } |
nexpaq | 0:6c56fb4bc5f0 | 3046 | |
nexpaq | 0:6c56fb4bc5f0 | 3047 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3048 | * |
nexpaq | 0:6c56fb4bc5f0 | 3049 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3050 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3051 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3052 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3053 | template<typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3054 | Callback<R(A0, A1)> callback(volatile T *obj, R (T::*func)(A0, A1) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3055 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3056 | } |
nexpaq | 0:6c56fb4bc5f0 | 3057 | |
nexpaq | 0:6c56fb4bc5f0 | 3058 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3059 | * |
nexpaq | 0:6c56fb4bc5f0 | 3060 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3061 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3062 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3063 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3064 | template<typename T, typename R, typename A0, typename A1> |
nexpaq | 0:6c56fb4bc5f0 | 3065 | Callback<R(A0, A1)> callback(const volatile T *obj, R (T::*func)(A0, A1) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3066 | return Callback<R(A0, A1)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3067 | } |
nexpaq | 0:6c56fb4bc5f0 | 3068 | |
nexpaq | 0:6c56fb4bc5f0 | 3069 | |
nexpaq | 0:6c56fb4bc5f0 | 3070 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3071 | * |
nexpaq | 0:6c56fb4bc5f0 | 3072 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3073 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3074 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3075 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3076 | Callback<R(A0, A1, A2)> callback(R (*func)(A0, A1, A2) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 3077 | return Callback<R(A0, A1, A2)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3078 | } |
nexpaq | 0:6c56fb4bc5f0 | 3079 | |
nexpaq | 0:6c56fb4bc5f0 | 3080 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3081 | * |
nexpaq | 0:6c56fb4bc5f0 | 3082 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3083 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3084 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3085 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3086 | Callback<R(A0, A1, A2)> callback(const Callback<R(A0, A1, A2)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 3087 | return Callback<R(A0, A1, A2)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3088 | } |
nexpaq | 0:6c56fb4bc5f0 | 3089 | |
nexpaq | 0:6c56fb4bc5f0 | 3090 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3091 | * |
nexpaq | 0:6c56fb4bc5f0 | 3092 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3093 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3094 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3095 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3096 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3097 | Callback<R(A0, A1, A2)> callback(void *obj, R (*func)(void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3098 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3099 | } |
nexpaq | 0:6c56fb4bc5f0 | 3100 | |
nexpaq | 0:6c56fb4bc5f0 | 3101 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3102 | * |
nexpaq | 0:6c56fb4bc5f0 | 3103 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3104 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3105 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3106 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3107 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3108 | Callback<R(A0, A1, A2)> callback(const void *obj, R (*func)(const void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3109 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3110 | } |
nexpaq | 0:6c56fb4bc5f0 | 3111 | |
nexpaq | 0:6c56fb4bc5f0 | 3112 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3113 | * |
nexpaq | 0:6c56fb4bc5f0 | 3114 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3115 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3116 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3117 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3118 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3119 | Callback<R(A0, A1, A2)> callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3120 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3121 | } |
nexpaq | 0:6c56fb4bc5f0 | 3122 | |
nexpaq | 0:6c56fb4bc5f0 | 3123 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3124 | * |
nexpaq | 0:6c56fb4bc5f0 | 3125 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3126 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3127 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3128 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3129 | template <typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3130 | Callback<R(A0, A1, A2)> callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3131 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3132 | } |
nexpaq | 0:6c56fb4bc5f0 | 3133 | |
nexpaq | 0:6c56fb4bc5f0 | 3134 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3135 | * |
nexpaq | 0:6c56fb4bc5f0 | 3136 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3137 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3138 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3139 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3140 | template <typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3141 | Callback<R(A0, A1, A2)> callback(T *obj, R (*func)(T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3142 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3143 | } |
nexpaq | 0:6c56fb4bc5f0 | 3144 | |
nexpaq | 0:6c56fb4bc5f0 | 3145 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3146 | * |
nexpaq | 0:6c56fb4bc5f0 | 3147 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3148 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3149 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3150 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3151 | template <typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3152 | Callback<R(A0, A1, A2)> callback(const T *obj, R (*func)(const T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3153 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3154 | } |
nexpaq | 0:6c56fb4bc5f0 | 3155 | |
nexpaq | 0:6c56fb4bc5f0 | 3156 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3157 | * |
nexpaq | 0:6c56fb4bc5f0 | 3158 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3159 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3160 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3161 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3162 | template <typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3163 | Callback<R(A0, A1, A2)> callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3164 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3165 | } |
nexpaq | 0:6c56fb4bc5f0 | 3166 | |
nexpaq | 0:6c56fb4bc5f0 | 3167 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3168 | * |
nexpaq | 0:6c56fb4bc5f0 | 3169 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3170 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3171 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3172 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3173 | template <typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3174 | Callback<R(A0, A1, A2)> callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3175 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3176 | } |
nexpaq | 0:6c56fb4bc5f0 | 3177 | |
nexpaq | 0:6c56fb4bc5f0 | 3178 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3179 | * |
nexpaq | 0:6c56fb4bc5f0 | 3180 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3181 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3182 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3183 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3184 | template<typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3185 | Callback<R(A0, A1, A2)> callback(T *obj, R (T::*func)(A0, A1, A2)) { |
nexpaq | 0:6c56fb4bc5f0 | 3186 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3187 | } |
nexpaq | 0:6c56fb4bc5f0 | 3188 | |
nexpaq | 0:6c56fb4bc5f0 | 3189 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3190 | * |
nexpaq | 0:6c56fb4bc5f0 | 3191 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3192 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3193 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3194 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3195 | template<typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3196 | Callback<R(A0, A1, A2)> callback(const T *obj, R (T::*func)(A0, A1, A2) const) { |
nexpaq | 0:6c56fb4bc5f0 | 3197 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3198 | } |
nexpaq | 0:6c56fb4bc5f0 | 3199 | |
nexpaq | 0:6c56fb4bc5f0 | 3200 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3201 | * |
nexpaq | 0:6c56fb4bc5f0 | 3202 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3203 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3204 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3205 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3206 | template<typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3207 | Callback<R(A0, A1, A2)> callback(volatile T *obj, R (T::*func)(A0, A1, A2) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3208 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3209 | } |
nexpaq | 0:6c56fb4bc5f0 | 3210 | |
nexpaq | 0:6c56fb4bc5f0 | 3211 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3212 | * |
nexpaq | 0:6c56fb4bc5f0 | 3213 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3214 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3215 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3216 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3217 | template<typename T, typename R, typename A0, typename A1, typename A2> |
nexpaq | 0:6c56fb4bc5f0 | 3218 | Callback<R(A0, A1, A2)> callback(const volatile T *obj, R (T::*func)(A0, A1, A2) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3219 | return Callback<R(A0, A1, A2)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3220 | } |
nexpaq | 0:6c56fb4bc5f0 | 3221 | |
nexpaq | 0:6c56fb4bc5f0 | 3222 | |
nexpaq | 0:6c56fb4bc5f0 | 3223 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3224 | * |
nexpaq | 0:6c56fb4bc5f0 | 3225 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3226 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3227 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3228 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3229 | Callback<R(A0, A1, A2, A3)> callback(R (*func)(A0, A1, A2, A3) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 3230 | return Callback<R(A0, A1, A2, A3)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3231 | } |
nexpaq | 0:6c56fb4bc5f0 | 3232 | |
nexpaq | 0:6c56fb4bc5f0 | 3233 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3234 | * |
nexpaq | 0:6c56fb4bc5f0 | 3235 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3236 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3237 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3238 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3239 | Callback<R(A0, A1, A2, A3)> callback(const Callback<R(A0, A1, A2, A3)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 3240 | return Callback<R(A0, A1, A2, A3)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3241 | } |
nexpaq | 0:6c56fb4bc5f0 | 3242 | |
nexpaq | 0:6c56fb4bc5f0 | 3243 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3244 | * |
nexpaq | 0:6c56fb4bc5f0 | 3245 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3246 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3247 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3248 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3249 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3250 | Callback<R(A0, A1, A2, A3)> callback(void *obj, R (*func)(void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3251 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3252 | } |
nexpaq | 0:6c56fb4bc5f0 | 3253 | |
nexpaq | 0:6c56fb4bc5f0 | 3254 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3255 | * |
nexpaq | 0:6c56fb4bc5f0 | 3256 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3257 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3258 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3259 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3260 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3261 | Callback<R(A0, A1, A2, A3)> callback(const void *obj, R (*func)(const void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3262 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3263 | } |
nexpaq | 0:6c56fb4bc5f0 | 3264 | |
nexpaq | 0:6c56fb4bc5f0 | 3265 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3266 | * |
nexpaq | 0:6c56fb4bc5f0 | 3267 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3268 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3269 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3270 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3271 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3272 | Callback<R(A0, A1, A2, A3)> callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3273 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3274 | } |
nexpaq | 0:6c56fb4bc5f0 | 3275 | |
nexpaq | 0:6c56fb4bc5f0 | 3276 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3277 | * |
nexpaq | 0:6c56fb4bc5f0 | 3278 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3279 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3280 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3281 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3282 | template <typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3283 | Callback<R(A0, A1, A2, A3)> callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3284 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3285 | } |
nexpaq | 0:6c56fb4bc5f0 | 3286 | |
nexpaq | 0:6c56fb4bc5f0 | 3287 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3288 | * |
nexpaq | 0:6c56fb4bc5f0 | 3289 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3290 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3291 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3292 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3293 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3294 | Callback<R(A0, A1, A2, A3)> callback(T *obj, R (*func)(T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3295 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3296 | } |
nexpaq | 0:6c56fb4bc5f0 | 3297 | |
nexpaq | 0:6c56fb4bc5f0 | 3298 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3299 | * |
nexpaq | 0:6c56fb4bc5f0 | 3300 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3301 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3302 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3303 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3304 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3305 | Callback<R(A0, A1, A2, A3)> callback(const T *obj, R (*func)(const T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3306 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3307 | } |
nexpaq | 0:6c56fb4bc5f0 | 3308 | |
nexpaq | 0:6c56fb4bc5f0 | 3309 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3310 | * |
nexpaq | 0:6c56fb4bc5f0 | 3311 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3312 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3313 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3314 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3315 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3316 | Callback<R(A0, A1, A2, A3)> callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3317 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3318 | } |
nexpaq | 0:6c56fb4bc5f0 | 3319 | |
nexpaq | 0:6c56fb4bc5f0 | 3320 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3321 | * |
nexpaq | 0:6c56fb4bc5f0 | 3322 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3323 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3324 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3325 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3326 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3327 | Callback<R(A0, A1, A2, A3)> callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3328 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3329 | } |
nexpaq | 0:6c56fb4bc5f0 | 3330 | |
nexpaq | 0:6c56fb4bc5f0 | 3331 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3332 | * |
nexpaq | 0:6c56fb4bc5f0 | 3333 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3334 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3335 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3336 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3337 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3338 | Callback<R(A0, A1, A2, A3)> callback(T *obj, R (T::*func)(A0, A1, A2, A3)) { |
nexpaq | 0:6c56fb4bc5f0 | 3339 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3340 | } |
nexpaq | 0:6c56fb4bc5f0 | 3341 | |
nexpaq | 0:6c56fb4bc5f0 | 3342 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3343 | * |
nexpaq | 0:6c56fb4bc5f0 | 3344 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3345 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3346 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3347 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3348 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3349 | Callback<R(A0, A1, A2, A3)> callback(const T *obj, R (T::*func)(A0, A1, A2, A3) const) { |
nexpaq | 0:6c56fb4bc5f0 | 3350 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3351 | } |
nexpaq | 0:6c56fb4bc5f0 | 3352 | |
nexpaq | 0:6c56fb4bc5f0 | 3353 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3354 | * |
nexpaq | 0:6c56fb4bc5f0 | 3355 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3356 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3357 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3358 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3359 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3360 | Callback<R(A0, A1, A2, A3)> callback(volatile T *obj, R (T::*func)(A0, A1, A2, A3) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3361 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3362 | } |
nexpaq | 0:6c56fb4bc5f0 | 3363 | |
nexpaq | 0:6c56fb4bc5f0 | 3364 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3365 | * |
nexpaq | 0:6c56fb4bc5f0 | 3366 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3367 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3368 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3369 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3370 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3> |
nexpaq | 0:6c56fb4bc5f0 | 3371 | Callback<R(A0, A1, A2, A3)> callback(const volatile T *obj, R (T::*func)(A0, A1, A2, A3) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3372 | return Callback<R(A0, A1, A2, A3)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3373 | } |
nexpaq | 0:6c56fb4bc5f0 | 3374 | |
nexpaq | 0:6c56fb4bc5f0 | 3375 | |
nexpaq | 0:6c56fb4bc5f0 | 3376 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3377 | * |
nexpaq | 0:6c56fb4bc5f0 | 3378 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3379 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3380 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3381 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3382 | Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(A0, A1, A2, A3, A4) = 0) { |
nexpaq | 0:6c56fb4bc5f0 | 3383 | return Callback<R(A0, A1, A2, A3, A4)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3384 | } |
nexpaq | 0:6c56fb4bc5f0 | 3385 | |
nexpaq | 0:6c56fb4bc5f0 | 3386 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3387 | * |
nexpaq | 0:6c56fb4bc5f0 | 3388 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3389 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3390 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3391 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3392 | Callback<R(A0, A1, A2, A3, A4)> callback(const Callback<R(A0, A1, A2, A3, A4)> &func) { |
nexpaq | 0:6c56fb4bc5f0 | 3393 | return Callback<R(A0, A1, A2, A3, A4)>(func); |
nexpaq | 0:6c56fb4bc5f0 | 3394 | } |
nexpaq | 0:6c56fb4bc5f0 | 3395 | |
nexpaq | 0:6c56fb4bc5f0 | 3396 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3397 | * |
nexpaq | 0:6c56fb4bc5f0 | 3398 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3399 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3400 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3401 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3402 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3403 | Callback<R(A0, A1, A2, A3, A4)> callback(void *obj, R (*func)(void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3404 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3405 | } |
nexpaq | 0:6c56fb4bc5f0 | 3406 | |
nexpaq | 0:6c56fb4bc5f0 | 3407 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3408 | * |
nexpaq | 0:6c56fb4bc5f0 | 3409 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3410 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3411 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3412 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3413 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3414 | Callback<R(A0, A1, A2, A3, A4)> callback(const void *obj, R (*func)(const void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3415 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3416 | } |
nexpaq | 0:6c56fb4bc5f0 | 3417 | |
nexpaq | 0:6c56fb4bc5f0 | 3418 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3419 | * |
nexpaq | 0:6c56fb4bc5f0 | 3420 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3421 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3422 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3423 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3424 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3425 | Callback<R(A0, A1, A2, A3, A4)> callback(volatile void *obj, R (*func)(volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3426 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3427 | } |
nexpaq | 0:6c56fb4bc5f0 | 3428 | |
nexpaq | 0:6c56fb4bc5f0 | 3429 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3430 | * |
nexpaq | 0:6c56fb4bc5f0 | 3431 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3432 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3433 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3434 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3435 | template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3436 | Callback<R(A0, A1, A2, A3, A4)> callback(const volatile void *obj, R (*func)(const volatile void*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3437 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3438 | } |
nexpaq | 0:6c56fb4bc5f0 | 3439 | |
nexpaq | 0:6c56fb4bc5f0 | 3440 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3441 | * |
nexpaq | 0:6c56fb4bc5f0 | 3442 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3443 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3444 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3445 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3446 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3447 | Callback<R(A0, A1, A2, A3, A4)> callback(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3448 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3449 | } |
nexpaq | 0:6c56fb4bc5f0 | 3450 | |
nexpaq | 0:6c56fb4bc5f0 | 3451 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3452 | * |
nexpaq | 0:6c56fb4bc5f0 | 3453 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3454 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3455 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3456 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3457 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3458 | Callback<R(A0, A1, A2, A3, A4)> callback(const T *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3459 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3460 | } |
nexpaq | 0:6c56fb4bc5f0 | 3461 | |
nexpaq | 0:6c56fb4bc5f0 | 3462 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3463 | * |
nexpaq | 0:6c56fb4bc5f0 | 3464 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3465 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3466 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3467 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3468 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3469 | Callback<R(A0, A1, A2, A3, A4)> callback(volatile T *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3470 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3471 | } |
nexpaq | 0:6c56fb4bc5f0 | 3472 | |
nexpaq | 0:6c56fb4bc5f0 | 3473 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3474 | * |
nexpaq | 0:6c56fb4bc5f0 | 3475 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3476 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3477 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3478 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3479 | template <typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3480 | Callback<R(A0, A1, A2, A3, A4)> callback(const volatile T *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3481 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3482 | } |
nexpaq | 0:6c56fb4bc5f0 | 3483 | |
nexpaq | 0:6c56fb4bc5f0 | 3484 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3485 | * |
nexpaq | 0:6c56fb4bc5f0 | 3486 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3487 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3488 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3489 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3490 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3491 | Callback<R(A0, A1, A2, A3, A4)> callback(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) { |
nexpaq | 0:6c56fb4bc5f0 | 3492 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3493 | } |
nexpaq | 0:6c56fb4bc5f0 | 3494 | |
nexpaq | 0:6c56fb4bc5f0 | 3495 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3496 | * |
nexpaq | 0:6c56fb4bc5f0 | 3497 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3498 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3499 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3500 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3501 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3502 | Callback<R(A0, A1, A2, A3, A4)> callback(const T *obj, R (T::*func)(A0, A1, A2, A3, A4) const) { |
nexpaq | 0:6c56fb4bc5f0 | 3503 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3504 | } |
nexpaq | 0:6c56fb4bc5f0 | 3505 | |
nexpaq | 0:6c56fb4bc5f0 | 3506 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3507 | * |
nexpaq | 0:6c56fb4bc5f0 | 3508 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3509 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3510 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3511 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3512 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3513 | Callback<R(A0, A1, A2, A3, A4)> callback(volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3514 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3515 | } |
nexpaq | 0:6c56fb4bc5f0 | 3516 | |
nexpaq | 0:6c56fb4bc5f0 | 3517 | /** Create a callback class with type infered from the arguments |
nexpaq | 0:6c56fb4bc5f0 | 3518 | * |
nexpaq | 0:6c56fb4bc5f0 | 3519 | * @param obj Optional pointer to object to bind to function |
nexpaq | 0:6c56fb4bc5f0 | 3520 | * @param func Static function to attach |
nexpaq | 0:6c56fb4bc5f0 | 3521 | * @return Callback with infered type |
nexpaq | 0:6c56fb4bc5f0 | 3522 | */ |
nexpaq | 0:6c56fb4bc5f0 | 3523 | template<typename T, typename R, typename A0, typename A1, typename A2, typename A3, typename A4> |
nexpaq | 0:6c56fb4bc5f0 | 3524 | Callback<R(A0, A1, A2, A3, A4)> callback(const volatile T *obj, R (T::*func)(A0, A1, A2, A3, A4) const volatile) { |
nexpaq | 0:6c56fb4bc5f0 | 3525 | return Callback<R(A0, A1, A2, A3, A4)>(obj, func); |
nexpaq | 0:6c56fb4bc5f0 | 3526 | } |
nexpaq | 0:6c56fb4bc5f0 | 3527 | |
nexpaq | 0:6c56fb4bc5f0 | 3528 | |
nexpaq | 0:6c56fb4bc5f0 | 3529 | } // namespace mbed |
nexpaq | 0:6c56fb4bc5f0 | 3530 | |
nexpaq | 0:6c56fb4bc5f0 | 3531 | #endif |