The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
158:1c57384330a6
Child:
170:e95d10626187
mbed library. Release version 162

Who changed what in which revision?

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