ADC/device/adc_device_concepts.h
2024-11-01 17:26:52 +03:00

55 lines
1.4 KiB
C++

#pragma once
#include <concepts>
namespace adc::interfaces
{
// ADC device attribute concept
template <typename T>
concept adc_device_attr_c = std::movable<T> && requires(T t, const T const_t) {
typename T::ident_t;
typename T::serialized_t;
{ const_t.ident() } -> std::same_as<typename T::ident_t>;
// serializer and deserializer must return/accept at least a value of type T::serialized_t
{ t.serialize() } -> std::convertible_to<typename T::serialized_t>;
t.deserialize(std::declval<typename T::serialized_t>());
};
// ADC device command concept
template <typename T>
concept adc_device_cmd_c = std::movable<T> && 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