ADC/device/adc_device_command.h
2024-10-31 12:01:02 +03:00

76 lines
1.1 KiB
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))
{
}
AdcDeviceCommand(const AdcDeviceCommand&) = default;
AdcDeviceCommand(AdcDeviceCommand&&) = default;
AdcDeviceCommand& operator=(const AdcDeviceCommand&) = default;
AdcDeviceCommand& operator=(AdcDeviceCommand&&) = default;
virtual ~AdcDeviceCommand() = default;
/* PUBLIC METHODS */
ident_t ident() const
{
return _ident;
}
void operator()()
{
_execFunc();
}
};
} // namespace adc