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