1 #ifndef ZSERIO_VIEW_H_INC
2 #define ZSERIO_VIEW_H_INC
29 template <
typename T,
typename... ARGS>
42 template <
size_t I,
typename T,
typename U>
45 using ParamType = std::tuple_element_t<I, typename ObjectTraits<T>::Parameters>;
46 if constexpr (is_dyn_int_wrapper_v<ParamType>)
48 return View<ParamType>(ParamType(
static_cast<typename ParamType::ValueType
>(arg)), 64);
50 else if constexpr (is_numeric_wrapper_v<ParamType>)
52 return ParamType(
static_cast<typename ParamType::ValueType
>(arg));
68 void validate(
const View<T>& view, std::string_view fieldName =
"")
70 ObjectTraits<T>::validate(view, fieldName);
84 return ObjectTraits<T>::bitSizeOf(view, bitPosition);
87 template <
typename T,
typename =
void>
88 struct has_initialize_offsets : std::false_type
92 struct has_initialize_offsets<T,
93 std::void_t<decltype(ObjectTraits<T>().initializeOffsets(std::declval<const View<T>&>(), 0))>>
97 template <
typename T,
typename V =
void>
98 inline constexpr
bool has_initialize_offsets_v = has_initialize_offsets<T, V>::value;
100 template <
typename T>
103 if constexpr (has_initialize_offsets_v<T>)
105 return ObjectTraits<T>::initializeOffsets(view, bitPosition);
109 return ObjectTraits<T>::bitSizeOf(view, bitPosition);
121 template <
typename T>
124 ObjectTraits<T>::write(writer, view);
138 template <
typename T,
typename... ARGS>
141 return ObjectTraits<T>::read(reader, data, std::forward<ARGS>(args)...);
146 template <
typename VALUE_TYPE>
147 class View<detail::DynIntWrapper<VALUE_TYPE>>
150 using ValueType = VALUE_TYPE;
152 View(detail::DynIntWrapper<VALUE_TYPE> value, uint8_t
numBits) :
162 detail::DynIntWrapper<VALUE_TYPE> value()
const
167 operator VALUE_TYPE()
const
173 detail::DynIntWrapper<VALUE_TYPE> m_value;
177 template <
typename VALUE_TYPE>
179 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
181 return lhs.numBits() == rhs.numBits() && lhs.value() == rhs.value();
184 template <
typename VALUE_TYPE>
186 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
188 return !(lhs == rhs);
191 template <
typename VALUE_TYPE>
193 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
195 if (lhs.numBits() != rhs.numBits())
197 return lhs.numBits() < rhs.numBits();
199 if (lhs.value() != rhs.value())
201 return lhs.value() < rhs.value();
207 template <
typename VALUE_TYPE>
209 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
214 template <
typename VALUE_TYPE>
216 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
221 template <
typename VALUE_TYPE>
223 const View<detail::DynIntWrapper<VALUE_TYPE>>& lhs,
const View<detail::DynIntWrapper<VALUE_TYPE>>& rhs)
231 template <
typename VALUE_TYPE>
232 void validate(
const View<detail::DynIntWrapper<VALUE_TYPE>>& view, std::string_view fieldName)
234 return validate(view.value(), view.numBits(), fieldName);
237 template <
typename VALUE_TYPE>
240 return view.numBits();
243 template <
typename VALUE_TYPE>
244 void write(BitStreamWriter& writer,
const View<detail::DynIntWrapper<VALUE_TYPE>>& view)
246 write(writer, view.value(), view.numBits());
256 template <
typename VALUE_TYPE>
257 struct hash<
zserio::
View<zserio::detail::DynIntWrapper<VALUE_TYPE>>>
259 size_t operator()(
const zserio::View<zserio::detail::DynIntWrapper<VALUE_TYPE>>& view)
const
261 uint32_t result = zserio::HASH_SEED;
uint8_t numBits(uint64_t numValues)
bool operator>(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator==(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator<(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
uint32_t calcHashCode(uint32_t seedValue, const ArrayView< T, ARRAY_TRAITS > &array)
View(T, ARGS &&...) -> View< T >
bool operator<=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator>=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
bool operator!=(const BasicBitBufferView< ALLOC > &lhs, const BasicBitBufferView< ALLOC > &rhs)
typename view_type< T, V >::type view_type_t