...
This commit is contained in:
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