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