mbed library sources. Supersedes mbed-src.

Dependents:   BREAK_SENSOR_LED

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Thu Nov 23 11:57:25 2017 +0000
Revision:
178:79309dc6340a
Parent:
167:e84263d55307
mbed-dev library. Release version 156

Who changed what in which revision?

UserRevisionLine numberNew 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 */
AnnaBridge 178:79309dc6340a 26 /** @{*/
AnnaBridge 178:79309dc6340a 27 /**
AnnaBridge 178:79309dc6340a 28 * \defgroup platform_FunctionPointer FunctionPointer class
AnnaBridge 178:79309dc6340a 29 * @{
AnnaBridge 178:79309dc6340a 30 */
<> 149:156823d33999 31
<> 149:156823d33999 32 // Declarations for backwards compatibility
<> 149:156823d33999 33 // To be foward compatible, code should adopt the Callback class
<> 149:156823d33999 34 template <typename R, typename A1>
<> 149:156823d33999 35 class FunctionPointerArg1 : public Callback<R(A1)> {
<> 149:156823d33999 36 public:
<> 149:156823d33999 37 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 149:156823d33999 38 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
<> 149:156823d33999 39 FunctionPointerArg1(R (*function)(A1) = 0)
<> 149:156823d33999 40 : Callback<R(A1)>(function) {}
<> 149:156823d33999 41
<> 149:156823d33999 42 template<typename T>
<> 149:156823d33999 43 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 149:156823d33999 44 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
<> 149:156823d33999 45 FunctionPointerArg1(T *object, R (T::*member)(A1))
<> 149:156823d33999 46 : Callback<R(A1)>(object, member) {}
<> 149:156823d33999 47
<> 149:156823d33999 48 R (*get_function())(A1) {
<> 149:156823d33999 49 return *reinterpret_cast<R (**)(A1)>(this);
<> 149:156823d33999 50 }
<> 149:156823d33999 51
<> 149:156823d33999 52 R call(A1 a1) const {
<> 149:156823d33999 53 if (!Callback<R(A1)>::operator bool()) {
<> 149:156823d33999 54 return (R)0;
<> 149:156823d33999 55 }
<> 149:156823d33999 56
<> 149:156823d33999 57 return Callback<R(A1)>::call(a1);
<> 149:156823d33999 58 }
<> 149:156823d33999 59
<> 149:156823d33999 60 R operator()(A1 a1) const {
<> 149:156823d33999 61 return Callback<R(A1)>::call(a1);
<> 149:156823d33999 62 }
<> 149:156823d33999 63 };
<> 149:156823d33999 64
<> 149:156823d33999 65 template <typename R>
<> 149:156823d33999 66 class FunctionPointerArg1<R, void> : public Callback<R()> {
<> 149:156823d33999 67 public:
<> 149:156823d33999 68 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 149:156823d33999 69 "FunctionPointer has been replaced by Callback<void()>")
<> 149:156823d33999 70 FunctionPointerArg1(R (*function)() = 0)
<> 149:156823d33999 71 : Callback<R()>(function) {}
<> 149:156823d33999 72
<> 149:156823d33999 73 template<typename T>
<> 149:156823d33999 74 MBED_DEPRECATED_SINCE("mbed-os-5.1",
<> 149:156823d33999 75 "FunctionPointer has been replaced by Callback<void()>")
<> 149:156823d33999 76 FunctionPointerArg1(T *object, R (T::*member)())
<> 149:156823d33999 77 : Callback<R()>(object, member) {}
<> 149:156823d33999 78
<> 149:156823d33999 79 R (*get_function())() {
<> 149:156823d33999 80 return *reinterpret_cast<R (**)()>(this);
<> 149:156823d33999 81 }
<> 149:156823d33999 82
<> 149:156823d33999 83 R call() const {
<> 149:156823d33999 84 if (!Callback<R()>::operator bool()) {
<> 149:156823d33999 85 return (R)0;
<> 149:156823d33999 86 }
<> 149:156823d33999 87
<> 149:156823d33999 88 return Callback<R()>::call();
<> 149:156823d33999 89 }
<> 149:156823d33999 90
<> 149:156823d33999 91 R operator()() const {
<> 149:156823d33999 92 return Callback<R()>::call();
<> 149:156823d33999 93 }
<> 149:156823d33999 94 };
<> 149:156823d33999 95
<> 149:156823d33999 96 typedef FunctionPointerArg1<void, void> FunctionPointer;
<> 149:156823d33999 97
AnnaBridge 178:79309dc6340a 98 /**@}*/
AnnaBridge 178:79309dc6340a 99
AnnaBridge 178:79309dc6340a 100 /**@}*/
AnnaBridge 178:79309dc6340a 101
<> 149:156823d33999 102
<> 149:156823d33999 103 } // namespace mbed
<> 149:156823d33999 104
<> 149:156823d33999 105 #endif