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