....
This commit is contained in:
parent
0d07fb77a6
commit
0f42246ec2
@ -35,8 +35,12 @@ concept adc_from_bytes_func_c = std::invocable<T, const BT&> && std::convertible
|
|||||||
|
|
||||||
template <typename T, typename BT, typename VT>
|
template <typename T, typename BT, typename VT>
|
||||||
concept adc_netmsg_converter_c = requires(T t) {
|
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>;
|
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 {
|
struct AdcTheSameTypeTag {
|
||||||
@ -45,6 +49,31 @@ struct AdcTheSameTypeTag {
|
|||||||
} // namespace traits
|
} // namespace traits
|
||||||
|
|
||||||
|
|
||||||
|
namespace utils
|
||||||
|
{
|
||||||
|
|
||||||
|
template <traits::adc_output_char_range T,
|
||||||
|
std::ranges::output_range<T> OutR,
|
||||||
|
traits::adc_input_char_range InR,
|
||||||
|
traits::adc_input_char_range DelimT = std::string_view>
|
||||||
|
size_t adcSplitRangeToTokens(OutR& result, const InR& input, const DelimT& delim = std::string_view(" "))
|
||||||
|
{
|
||||||
|
decltype(std::ranges::split_view(input, delim)) vv;
|
||||||
|
|
||||||
|
if constexpr (std::is_array_v<DelimT>) {
|
||||||
|
vv = input | std::views::split(std::string_view(delim));
|
||||||
|
} else {
|
||||||
|
vv = input | std::views::split(delim);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ranges::copy(vv, std::back_inserter(result));
|
||||||
|
|
||||||
|
return std::ranges::distance(vv.begin(), vv.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
|
||||||
|
|
||||||
template <std::ranges::output_range<char> ByteStorageT,
|
template <std::ranges::output_range<char> ByteStorageT,
|
||||||
std::ranges::output_range<std::reference_wrapper<const ByteStorageT>> StorageSeqT>
|
std::ranges::output_range<std::reference_wrapper<const ByteStorageT>> StorageSeqT>
|
||||||
class AdcNetMessageInterface
|
class AdcNetMessageInterface
|
||||||
@ -53,7 +82,7 @@ protected:
|
|||||||
ByteStorageT _byteStorage;
|
ByteStorageT _byteStorage;
|
||||||
StorageSeqT _storageSequence;
|
StorageSeqT _storageSequence;
|
||||||
|
|
||||||
AdcNetMessageInterface() : _byteStorage(), _storageSequence({_byteStorage}) {};
|
AdcNetMessageInterface() : _byteStorage(), _storageSequence({_byteStorage}){};
|
||||||
|
|
||||||
template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
||||||
AdcNetMessageInterface(const T& v, const Ts&... vs) : AdcNetMessageInterface()
|
AdcNetMessageInterface(const T& v, const Ts&... vs) : AdcNetMessageInterface()
|
||||||
@ -85,30 +114,61 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
template <typename T, typename... Ts>
|
||||||
void appendBytes(const T& v, const Ts&... vs)
|
void appendBytes(const T& v, const Ts&... vs)
|
||||||
{
|
{
|
||||||
if constexpr (std::is_array_v<std::remove_cvref_t<T>>) {
|
if constexpr (std::is_array_v<std::remove_cvref_t<T>>) {
|
||||||
appendBytes(std::string_view(v), vs...);
|
appendBytes(std::string_view(v), vs...);
|
||||||
} else {
|
} else {
|
||||||
std::ranges::copy(v, std::back_inserter(_byteStorage));
|
if constexpr (traits::adc_input_char_range<T>) {
|
||||||
|
std::ranges::copy(v, std::back_inserter(_byteStorage));
|
||||||
|
} else if constexpr (traits::formattable<T>) {
|
||||||
|
std::format_to(std::back_inserter(_byteStorage), v);
|
||||||
|
} else {
|
||||||
|
static_assert(false, "UNSUPPORTED TYPE!!!");
|
||||||
|
}
|
||||||
|
updateState();
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (sizeof...(Ts)) {
|
if constexpr (sizeof...(Ts)) {
|
||||||
appendBytes(vs...);
|
appendBytes(vs...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <traits::formattable T, traits::formattable... Ts>
|
template <typename T, typename... Ts>
|
||||||
void appendBytes(const T& v, const Ts&... vs)
|
void setBytes(const T& v, const Ts&... vs)
|
||||||
{
|
{
|
||||||
std::format_to(std::back_inserter(_byteStorage), v);
|
_byteStorage = ByteStorageT();
|
||||||
|
appendBytes(v, vs...);
|
||||||
if constexpr (sizeof...(Ts)) {
|
|
||||||
appendBytes(vs...);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
||||||
|
// void appendBytes(const T& v, const Ts&... vs)
|
||||||
|
// {
|
||||||
|
// if constexpr (std::is_array_v<std::remove_cvref_t<T>>) {
|
||||||
|
// appendBytes(std::string_view(v), vs...);
|
||||||
|
// } else {
|
||||||
|
// std::ranges::copy(v, std::back_inserter(_byteStorage));
|
||||||
|
// }
|
||||||
|
// if constexpr (sizeof...(Ts)) {
|
||||||
|
// appendBytes(vs...);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// template <traits::formattable T, traits::formattable... Ts>
|
||||||
|
// void appendBytes(const T& v, const Ts&... vs)
|
||||||
|
// {
|
||||||
|
// std::format_to(std::back_inserter(_byteStorage), v);
|
||||||
|
|
||||||
|
// if constexpr (sizeof...(Ts)) {
|
||||||
|
// appendBytes(vs...);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
template <std::input_iterator IterT>
|
template <std::input_iterator IterT>
|
||||||
void appendBytes(IterT begin, IterT end)
|
void appendBytes(IterT begin, IterT end)
|
||||||
{
|
{
|
||||||
@ -118,24 +178,24 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
// template <traits::adc_input_char_range T, traits::adc_input_char_range... Ts>
|
||||||
void setBytes(const T& v, const Ts&... vs)
|
// void setBytes(const T& v, const Ts&... vs)
|
||||||
{
|
// {
|
||||||
_byteStorage = ByteStorageT();
|
// _byteStorage = ByteStorageT();
|
||||||
appendBytes(v, vs...);
|
// appendBytes(v, vs...);
|
||||||
|
|
||||||
updateState();
|
// updateState();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
template <traits::formattable T, traits::formattable... Ts>
|
// template <traits::formattable T, traits::formattable... Ts>
|
||||||
void setBytes(const T& v, const Ts&... vs)
|
// void setBytes(const T& v, const Ts&... vs)
|
||||||
{
|
// {
|
||||||
_byteStorage = ByteStorageT();
|
// _byteStorage = ByteStorageT();
|
||||||
appendBytes(v, vs...);
|
// appendBytes(v, vs...);
|
||||||
|
|
||||||
updateState();
|
// updateState();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
template <std::input_iterator IterT>
|
template <std::input_iterator IterT>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user