mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
Improved MethodBinder
This commit is contained in:
parent
c1a8f818f8
commit
c7351c4bbb
@ -20,13 +20,9 @@ class MethodBinder
|
||||
ObjectPtr obj_;
|
||||
MemFunPtr fun_;
|
||||
|
||||
public:
|
||||
MethodBinder(ObjectPtr o, MemFunPtr f)
|
||||
: obj_(o)
|
||||
, fun_(f)
|
||||
void validateBeforeCall() const
|
||||
{
|
||||
if (!try_implicit_cast<bool>(o, true) ||
|
||||
!try_implicit_cast<bool>(f, true))
|
||||
if (!operator bool())
|
||||
{
|
||||
#if UAVCAN_EXCEPTIONS
|
||||
throw std::runtime_error(typeid(*this).name());
|
||||
@ -37,13 +33,41 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void operator()() { (obj_->*fun_)(); }
|
||||
public:
|
||||
MethodBinder()
|
||||
: obj_()
|
||||
, fun_()
|
||||
{ }
|
||||
|
||||
MethodBinder(ObjectPtr o, MemFunPtr f)
|
||||
: obj_(o)
|
||||
, fun_(f)
|
||||
{ }
|
||||
|
||||
operator bool() const
|
||||
{
|
||||
return try_implicit_cast<bool>(obj_, true) && try_implicit_cast<bool>(fun_, true);
|
||||
}
|
||||
|
||||
void operator()()
|
||||
{
|
||||
validateBeforeCall();
|
||||
(obj_->*fun_)();
|
||||
}
|
||||
|
||||
template <typename Par1>
|
||||
void operator()(Par1 p1) { (obj_->*fun_)(p1); }
|
||||
void operator()(Par1 p1)
|
||||
{
|
||||
validateBeforeCall();
|
||||
(obj_->*fun_)(p1);
|
||||
}
|
||||
|
||||
template <typename Par1, typename Par2>
|
||||
void operator()(Par1 p1, Par2 p2) { (obj_->*fun_)(p1, p2); }
|
||||
void operator()(Par1 p1, Par2 p2)
|
||||
{
|
||||
validateBeforeCall();
|
||||
(obj_->*fun_)(p1, p2);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user