mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 01:43:33 +08:00
Utils moved to uavcan/util/*
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <uavcan/internal/fatal_error.hpp>
|
||||
#include <uavcan/internal/impl_constants.hpp>
|
||||
#include <uavcan/util/compile_time.hpp>
|
||||
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
template <typename ObjectPtr, typename MemFunPtr>
|
||||
class MethodBinder
|
||||
{
|
||||
ObjectPtr obj_;
|
||||
MemFunPtr fun_;
|
||||
|
||||
void validateBeforeCall() const
|
||||
{
|
||||
if (!operator bool())
|
||||
handleFatalError("Null method binder");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
validateBeforeCall();
|
||||
(obj_->*fun_)(p1);
|
||||
}
|
||||
|
||||
template <typename Par1, typename Par2>
|
||||
void operator()(Par1 p1, Par2 p2)
|
||||
{
|
||||
validateBeforeCall();
|
||||
(obj_->*fun_)(p1, p2);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user