/* * Copyright (C) 2014 Pavel Kirienko */ #pragma once #include #include #include namespace uavcan { template class UAVCAN_EXPORT MethodBinder { ObjectPtr obj_; MemFunPtr fun_; void validateBeforeCall() const { if (!operator bool()) { handleFatalError("Null binder"); } } public: MethodBinder() : obj_() , fun_() { } MethodBinder(ObjectPtr o, MemFunPtr f) : obj_(o) , fun_(f) { } operator bool() const { return try_implicit_cast(obj_, true) && try_implicit_cast(fun_, true); } void operator()() { validateBeforeCall(); (obj_->*fun_)(); } template void operator()(Par1& p1) { validateBeforeCall(); (obj_->*fun_)(p1); } template void operator()(Par1& p1, Par2& p2) { validateBeforeCall(); (obj_->*fun_)(p1, p2); } }; }