1 #ifndef ZSERIO_ARRAY_TRAIT_H_INC
2 #define ZSERIO_ARRAY_TRAIT_H_INC
25 template <
typename T,
typename =
void>
31 struct DummyArrayOwner
34 template <
typename ARRAY_TRAITS,
typename =
void>
35 struct array_owner_type
37 using type = DummyArrayOwner;
40 template <
typename ARRAY_TRAITS>
41 struct array_owner_type<ARRAY_TRAITS,
std::void_t<typename ARRAY_TRAITS::OwnerType>>
43 using type =
typename ARRAY_TRAITS::OwnerType;
46 template <
typename T,
typename V =
void>
47 using array_owner_type_t =
typename array_owner_type<T, V>::type;
50 struct is_dummy_array_owner : std::is_same<DummyArrayOwner, T>
54 inline constexpr
bool is_dummy_array_owner_v = is_dummy_array_owner<T>::value;
56 template <
typename T,
typename =
void>
57 struct is_packable : std::false_type
61 struct is_packable<T,
std::enable_if_t<is_numeric_wrapper_v<T> || is_bitmask_v<T> || std::is_enum_v<T>>>
66 struct is_packable<T,
std::enable_if_t<is_complete_v<typename ObjectTraits<std::decay_t<T>>::PackingContext>>>
70 template <
typename T,
typename V =
void>
71 inline constexpr
bool is_packable_v = is_packable<T, V>::value;
74 struct is_delta_context : std::is_same<DeltaContext, T>
78 inline constexpr
bool is_delta_context_v = is_delta_context<T>::value;
81 struct NumericArrayTraits
83 static const T& at(
const detail::DummyArrayOwner&,
const T& element,
size_t)
88 static T& at(
const detail::DummyArrayOwner&, T& element,
size_t)
93 static void read(BitStreamReader& reader,
const detail::DummyArrayOwner&, T& element,
size_t)
95 detail::read(reader, element);
100 return detail::bitSizeOf(T{});
104 template <
typename T>
105 struct IntegralArrayTraits : NumericArrayTraits<T>
107 using NumericArrayTraits<T>::read;
110 DeltaContext& context, BitStreamReader& reader,
const detail::DummyArrayOwner&, T& element,
size_t)
112 detail::read(context, reader, element);
119 template <
typename OBJECT,
typename>
122 template <
typename OBJECT_ = OBJECT,
123 std::enable_if_t<std::is_constructible_v<View<OBJECT_>,
const OBJECT&>,
int> = 0>
124 static View<OBJECT> at(
const detail::DummyArrayOwner&,
const OBJECT& element,
size_t)
129 template <
typename OBJECT_ = OBJECT,
130 std::enable_if_t<std::is_constructible_v<View<OBJECT_>, OBJECT&>,
int> = 0>
138 (void)detail::read(reader, element);
141 template <
typename OBJECT_ = OBJECT>
142 static std::enable_if_t<!detail::is_delta_context_v<detail::packing_context_type_t<OBJECT_>>>
read(
143 typename detail::ObjectTraits<OBJECT_>::PackingContext& packingContext,
BitStreamReader& reader,
144 const detail::DummyArrayOwner&, OBJECT& element,
size_t)
146 detail::read(packingContext, reader, element);
151 struct ArrayTraits<detail::BoolWrapper> : detail::IntegralArrayTraits<detail::BoolWrapper>
154 template <BitSize BIT_SIZE,
bool IS_SIGNED>
155 struct ArrayTraits<detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED>>
156 : detail::IntegralArrayTraits<detail::FixedIntWrapper<BIT_SIZE, IS_SIGNED>>
159 template <
typename VALUE_TYPE,
typename detail::VarIntType VAR_TYPE>
160 struct ArrayTraits<detail::VarIntWrapper<VALUE_TYPE, VAR_TYPE>>
161 : detail::IntegralArrayTraits<detail::VarIntWrapper<VALUE_TYPE, VAR_TYPE>>
164 template <
typename VALUE_TYPE, detail::FloatType FLOAT_TYPE>
165 struct ArrayTraits<detail::FloatWrapper<VALUE_TYPE, FLOAT_TYPE>>
166 : detail::NumericArrayTraits<detail::FloatWrapper<VALUE_TYPE, FLOAT_TYPE>>
169 template <
typename ALLOC>
180 detail::read(reader, element);
184 template <
typename ALLOC>
196 detail::read(reader, element);
200 template <
typename ALLOC>
203 static constexpr std::string_view
at(
const detail::DummyArrayOwner&, std::string_view element,
size_t)
211 detail::read(reader, element);
215 template <
typename T>
218 static T
at(
const detail::DummyArrayOwner&, T element,
size_t)
225 detail::read(reader, element);
231 detail::read(context, reader, element);
235 template <
typename T>
238 static T
at(
const detail::DummyArrayOwner&, T element,
size_t)
245 detail::read(reader, element);
251 detail::read(context, reader, element);
std::basic_string< char, std::char_traits< char >, ALLOC > BasicString
std::vector< uint8_t, ALLOC > BasicBytes
std::reference_wrapper< const BasicBitBuffer< ALLOC > > BasicBitBufferView
static constexpr BasicBitBufferView< ALLOC > at(const detail::DummyArrayOwner &, const BasicBitBuffer< ALLOC > &element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, BasicBitBuffer< ALLOC > &element, size_t)
static constexpr BytesView at(const detail::DummyArrayOwner &, const BasicBytes< ALLOC > &element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, BasicBytes< ALLOC > &element, size_t)
static constexpr std::string_view at(const detail::DummyArrayOwner &, std::string_view element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, BasicString< ALLOC > &element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, T &element, size_t)
static void read(detail::DeltaContext &context, BitStreamReader &reader, const detail::DummyArrayOwner &, T &element, size_t)
static T at(const detail::DummyArrayOwner &, T element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, T &element, size_t)
static void read(detail::DeltaContext &context, BitStreamReader &reader, const detail::DummyArrayOwner &, T &element, size_t)
static T at(const detail::DummyArrayOwner &, T element, size_t)
static View< OBJECT > at(const detail::DummyArrayOwner &, const OBJECT &element, size_t)
static std::enable_if_t<!detail::is_delta_context_v< detail::packing_context_type_t< OBJECT_ > > > read(typename detail::ObjectTraits< OBJECT_ >::PackingContext &packingContext, BitStreamReader &reader, const detail::DummyArrayOwner &, OBJECT &element, size_t)
static void read(BitStreamReader &reader, const detail::DummyArrayOwner &, OBJECT &element, size_t)
static View< OBJECT > at(const detail::DummyArrayOwner &, OBJECT &element, size_t)