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