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

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.