dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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