mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
FunctionPointer.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2015 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #ifndef MBED_FUNCTIONPOINTER_H 00018 #define MBED_FUNCTIONPOINTER_H 00019 00020 #include "platform/Callback.h" 00021 #include "platform/mbed_toolchain.h" 00022 #include <string.h> 00023 #include <stdint.h> 00024 00025 namespace mbed { 00026 /** \addtogroup platform */ 00027 /** @{*/ 00028 /** 00029 * \defgroup platform_FunctionPointer FunctionPointer class 00030 * @{ 00031 */ 00032 00033 // Declarations for backwards compatibility 00034 // To be foward compatible, code should adopt the Callback class 00035 template <typename R, typename A1> 00036 class FunctionPointerArg1 : public Callback<R(A1)> { 00037 public: 00038 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00039 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") 00040 FunctionPointerArg1(R(*function)(A1) = 0) 00041 : Callback<R(A1)>(function) {} 00042 00043 template<typename T> 00044 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00045 "FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>") 00046 FunctionPointerArg1(T *object, R(T::*member)(A1)) 00047 : Callback<R(A1)>(object, member) {} 00048 00049 R(*get_function())(A1) 00050 { 00051 return *reinterpret_cast<R(* *)(A1)>(this); 00052 } 00053 00054 R call(A1 a1) const 00055 { 00056 if (!Callback<R(A1)>::operator bool()) { 00057 return (R)0; 00058 } 00059 00060 return Callback<R(A1)>::call(a1); 00061 } 00062 00063 R operator()(A1 a1) const 00064 { 00065 return Callback<R(A1)>::call(a1); 00066 } 00067 }; 00068 00069 template <typename R> 00070 class FunctionPointerArg1<R, void> : public Callback<R()> { 00071 public: 00072 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00073 "FunctionPointer has been replaced by Callback<void()>") 00074 FunctionPointerArg1(R(*function)() = 0) 00075 : Callback<R()>(function) {} 00076 00077 template<typename T> 00078 MBED_DEPRECATED_SINCE("mbed-os-5.1", 00079 "FunctionPointer has been replaced by Callback<void()>") 00080 FunctionPointerArg1(T *object, R(T::*member)()) 00081 : Callback<R()>(object, member) {} 00082 00083 R(*get_function())() 00084 { 00085 return *reinterpret_cast<R(* *)()>(this); 00086 } 00087 00088 R call() const 00089 { 00090 if (!Callback<R()>::operator bool()) { 00091 return (R)0; 00092 } 00093 00094 return Callback<R()>::call(); 00095 } 00096 00097 R operator()() const 00098 { 00099 return Callback<R()>::call(); 00100 } 00101 }; 00102 00103 typedef FunctionPointerArg1<void, void> FunctionPointer; 00104 00105 /**@}*/ 00106 00107 /**@}*/ 00108 00109 00110 } // namespace mbed 00111 00112 #endif
Generated on Tue Jul 12 2022 20:41:14 by 1.7.2