libs
libuavcan
libuavcan
include
uavcan
util
method_binder.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3
*/
4
5
#ifndef UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
6
#define UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
7
8
#include <
uavcan/error.hpp
>
9
#include <
uavcan/build_config.hpp
>
10
#include <
uavcan/util/templates.hpp
>
11
12
namespace
uavcan
13
{
19
template
<
typename
ObjectPtr,
typename
MemFunPtr>
20
class
UAVCAN_EXPORT
MethodBinder
21
{
22
ObjectPtr
obj_
;
23
MemFunPtr
fun_
;
24
25
void
validateBeforeCall
()
const
26
{
27
if
(!
operator
bool
())
28
{
29
handleFatalError
(
"Null binder"
);
30
}
31
}
32
33
public
:
34
MethodBinder
()
35
: obj_()
36
, fun_()
37
{ }
38
39
MethodBinder
(ObjectPtr o, MemFunPtr f)
40
: obj_(o)
41
, fun_(
f
)
42
{ }
43
47
operator
bool()
const
48
{
49
return
coerceOrFallback<bool>(obj_,
true
) && coerceOrFallback<bool>(fun_,
true
);
50
}
51
55
void
operator()
()
56
{
57
validateBeforeCall();
58
(obj_->*fun_)();
59
}
60
64
template
<
typename
Par1>
65
void
operator()
(Par1& p1)
66
{
67
validateBeforeCall();
68
(obj_->*fun_)(p1);
69
}
70
74
template
<
typename
Par1,
typename
Par2>
75
void
operator()
(Par1& p1, Par2& p2)
76
{
77
validateBeforeCall();
78
(obj_->*fun_)(p1, p2);
79
}
80
};
81
82
}
83
84
#endif // UAVCAN_UTIL_METHOD_BINDER_HPP_INCLUDED
templates.hpp
uavcan::MethodBinder::MethodBinder
MethodBinder()
Definition:
method_binder.hpp:34
uavcan::MethodBinder::MethodBinder
MethodBinder(ObjectPtr o, MemFunPtr f)
Definition:
method_binder.hpp:39
f
f
uavcan::MethodBinder::operator()
void operator()(Par1 &p1)
Definition:
method_binder.hpp:65
uavcan::MethodBinder::operator()
void operator()()
Definition:
method_binder.hpp:55
UAVCAN_EXPORT
#define UAVCAN_EXPORT
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:108
uavcan::MethodBinder::operator()
void operator()(Par1 &p1, Par2 &p2)
Definition:
method_binder.hpp:75
uavcan::MethodBinder::validateBeforeCall
void validateBeforeCall() const
Definition:
method_binder.hpp:25
build_config.hpp
uavcan::MethodBinder
Definition:
method_binder.hpp:20
uavcan::handleFatalError
UAVCAN_EXPORT void handleFatalError(const char *msg)
Definition:
uc_error.cpp:20
uavcan
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:204
uavcan::MethodBinder::obj_
ObjectPtr obj_
Definition:
method_binder.hpp:22
uavcan::MethodBinder::fun_
MemFunPtr fun_
Definition:
method_binder.hpp:23
error.hpp
uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:02