This commit is contained in:
Timur A. Fatkhullin 2024-05-26 00:31:59 +03:00
parent 366d4e05b0
commit eb64c6e56d
2 changed files with 33 additions and 4 deletions

View File

@ -21,6 +21,10 @@ set(ADC_DEVICE_HEADERS
device/adc_device.h
)
set(ADC_NETWORK_HEADERS
net/adc_netmessage.h)
option(BUILD_TESTS "Build tests" ON)
if (BUILD_TESTS)
@ -52,7 +56,7 @@ endif(BUILD_TESTS)
include(GNUInstallDirs)
add_library(${PROJECT_NAME} INTERFACE ${ADC_COMMON_HEADERS} ${ADC_DEVICE_HEADERS})
add_library(${PROJECT_NAME} INTERFACE ${ADC_COMMON_HEADERS} ${ADC_DEVICE_HEADERS} ${ADC_NETWORK_HEADERS})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_20)
# target_link_libraries(${PROJECT_NAME} INTERFACE ASIO::ASIO)
target_include_directories(

View File

@ -33,6 +33,12 @@ template <typename T, typename BT, typename VT>
concept adc_from_bytes_func_c = std::invocable<T, const BT&> && std::convertible_to<traits::adc_retval_t<T>, VT>;
template <typename T, typename BT, typename VT>
concept adc_netmsg_converter_c = requires(T t) {
{ t.template serialize<BT, VT>(std::declval<const VT&>()) } -> std::same_as<BT>;
{ t.template deserialize<VT, BT>(std::declval<const BT&>()) } -> std::same_as<VT>;
};
struct AdcTheSameTypeTag {
};
@ -63,6 +69,12 @@ protected:
AdcNetMessageInterface& operator=(const AdcNetMessageInterface&) = default;
AdcNetMessageInterface& operator=(AdcNetMessageInterface&&) = default;
virtual void updateState() = 0;
public:
typedef ByteStorageT byte_storage_t;
typedef StorageSeqT storage_seq_t;
template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
void appendBytes(const T& v, const Ts&... vs)
{
@ -81,6 +93,8 @@ protected:
{
_byteStorage = ByteStorageT();
appendBytes(v, vs...);
updateState();
}
@ -88,17 +102,19 @@ protected:
void setBytes(IterT begin, IterT end)
{
_byteStorage = ByteStorageT(begin, end);
updateState();
}
template <std::input_iterator IterT>
void appendBytes(IterT begin, IterT end)
{
std::copy(begin, end, std::back_inserter(_byteStorage));
updateState();
}
public:
typedef ByteStorageT byte_storage_t;
typedef StorageSeqT storage_seq_t;
virtual size_t byteSize()
{
@ -135,6 +151,9 @@ public:
using typename base_t::byte_storage_t;
using typename base_t::storage_seq_t;
using base_t::appendBytes;
using base_t::setBytes;
using message_view_t =
std::conditional_t<std::is_same_v<MessageViewT, traits::AdcTheSameTypeTag>, ByteStorageT, MessageViewT>;
@ -223,6 +242,12 @@ public:
protected:
MessageViewT _messageView;
void updateState() override
{
if constexpr (!std::is_same_v<MessageViewT, traits::AdcTheSameTypeTag>) {
}
}
};