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