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