1 #ifndef ZSERIO_ARRAY_H_INC
2 #define ZSERIO_ARRAY_H_INC
25 struct DummyArrayExpressions
29 struct DummyArrayOwner
33 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS,
typename =
void>
34 struct array_owner_type
36 using type = DummyArrayOwner;
39 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS>
40 struct array_owner_type<ARRAY_TRAITS, ARRAY_EXPRESSIONS,
41 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value>::type>
43 using type =
typename ARRAY_TRAITS::OwnerType;
46 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS>
47 struct array_owner_type<ARRAY_TRAITS, ARRAY_EXPRESSIONS,
48 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
49 has_owner_type<ARRAY_EXPRESSIONS>::value>::type>
51 using type =
typename ARRAY_EXPRESSIONS::OwnerType;
55 template <
typename T,
typename =
void>
56 struct packing_context_type
58 using type = DeltaContext;
62 struct packing_context_type<T, typename std::enable_if<has_zserio_packing_context<T>::value>::type>
64 using type =
typename T::ZserioPackingContext;
68 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
69 typename std::enable_if<has_initialize_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
70 void initializeOffset(OWNER_TYPE& owner,
size_t index,
size_t bitPosition)
72 ARRAY_EXPRESSIONS::initializeOffset(owner, index, bitPosition);
75 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
76 typename std::enable_if<!has_initialize_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
77 void initializeOffset(OWNER_TYPE&,
size_t,
size_t)
81 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
82 typename std::enable_if<has_check_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
83 void checkOffset(
const OWNER_TYPE& owner,
size_t index,
size_t bitPosition)
85 ARRAY_EXPRESSIONS::checkOffset(owner, index, bitPosition);
88 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
89 typename std::enable_if<!has_check_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
90 void checkOffset(
const OWNER_TYPE&,
size_t,
size_t)
94 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
95 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
96 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
98 void packedArrayTraitsInitContext(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
99 const typename PACKED_ARRAY_TRAITS::ElementType& element)
101 PACKED_ARRAY_TRAITS::initContext(owner, context, element);
104 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
105 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
106 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
108 void packedArrayTraitsInitContext(
109 const OWNER_TYPE& owner, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
111 PACKED_ARRAY_TRAITS::initContext(owner, context, element);
114 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
115 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
116 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
118 void packedArrayTraitsInitContext(
119 const OWNER_TYPE&, PACKING_CONTEXT& context,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
121 PACKED_ARRAY_TRAITS::initContext(context, element);
124 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
125 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
126 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
128 void packedArrayTraitsInitContext(
129 const OWNER_TYPE&, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
131 PACKED_ARRAY_TRAITS::initContext(context, element);
135 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
136 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && has_owner_type<ARRAY_TRAITS>::value,
138 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE& owner)
143 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
144 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && !has_owner_type<ARRAY_TRAITS>::value,
146 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE&)
152 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
153 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
154 size_t arrayTraitsBitSizeOf(
155 const OWNER_TYPE& owner,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
160 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
161 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
162 size_t arrayTraitsBitSizeOf(
163 const OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
169 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
170 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
171 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
172 const typename PACKED_ARRAY_TRAITS::ElementType& element)
177 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
178 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
179 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
180 const typename PACKED_ARRAY_TRAITS::ElementType& element)
186 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
187 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
188 size_t arrayTraitsInitializeOffsets(
189 OWNER_TYPE& owner,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType& element)
194 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
195 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
196 !std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
198 size_t arrayTraitsInitializeOffsets(
199 OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
204 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
205 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
206 std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
208 size_t arrayTraitsInitializeOffsets(OWNER_TYPE&,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType element)
214 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
215 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
216 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
217 typename PACKED_ARRAY_TRAITS::ElementType& element)
222 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
223 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
224 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
226 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
227 const typename PACKED_ARRAY_TRAITS::ElementType& element)
232 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
233 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
234 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
236 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
237 typename PACKED_ARRAY_TRAITS::ElementType element)
243 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
244 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value && !has_allocator<ARRAY_TRAITS>::value,
246 void arrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
251 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
252 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
254 void arrayTraitsRead(OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
259 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
260 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && !has_allocator<ARRAY_TRAITS>::value,
262 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
267 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
268 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
270 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
276 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
277 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
278 has_allocator<PACKED_ARRAY_TRAITS>::value,
280 void packedArrayTraitsRead(
281 OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
286 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
287 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
288 !has_allocator<PACKED_ARRAY_TRAITS>::value,
290 void packedArrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
291 BitStreamReader& in,
size_t index)
299 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
300 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
301 !has_allocator<PACKED_ARRAY_TRAITS>::value,
303 void packedArrayTraitsRead(
304 const OWNER_TYPE&, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
310 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
311 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
312 void arrayTraitsWrite(
313 const OWNER_TYPE& owner, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
318 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
319 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
320 void arrayTraitsWrite(
321 const OWNER_TYPE&, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
327 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
328 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
329 void packedArrayTraitsWrite(
const OWNER_TYPE& owner, PACKING_CONTEXT& context, BitStreamWriter& out,
330 const typename PACKED_ARRAY_TRAITS::ElementType& element)
335 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
336 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
337 void packedArrayTraitsWrite(
const OWNER_TYPE&, PACKING_CONTEXT& context, BitStreamWriter& out,
338 const typename PACKED_ARRAY_TRAITS::ElementType& element)
364 template <
typename RAW_ARRAY,
typename ARRAY_TRAITS,
ArrayType ARRAY_TYPE,
365 typename ARRAY_EXPRESSIONS = detail::DummyArrayExpressions>
384 using OwnerType =
typename detail::array_owner_type<ArrayTraits, ArrayExpressions>::type;
395 m_rawArray(allocator)
413 m_rawArray(std::move(rawArray))
437 template <
typename T =
typename RAW_ARRAY::value_type,
438 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
441 other.m_rawArray.get_allocator()))
443 m_rawArray.reserve(other.m_rawArray.size());
444 for (
const auto& value : other.m_rawArray)
446 m_rawArray.emplace_back(
NoInit, value);
457 template <
typename T =
typename RAW_ARRAY::value_type,
458 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
461 const RawArray rawArray(other.m_rawArray.get_allocator());
462 m_rawArray = rawArray;
463 m_rawArray.reserve(other.m_rawArray.size());
464 for (
const auto& value : other.m_rawArray)
466 m_rawArray.emplace_back(
NoInit, value);
479 template <
typename T =
typename RAW_ARRAY::value_type,
480 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
482 Array(std::move(other))
493 template <
typename T =
typename RAW_ARRAY::value_type,
494 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
517 template <
typename T =
typename RAW_ARRAY::value_type,
518 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
532 return m_rawArray == other.m_rawArray;
544 return m_rawArray < other.m_rawArray;
583 typename std::enable_if<has_initialize_element<ARRAY_EXPRESSIONS_>::value,
int>::type = 0>
587 for (
auto&& element : m_rawArray)
589 ArrayExpressions::initializeElement(owner, element, index);
603 template <
typename OWNER_TYPE_ =
OwnerType,
604 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
607 return bitSizeOfImpl(detail::DummyArrayOwner(), bitPosition);
620 template <
typename OWNER_TYPE_ =
OwnerType,
621 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
624 return bitSizeOfImpl(owner, bitPosition);
636 template <
typename OWNER_TYPE_ =
OwnerType,
637 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
640 detail::DummyArrayOwner owner;
641 return initializeOffsetsImpl(owner, bitPosition);
654 template <
typename OWNER_TYPE_ =
OwnerType,
655 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
658 return initializeOffsetsImpl(owner, bitPosition);
669 template <
typename OWNER_TYPE_ =
OwnerType,
670 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
673 detail::DummyArrayOwner owner;
674 readImpl(owner, in, arrayLength);
686 template <
typename OWNER_TYPE_ =
OwnerType,
687 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
690 readImpl(owner, in, arrayLength);
700 template <
typename OWNER_TYPE_ =
OwnerType,
701 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
704 writeImpl(detail::DummyArrayOwner(), out);
715 template <
typename OWNER_TYPE_ =
OwnerType,
716 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
719 writeImpl(owner, out);
731 template <
typename OWNER_TYPE_ =
OwnerType,
732 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
735 return bitSizeOfPackedImpl(detail::DummyArrayOwner(), bitPosition);
748 template <
typename OWNER_TYPE_ =
OwnerType,
749 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
752 return bitSizeOfPackedImpl(ownerType, bitPosition);
764 template <
typename OWNER_TYPE_ =
OwnerType,
765 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
768 detail::DummyArrayOwner owner;
769 return initializeOffsetsPackedImpl(owner, bitPosition);
782 template <
typename OWNER_TYPE_ =
OwnerType,
783 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
786 return initializeOffsetsPackedImpl(owner, bitPosition);
797 template <
typename OWNER_TYPE_ =
OwnerType,
798 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
801 detail::DummyArrayOwner owner;
802 readPackedImpl(owner, in, arrayLength);
814 template <
typename OWNER_TYPE_ =
OwnerType,
815 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
818 readPackedImpl(owner, in, arrayLength);
828 template <
typename OWNER_TYPE_ =
OwnerType,
829 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
832 writePackedImpl(detail::DummyArrayOwner(), out);
843 template <
typename OWNER_TYPE_ =
OwnerType,
844 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
847 writePackedImpl(owner, out);
851 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
854 static void addBitSizeOfArrayLength(
size_t&,
size_t)
857 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
860 static void addBitSizeOfArrayLength(
size_t& bitPosition,
size_t arrayLength)
865 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
868 static void alignBitPosition(
size_t&)
871 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
874 static void alignBitPosition(
size_t& bitPosition)
876 bitPosition =
alignTo(8, bitPosition);
879 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
882 static void alignAndCheckOffset(IO&, OWNER_TYPE&,
size_t)
885 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
888 static void alignAndCheckOffset(IO& io, OWNER_TYPE& owner,
size_t index)
891 detail::checkOffset<ArrayExpressions>(owner, index, io.getBitPosition() / 8);
894 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
897 static void initializeOffset(
OwnerType&,
size_t,
size_t&)
900 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
903 static void initializeOffset(
OwnerType& owner,
size_t index,
size_t& bitPosition)
905 bitPosition =
alignTo(8, bitPosition);
906 detail::initializeOffset<ArrayExpressions>(owner, index, bitPosition / 8);
909 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
913 static size_t readArrayLength(
OwnerType&, BitStreamReader&,
size_t arrayLength)
918 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
921 static size_t readArrayLength(
OwnerType&, BitStreamReader& in,
size_t)
923 return in.readVarSize();
926 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
927 typename std::enable_if<ARRAY_TYPE_ == ArrayType::IMPLICIT, int>::type = 0>
928 static size_t readArrayLength(
OwnerType& owner, BitStreamReader& in,
size_t)
931 "Implicit array elements must have constant bit size!");
933 const size_t remainingBits = in.getBufferBitSize() - in.getBitPosition();
934 return remainingBits / detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
937 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
940 static void writeArrayLength(BitStreamWriter&,
size_t)
943 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
946 static void writeArrayLength(BitStreamWriter& out,
size_t arrayLength)
951 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
954 static size_t constBitSizeOfElements(
size_t,
size_t arrayLength,
size_t elementBitSize)
956 return arrayLength * elementBitSize;
959 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
962 static size_t constBitSizeOfElements(
size_t bitPosition,
size_t arrayLength,
size_t elementBitSize)
964 size_t endBitPosition =
alignTo(8, bitPosition);
965 endBitPosition += elementBitSize + (arrayLength - 1) *
alignTo(8, elementBitSize);
967 return endBitPosition - bitPosition;
971 typename std::enable_if<ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
972 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
974 size_t endBitPosition = bitPosition;
976 const size_t arrayLength = m_rawArray.size();
977 addBitSizeOfArrayLength(endBitPosition, arrayLength);
981 const size_t elementBitSize = detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
982 endBitPosition += constBitSizeOfElements(endBitPosition, arrayLength, elementBitSize);
985 return endBitPosition - bitPosition;
989 typename std::enable_if<!ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
990 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
992 size_t endBitPosition = bitPosition;
994 const size_t arrayLength = m_rawArray.size();
995 addBitSizeOfArrayLength(endBitPosition, arrayLength);
997 for (
size_t index = 0; index < arrayLength; ++index)
999 alignBitPosition(endBitPosition);
1001 detail::arrayTraitsBitSizeOf<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
1004 return endBitPosition - bitPosition;
1007 size_t initializeOffsetsImpl(
OwnerType& owner,
size_t bitPosition)
1009 size_t endBitPosition = bitPosition;
1011 const size_t arrayLength = m_rawArray.size();
1012 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1014 for (
size_t index = 0; index < arrayLength; ++index)
1016 initializeOffset(owner, index, endBitPosition);
1018 detail::arrayTraitsInitializeOffsets<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
1021 return endBitPosition;
1024 void readImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength)
1026 size_t readLength = readArrayLength(owner, in, arrayLength);
1029 m_rawArray.reserve(readLength);
1030 for (
size_t index = 0; index < readLength; ++index)
1032 alignAndCheckOffset(in, owner, index);
1033 detail::arrayTraitsRead<ArrayTraits>(owner, m_rawArray, in, index);
1037 void writeImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1039 const size_t arrayLength = m_rawArray.size();
1040 writeArrayLength(out, arrayLength);
1042 for (
size_t index = 0; index < arrayLength; ++index)
1044 alignAndCheckOffset(out, owner, index);
1045 detail::arrayTraitsWrite<ArrayTraits>(owner, out, m_rawArray[index]);
1049 using PackingContext =
typename detail::packing_context_type<typename RawArray::value_type>::type;
1051 size_t bitSizeOfPackedImpl(
const OwnerType& owner,
size_t bitPosition)
const
1055 size_t endBitPosition = bitPosition;
1057 const size_t arrayLength = m_rawArray.size();
1058 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1060 if (arrayLength > 0)
1062 PackingContext context;
1064 for (
size_t index = 0; index < arrayLength; ++index)
1066 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1067 owner, context, m_rawArray[index]);
1070 for (
size_t index = 0; index < arrayLength; ++index)
1072 alignBitPosition(endBitPosition);
1073 endBitPosition += detail::packedArrayTraitsBitSizeOf<PackedArrayTraits<ArrayTraits>>(
1074 owner, context, endBitPosition, m_rawArray[index]);
1078 return endBitPosition - bitPosition;
1081 size_t initializeOffsetsPackedImpl(
OwnerType& owner,
size_t bitPosition)
1085 size_t endBitPosition = bitPosition;
1087 const size_t arrayLength = m_rawArray.size();
1088 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1090 if (arrayLength > 0)
1092 PackingContext context;
1094 for (
size_t index = 0; index < arrayLength; ++index)
1096 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1097 owner, context, m_rawArray[index]);
1100 for (
size_t index = 0; index < arrayLength; ++index)
1102 initializeOffset(owner, index, endBitPosition);
1103 endBitPosition = detail::packedArrayTraitsInitializeOffsets<PackedArrayTraits<ArrayTraits>>(
1104 owner, context, endBitPosition, m_rawArray[index]);
1108 return endBitPosition;
1111 void readPackedImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength = 0)
1115 size_t readLength = readArrayLength(owner, in, arrayLength);
1121 m_rawArray.reserve(readLength);
1123 PackingContext context;
1125 for (
size_t index = 0; index < readLength; ++index)
1127 alignAndCheckOffset(in, owner, index);
1128 detail::packedArrayTraitsRead<PackedArrayTraits<ArrayTraits>>(
1129 owner, m_rawArray, context, in, index);
1134 void writePackedImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1138 const size_t arrayLength = m_rawArray.size();
1139 writeArrayLength(out, arrayLength);
1141 if (arrayLength > 0)
1143 PackingContext context;
1145 for (
size_t index = 0; index < arrayLength; ++index)
1147 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1148 owner, context, m_rawArray[index]);
1151 for (
size_t index = 0; index < arrayLength; ++index)
1153 alignAndCheckOffset(out, owner, index);
1154 detail::packedArrayTraitsWrite<PackedArrayTraits<ArrayTraits>>(
1155 owner, context, out, m_rawArray[index]);
1167 template <
typename ARRAY,
typename RAW_ARRAY>
1170 return ARRAY(std::forward<RAW_ARRAY>(rawArray));
1176 template <
typename ARRAY>
size_t bitSizeOf(const OwnerType &owner, size_t bitPosition) const
Array(NoInitT, const Array &other)
bool operator==(const Array &other) const
void readPacked(BitStreamReader &in, size_t arrayLength=0)
Array & operator=(Array &&other)=default
size_t initializeOffsetsPacked(OwnerType &owner, size_t bitPosition)
Array & assign(NoInitT, const Array &other)
void write(BitStreamWriter &out) const
void read(OwnerType &owner, BitStreamReader &in, size_t arrayLength=0)
Array & operator=(const Array &other)=default
size_t bitSizeOfPacked(size_t bitPosition) const
size_t initializeOffsets(OwnerType &owner, size_t bitPosition)
void readPacked(OwnerType &owner, BitStreamReader &in, size_t arrayLength=0)
void read(BitStreamReader &in, size_t arrayLength=0)
typename detail::array_owner_type< ArrayTraits, ArrayExpressions >::type OwnerType
size_t initializeOffsets(size_t bitPosition)
void writePacked(BitStreamWriter &out) const
uint32_t hashCode() const
Array(RawArray &&rawArray)
bool operator<(const Array &other) const
Array(PropagateAllocatorT, const Array &other, const allocator_type &allocator)
ARRAY_EXPRESSIONS ArrayExpressions
typename RawArray::allocator_type allocator_type
size_t bitSizeOf(size_t bitPosition) const
Array(Array &&other)=default
Array(PropagateAllocatorT, NoInitT, const Array &other, const allocator_type &allocator)
void initializeElements(OwnerType &owner)
const RawArray & getRawArray() const
Array & assign(NoInitT, Array &&other)
void write(const OwnerType &owner, BitStreamWriter &out) const
Array(NoInitT, Array &&other)
size_t initializeOffsetsPacked(size_t bitPosition)
Array(const RawArray &rawArray)
size_t bitSizeOfPacked(const OwnerType &ownerType, size_t bitPosition) const
Array(const allocator_type &allocator=allocator_type())
Array(const Array &other)=default
void writePacked(const OwnerType &owner, BitStreamWriter &out) const
T read(BitStreamReader &in)
void write(BitStreamWriter &out, T value)
ARRAY createOptionalArray(RAW_ARRAY &&rawArray)
T allocatorPropagatingCopy(const T &source, const ALLOC &allocator)
constexpr size_t alignTo(size_t alignmentValue, size_t bitPosition)
constexpr NullOptType NullOpt
size_t initializeOffsets(size_t bitPosition, T value)
size_t bitSizeOfVarSize(uint32_t value)
std::enable_if< std::is_integral< T >::value &&(sizeof(T)<=4), uint32_t >::type calcHashCode(uint32_t seedValue, T value)
uint32_t convertSizeToUInt32(size_t value)
size_t bitSizeOf(T value)