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