16#include "comms/details/tag.h"
28 template <
typename TFieldTo,
typename TFieldFrom>
29 static TFieldTo cast(
const TFieldFrom& field)
31 return castInternal<TFieldTo>(field, Tag<TFieldFrom, TFieldTo>());
36 template <
typename... TParams>
37 using StaticCastTag = comms::details::tag::Tag1<>;
39 template <
typename... TParams>
40 using WriteReadTag = comms::details::tag::Tag2<>;
42 template <
typename TFieldFrom,
typename TFieldTo>
44 std::is_convertible<typename TFieldFrom::ValueType, typename TFieldTo::ValueType>;
46 template <
typename TField>
48 std::integral_constant<
50 std::is_enum<typename TField::ValueType>::value ||
51 std::is_integral<typename TField::ValueType>::value
54 template <
typename TFieldFrom,
typename TFieldTo>
56 std::integral_constant<
58 Convertible<TFieldFrom, TFieldTo>::value ||
59 (IsIntegral<TFieldFrom>::value && IsIntegral<TFieldTo>::value)
62 template <
typename TFieldFrom,
typename TFieldTo>
64 typename comms::util::LazyShallowConditional<
65 UseStaticCast<TFieldFrom, TFieldTo>::value
71 template <
typename TFieldTo,
typename TFieldFrom,
typename... TParams>
72 static TFieldTo castInternal(
const TFieldFrom& field, StaticCastTag<TParams...>)
75 result.value() =
static_cast<typename TFieldTo::ValueType
>(field.value());
79 template <
typename TFieldTo,
typename TFieldFrom,
typename... TParams>
80 static TFieldTo castInternal(
const TFieldFrom& field, WriteReadTag<TParams...>)
82 static_assert(TFieldFrom::minLength() <= TFieldTo::maxLength(),
"Casting between specified fields will fail .");
84 static const auto MaxBufSize = TFieldFrom::maxLength();
85 std::uint8_t buf[MaxBufSize] = {0};
86 auto* writeIter = &buf[0];
87 auto es = field.write(writeIter, MaxBufSize);
93 auto len =
static_cast<std::size_t
>(std::distance(&buf[0], writeIter));
97 const auto* readIter = &buf[0];
98 es = result.read(readIter, len);
99 static_cast<void>(es);
#define COMMS_ASSERT(expr)
Generic assert macro.
Definition Assert.h:170
This file contain definition of error statuses used by comms module.
Main namespace for all classes / functions of COMMS library.
@ Success
Used to indicate successful outcome of the operation.
Replacement to some types from standard type_traits.