2013-08-08 09:58:34 +00:00
|
|
|
/* mbed Microcontroller Library
|
2015-04-23 13:56:34 +00:00
|
|
|
* Copyright (c) 2006-2015 ARM Limited
|
2013-08-08 09:58:34 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
#ifndef MBED_FUNCTIONPOINTER_H
|
|
|
|
#define MBED_FUNCTIONPOINTER_H
|
|
|
|
|
2016-10-01 07:11:36 +00:00
|
|
|
#include "platform/Callback.h"
|
2017-01-27 11:10:28 +00:00
|
|
|
#include "platform/mbed_toolchain.h"
|
2013-08-08 09:58:34 +00:00
|
|
|
#include <string.h>
|
2015-04-23 13:56:34 +00:00
|
|
|
#include <stdint.h>
|
2013-08-08 09:58:34 +00:00
|
|
|
|
|
|
|
namespace mbed {
|
2016-10-04 20:02:44 +00:00
|
|
|
/** \addtogroup platform */
|
2017-10-24 15:05:45 +00:00
|
|
|
/** @{*/
|
|
|
|
/**
|
|
|
|
* \defgroup platform_FunctionPointer FunctionPointer class
|
|
|
|
* @{
|
|
|
|
*/
|
2013-08-08 09:58:34 +00:00
|
|
|
|
2016-05-13 19:55:48 +00:00
|
|
|
// Declarations for backwards compatibility
|
|
|
|
// To be foward compatible, code should adopt the Callback class
|
2015-04-23 13:56:34 +00:00
|
|
|
template <typename R, typename A1>
|
2016-05-13 19:55:48 +00:00
|
|
|
class FunctionPointerArg1 : public Callback<R(A1)> {
|
2013-08-08 09:58:34 +00:00
|
|
|
public:
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2016-08-08 22:12:48 +00:00
|
|
|
"FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
|
2016-05-13 19:55:48 +00:00
|
|
|
FunctionPointerArg1(R (*function)(A1) = 0)
|
|
|
|
: Callback<R(A1)>(function) {}
|
2015-04-23 13:56:34 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2016-08-08 22:12:48 +00:00
|
|
|
"FunctionPointerArg1<R, A> has been replaced by Callback<R(A)>")
|
2016-05-13 19:55:48 +00:00
|
|
|
FunctionPointerArg1(T *object, R (T::*member)(A1))
|
|
|
|
: Callback<R(A1)>(object, member) {}
|
2015-04-23 13:56:34 +00:00
|
|
|
|
2016-05-13 19:55:48 +00:00
|
|
|
R (*get_function())(A1) {
|
|
|
|
return *reinterpret_cast<R (**)(A1)>(this);
|
2015-04-23 13:56:34 +00:00
|
|
|
}
|
2016-08-19 20:49:49 +00:00
|
|
|
|
|
|
|
R call(A1 a1) const {
|
|
|
|
if (!Callback<R(A1)>::operator bool()) {
|
|
|
|
return (R)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Callback<R(A1)>::call(a1);
|
|
|
|
}
|
|
|
|
|
|
|
|
R operator()(A1 a1) const {
|
|
|
|
return Callback<R(A1)>::call(a1);
|
|
|
|
}
|
2015-04-23 13:56:34 +00:00
|
|
|
};
|
2013-08-08 09:58:34 +00:00
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
template <typename R>
|
2016-05-13 19:55:48 +00:00
|
|
|
class FunctionPointerArg1<R, void> : public Callback<R()> {
|
2015-04-23 13:56:34 +00:00
|
|
|
public:
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2016-08-08 22:12:48 +00:00
|
|
|
"FunctionPointer has been replaced by Callback<void()>")
|
2016-05-13 19:55:48 +00:00
|
|
|
FunctionPointerArg1(R (*function)() = 0)
|
|
|
|
: Callback<R()>(function) {}
|
2013-08-08 09:58:34 +00:00
|
|
|
|
|
|
|
template<typename T>
|
2016-08-17 01:30:20 +00:00
|
|
|
MBED_DEPRECATED_SINCE("mbed-os-5.1",
|
2016-08-08 22:12:48 +00:00
|
|
|
"FunctionPointer has been replaced by Callback<void()>")
|
2016-05-13 19:55:48 +00:00
|
|
|
FunctionPointerArg1(T *object, R (T::*member)())
|
|
|
|
: Callback<R()>(object, member) {}
|
2013-08-08 09:58:34 +00:00
|
|
|
|
2016-05-13 19:55:48 +00:00
|
|
|
R (*get_function())() {
|
|
|
|
return *reinterpret_cast<R (**)()>(this);
|
2013-08-08 09:58:34 +00:00
|
|
|
}
|
2016-08-19 20:49:49 +00:00
|
|
|
|
|
|
|
R call() const {
|
|
|
|
if (!Callback<R()>::operator bool()) {
|
|
|
|
return (R)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Callback<R()>::call();
|
|
|
|
}
|
|
|
|
|
|
|
|
R operator()() const {
|
|
|
|
return Callback<R()>::call();
|
|
|
|
}
|
2013-08-08 09:58:34 +00:00
|
|
|
};
|
|
|
|
|
2015-04-23 13:56:34 +00:00
|
|
|
typedef FunctionPointerArg1<void, void> FunctionPointer;
|
|
|
|
|
2017-10-24 15:05:45 +00:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2016-05-13 19:55:48 +00:00
|
|
|
|
2013-08-08 09:58:34 +00:00
|
|
|
} // namespace mbed
|
|
|
|
|
|
|
|
#endif
|