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