CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Sun Nov 04 18:44:51 2018 -0700
Revision:
0:aa13e1c335cd
create new repo for show2me

Who changed what in which revision?

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