...
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <ranges>
|
||||
#include <system_error>
|
||||
|
||||
#include "adc_device_concepts.h"
|
||||
|
||||
namespace adc
|
||||
{
|
||||
|
||||
@@ -33,7 +35,10 @@ namespace adc
|
||||
struct AdcGenericDeviceErrorCategory : public std::error_category {
|
||||
AdcGenericDeviceErrorCategory() : std::error_category() {}
|
||||
|
||||
const char* name() const noexcept { return "ADC_GENERIC_DEVICE"; }
|
||||
const char* name() const noexcept
|
||||
{
|
||||
return "ADC_GENERIC_DEVICE";
|
||||
}
|
||||
|
||||
std::string message(int ec) const
|
||||
{
|
||||
@@ -66,32 +71,7 @@ inline std::error_code make_error_code(AdcGenericDeviceErrorCode ec)
|
||||
|
||||
|
||||
|
||||
namespace traits
|
||||
{
|
||||
|
||||
// ADC device attribute concept
|
||||
template <typename T>
|
||||
concept adc_device_attr_c = requires {
|
||||
typename T::ident_t;
|
||||
&T::ident;
|
||||
&T::serialize;
|
||||
&T::deserialize;
|
||||
// std::declval<T>().operator int();
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
concept adc_device_cmd_c = requires {
|
||||
typename T::ident_t;
|
||||
&T::ident;
|
||||
&T::operator();
|
||||
};
|
||||
|
||||
|
||||
} // namespace traits
|
||||
|
||||
|
||||
template <typename IdentT, traits::adc_device_attr_c AttributeT, traits::adc_device_cmd_c CommandT>
|
||||
template <typename IdentT, interfaces::adc_device_attr_c AttributeT, interfaces::adc_device_cmd_c CommandT>
|
||||
class AdcGenericDevice
|
||||
{
|
||||
public:
|
||||
@@ -110,7 +90,10 @@ public:
|
||||
|
||||
/* PUBLIC METHODS */
|
||||
|
||||
IdentT ident() const { return _ident; }
|
||||
IdentT ident() const
|
||||
{
|
||||
return _ident;
|
||||
}
|
||||
|
||||
AdcGenericDevice& operator()(const cmd_ident_t& cmd_ident)
|
||||
{
|
||||
|
||||
54
device/adc_device_concepts.h
Normal file
54
device/adc_device_concepts.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
|
||||
namespace adc::interfaces
|
||||
{
|
||||
|
||||
// ADC device attribute concept
|
||||
template <typename T>
|
||||
concept adc_device_attr_c = requires(T t, const T const_t) {
|
||||
typename T::ident_t;
|
||||
typename T::default_serialized_t;
|
||||
|
||||
{ const_t.ident() } -> std::same_as<typename T::ident_t>;
|
||||
|
||||
// serializer and desiarializer must return/accept at least a value of type T::default_serialized_t
|
||||
{ t.serialize() } -> std::convertible_to<typename T::default_serialized_t>;
|
||||
t.deserialize(std::declval<typename T::default_serialized_t>());
|
||||
};
|
||||
|
||||
|
||||
// ADC device command concept
|
||||
template <typename T>
|
||||
concept adc_device_cmd_c = requires(T t, const T const_t) {
|
||||
typename T::ident_t;
|
||||
|
||||
{ const_t.ident() } -> std::same_as<typename T::ident_t>;
|
||||
t(); // operator()()
|
||||
};
|
||||
|
||||
|
||||
// ADC device concept
|
||||
|
||||
template <typename T>
|
||||
concept adc_device_c = requires(T t, const T const_t) {
|
||||
typename T::ident_t;
|
||||
|
||||
requires adc_device_attr_c<typename T::attribute_t>;
|
||||
requires adc_device_cmd_c<typename T::command_t>;
|
||||
|
||||
typename T::attr_ident_t;
|
||||
typename T::cmd_ident_t;
|
||||
|
||||
{ const_t.ident() } -> std::same_as<typename T::ident_t>;
|
||||
|
||||
t(std::declval<typename T::cmd_ident_t>()); // operator()(cmd_ident_t)
|
||||
|
||||
{
|
||||
t[std::declval<typename T::attr_ident_t>()]
|
||||
} -> std::same_as<typename T::attribute_t&>; // attribute_t& operator[](attr_ident_t)
|
||||
};
|
||||
|
||||
|
||||
} // namespace adc::interfaces
|
||||
Reference in New Issue
Block a user