ADC/device/adc_device_command.h
Timur A. Fatkhullin 534d98994b AdcDeviceCommand is now parameter-less
rewrite AdcDeviceAttribute class, basic tests of AdcDeviceAttribute passed
2024-05-19 20:28:53 +03:00

63 lines
874 B
C++

#pragma once
/*
ABSTRACT DEVICE COMPONENTS LIBRARY
*/
#include <functional>
#include "../common/adc_traits.h"
/*
*/
namespace adc
{
namespace traits
{
template <typename T>
concept adc_cmd_exec_c = traits::adc_func_traits<T>::arity == 0 && !std::same_as<T, std::nullptr_t>;
} // namespace traits
template <typename IdentT = std::string_view>
class AdcDeviceCommand
{
protected:
IdentT _ident;
std::function<void()> _execFunc;
public:
typedef IdentT ident_t;
template <traits::adc_cmd_exec_c ExecFuncT>
AdcDeviceCommand(const IdentT& ident, ExecFuncT&& exec_func)
: _ident(ident), _execFunc(std::forward<ExecFuncT>(exec_func))
{
}
virtual ~AdcDeviceCommand() = default;
/* PUBLIC METHODS */
IdentT ident() const { return ident; }
void operator()() { _execFunc(); }
};
} // namespace adc