BA
/
BaBoRo_test2
Backup 1
mbed-os/platform/FunctionPointer.h@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | /* mbed Microcontroller Library |
borlanic | 0:02dd72d1d465 | 2 | * Copyright (c) 2006-2015 ARM Limited |
borlanic | 0:02dd72d1d465 | 3 | * |
borlanic | 0:02dd72d1d465 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 6 | * You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 7 | * |
borlanic | 0:02dd72d1d465 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 9 | * |
borlanic | 0:02dd72d1d465 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 14 | * limitations under the License. |
borlanic | 0:02dd72d1d465 | 15 | */ |
borlanic | 0:02dd72d1d465 | 16 | #ifndef MBED_FUNCTIONPOINTER_H |
borlanic | 0:02dd72d1d465 | 17 | #define MBED_FUNCTIONPOINTER_H |
borlanic | 0:02dd72d1d465 | 18 | |
borlanic | 0:02dd72d1d465 | 19 | #include "platform/Callback.h" |
borlanic | 0:02dd72d1d465 | 20 | #include "platform/mbed_toolchain.h" |
borlanic | 0:02dd72d1d465 | 21 | #include <string.h> |
borlanic | 0:02dd72d1d465 | 22 | #include <stdint.h> |
borlanic | 0:02dd72d1d465 | 23 | |
borlanic | 0:02dd72d1d465 | 24 | namespace mbed { |
borlanic | 0:02dd72d1d465 | 25 | /** \addtogroup platform */ |
borlanic | 0:02dd72d1d465 | 26 | /** @{*/ |
borlanic | 0:02dd72d1d465 | 27 | /** |
borlanic | 0:02dd72d1d465 | 28 | * \defgroup platform_FunctionPointer FunctionPointer class |
borlanic | 0:02dd72d1d465 | 29 | * @{ |
borlanic | 0:02dd72d1d465 | 30 | */ |
borlanic | 0:02dd72d1d465 | 31 | |
borlanic | 0:02dd72d1d465 | 32 | // Declarations for backwards compatibility |
borlanic | 0:02dd72d1d465 | 33 | // To be foward compatible, code should adopt the Callback class |
borlanic | 0:02dd72d1d465 | 34 | template <typename R, typename A1> |
borlanic | 0:02dd72d1d465 | 35 | class FunctionPointerArg1 : public Callback<R(A1)> { |
borlanic | 0:02dd72d1d465 | 36 | public: |
borlanic | 0:02dd72d1d465 | 37 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
borlanic | 0:02dd72d1d465 | 38 | "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") |
borlanic | 0:02dd72d1d465 | 39 | FunctionPointerArg1(R (*function)(A1) = 0) |
borlanic | 0:02dd72d1d465 | 40 | : Callback<R(A1)>(function) {} |
borlanic | 0:02dd72d1d465 | 41 | |
borlanic | 0:02dd72d1d465 | 42 | template<typename T> |
borlanic | 0:02dd72d1d465 | 43 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
borlanic | 0:02dd72d1d465 | 44 | "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") |
borlanic | 0:02dd72d1d465 | 45 | FunctionPointerArg1(T *object, R (T::*member)(A1)) |
borlanic | 0:02dd72d1d465 | 46 | : Callback<R(A1)>(object, member) {} |
borlanic | 0:02dd72d1d465 | 47 | |
borlanic | 0:02dd72d1d465 | 48 | R (*get_function())(A1) { |
borlanic | 0:02dd72d1d465 | 49 | return *reinterpret_cast<R (**)(A1)>(this); |
borlanic | 0:02dd72d1d465 | 50 | } |
borlanic | 0:02dd72d1d465 | 51 | |
borlanic | 0:02dd72d1d465 | 52 | R call(A1 a1) const { |
borlanic | 0:02dd72d1d465 | 53 | if (!Callback<R(A1)>::operator bool()) { |
borlanic | 0:02dd72d1d465 | 54 | return (R)0; |
borlanic | 0:02dd72d1d465 | 55 | } |
borlanic | 0:02dd72d1d465 | 56 | |
borlanic | 0:02dd72d1d465 | 57 | return Callback<R(A1)>::call(a1); |
borlanic | 0:02dd72d1d465 | 58 | } |
borlanic | 0:02dd72d1d465 | 59 | |
borlanic | 0:02dd72d1d465 | 60 | R operator()(A1 a1) const { |
borlanic | 0:02dd72d1d465 | 61 | return Callback<R(A1)>::call(a1); |
borlanic | 0:02dd72d1d465 | 62 | } |
borlanic | 0:02dd72d1d465 | 63 | }; |
borlanic | 0:02dd72d1d465 | 64 | |
borlanic | 0:02dd72d1d465 | 65 | template <typename R> |
borlanic | 0:02dd72d1d465 | 66 | class FunctionPointerArg1<R, void> : public Callback<R()> { |
borlanic | 0:02dd72d1d465 | 67 | public: |
borlanic | 0:02dd72d1d465 | 68 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
borlanic | 0:02dd72d1d465 | 69 | "FunctionPointer has been replaced by Callback<void()>") |
borlanic | 0:02dd72d1d465 | 70 | FunctionPointerArg1(R (*function)() = 0) |
borlanic | 0:02dd72d1d465 | 71 | : Callback<R()>(function) {} |
borlanic | 0:02dd72d1d465 | 72 | |
borlanic | 0:02dd72d1d465 | 73 | template<typename T> |
borlanic | 0:02dd72d1d465 | 74 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
borlanic | 0:02dd72d1d465 | 75 | "FunctionPointer has been replaced by Callback<void()>") |
borlanic | 0:02dd72d1d465 | 76 | FunctionPointerArg1(T *object, R (T::*member)()) |
borlanic | 0:02dd72d1d465 | 77 | : Callback<R()>(object, member) {} |
borlanic | 0:02dd72d1d465 | 78 | |
borlanic | 0:02dd72d1d465 | 79 | R (*get_function())() { |
borlanic | 0:02dd72d1d465 | 80 | return *reinterpret_cast<R (**)()>(this); |
borlanic | 0:02dd72d1d465 | 81 | } |
borlanic | 0:02dd72d1d465 | 82 | |
borlanic | 0:02dd72d1d465 | 83 | R call() const { |
borlanic | 0:02dd72d1d465 | 84 | if (!Callback<R()>::operator bool()) { |
borlanic | 0:02dd72d1d465 | 85 | return (R)0; |
borlanic | 0:02dd72d1d465 | 86 | } |
borlanic | 0:02dd72d1d465 | 87 | |
borlanic | 0:02dd72d1d465 | 88 | return Callback<R()>::call(); |
borlanic | 0:02dd72d1d465 | 89 | } |
borlanic | 0:02dd72d1d465 | 90 | |
borlanic | 0:02dd72d1d465 | 91 | R operator()() const { |
borlanic | 0:02dd72d1d465 | 92 | return Callback<R()>::call(); |
borlanic | 0:02dd72d1d465 | 93 | } |
borlanic | 0:02dd72d1d465 | 94 | }; |
borlanic | 0:02dd72d1d465 | 95 | |
borlanic | 0:02dd72d1d465 | 96 | typedef FunctionPointerArg1<void, void> FunctionPointer; |
borlanic | 0:02dd72d1d465 | 97 | |
borlanic | 0:02dd72d1d465 | 98 | /**@}*/ |
borlanic | 0:02dd72d1d465 | 99 | |
borlanic | 0:02dd72d1d465 | 100 | /**@}*/ |
borlanic | 0:02dd72d1d465 | 101 | |
borlanic | 0:02dd72d1d465 | 102 | |
borlanic | 0:02dd72d1d465 | 103 | } // namespace mbed |
borlanic | 0:02dd72d1d465 | 104 | |
borlanic | 0:02dd72d1d465 | 105 | #endif |