mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
platform/FunctionPointer.h@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Child:
- 160:d5399cc887bb
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
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" |
<> | 149:156823d33999 | 20 | #include "platform/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 | |
<> | 149:156823d33999 | 29 | // Declarations for backwards compatibility |
<> | 149:156823d33999 | 30 | // To be foward compatible, code should adopt the Callback class |
<> | 149:156823d33999 | 31 | template <typename R, typename A1> |
<> | 149:156823d33999 | 32 | class FunctionPointerArg1 : public Callback<R(A1)> { |
<> | 149:156823d33999 | 33 | public: |
<> | 149:156823d33999 | 34 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
<> | 149:156823d33999 | 35 | "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") |
<> | 149:156823d33999 | 36 | FunctionPointerArg1(R (*function)(A1) = 0) |
<> | 149:156823d33999 | 37 | : Callback<R(A1)>(function) {} |
<> | 149:156823d33999 | 38 | |
<> | 149:156823d33999 | 39 | template<typename T> |
<> | 149:156823d33999 | 40 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
<> | 149:156823d33999 | 41 | "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") |
<> | 149:156823d33999 | 42 | FunctionPointerArg1(T *object, R (T::*member)(A1)) |
<> | 149:156823d33999 | 43 | : Callback<R(A1)>(object, member) {} |
<> | 149:156823d33999 | 44 | |
<> | 149:156823d33999 | 45 | R (*get_function())(A1) { |
<> | 149:156823d33999 | 46 | return *reinterpret_cast<R (**)(A1)>(this); |
<> | 149:156823d33999 | 47 | } |
<> | 149:156823d33999 | 48 | |
<> | 149:156823d33999 | 49 | R call(A1 a1) const { |
<> | 149:156823d33999 | 50 | if (!Callback<R(A1)>::operator bool()) { |
<> | 149:156823d33999 | 51 | return (R)0; |
<> | 149:156823d33999 | 52 | } |
<> | 149:156823d33999 | 53 | |
<> | 149:156823d33999 | 54 | return Callback<R(A1)>::call(a1); |
<> | 149:156823d33999 | 55 | } |
<> | 149:156823d33999 | 56 | |
<> | 149:156823d33999 | 57 | R operator()(A1 a1) const { |
<> | 149:156823d33999 | 58 | return Callback<R(A1)>::call(a1); |
<> | 149:156823d33999 | 59 | } |
<> | 149:156823d33999 | 60 | }; |
<> | 149:156823d33999 | 61 | |
<> | 149:156823d33999 | 62 | template <typename R> |
<> | 149:156823d33999 | 63 | class FunctionPointerArg1<R, void> : public Callback<R()> { |
<> | 149:156823d33999 | 64 | public: |
<> | 149:156823d33999 | 65 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
<> | 149:156823d33999 | 66 | "FunctionPointer has been replaced by Callback<void()>") |
<> | 149:156823d33999 | 67 | FunctionPointerArg1(R (*function)() = 0) |
<> | 149:156823d33999 | 68 | : Callback<R()>(function) {} |
<> | 149:156823d33999 | 69 | |
<> | 149:156823d33999 | 70 | template<typename T> |
<> | 149:156823d33999 | 71 | MBED_DEPRECATED_SINCE("mbed-os-5.1", |
<> | 149:156823d33999 | 72 | "FunctionPointer has been replaced by Callback<void()>") |
<> | 149:156823d33999 | 73 | FunctionPointerArg1(T *object, R (T::*member)()) |
<> | 149:156823d33999 | 74 | : Callback<R()>(object, member) {} |
<> | 149:156823d33999 | 75 | |
<> | 149:156823d33999 | 76 | R (*get_function())() { |
<> | 149:156823d33999 | 77 | return *reinterpret_cast<R (**)()>(this); |
<> | 149:156823d33999 | 78 | } |
<> | 149:156823d33999 | 79 | |
<> | 149:156823d33999 | 80 | R call() const { |
<> | 149:156823d33999 | 81 | if (!Callback<R()>::operator bool()) { |
<> | 149:156823d33999 | 82 | return (R)0; |
<> | 149:156823d33999 | 83 | } |
<> | 149:156823d33999 | 84 | |
<> | 149:156823d33999 | 85 | return Callback<R()>::call(); |
<> | 149:156823d33999 | 86 | } |
<> | 149:156823d33999 | 87 | |
<> | 149:156823d33999 | 88 | R operator()() const { |
<> | 149:156823d33999 | 89 | return Callback<R()>::call(); |
<> | 149:156823d33999 | 90 | } |
<> | 149:156823d33999 | 91 | }; |
<> | 149:156823d33999 | 92 | |
<> | 149:156823d33999 | 93 | typedef FunctionPointerArg1<void, void> FunctionPointer; |
<> | 149:156823d33999 | 94 | |
<> | 149:156823d33999 | 95 | |
<> | 149:156823d33999 | 96 | } // namespace mbed |
<> | 149:156823d33999 | 97 | |
<> | 149:156823d33999 | 98 | #endif |
<> | 149:156823d33999 | 99 | |
<> | 149:156823d33999 | 100 | /** @}*/ |