mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-28 22:33:35 +08:00
Improved MethodBinder
This commit is contained in:
@@ -20,13 +20,9 @@ class MethodBinder
|
|||||||
ObjectPtr obj_;
|
ObjectPtr obj_;
|
||||||
MemFunPtr fun_;
|
MemFunPtr fun_;
|
||||||
|
|
||||||
public:
|
void validateBeforeCall() const
|
||||||
MethodBinder(ObjectPtr o, MemFunPtr f)
|
|
||||||
: obj_(o)
|
|
||||||
, fun_(f)
|
|
||||||
{
|
{
|
||||||
if (!try_implicit_cast<bool>(o, true) ||
|
if (!operator bool())
|
||||||
!try_implicit_cast<bool>(f, true))
|
|
||||||
{
|
{
|
||||||
#if UAVCAN_EXCEPTIONS
|
#if UAVCAN_EXCEPTIONS
|
||||||
throw std::runtime_error(typeid(*this).name());
|
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>
|
template <typename Par1>
|
||||||
void operator()(Par1 p1) { (obj_->*fun_)(p1); }
|
void operator()(Par1 p1)
|
||||||
|
{
|
||||||
|
validateBeforeCall();
|
||||||
|
(obj_->*fun_)(p1);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Par1, typename Par2>
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user