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