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