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