1 #ifndef ZSERIO_ARRAY_H_INC
2 #define ZSERIO_ARRAY_H_INC
24 struct DummyArrayExpressions
28 struct DummyArrayOwner
32 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS,
typename =
void>
33 struct array_owner_type
35 using type = DummyArrayOwner;
38 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS>
39 struct array_owner_type<ARRAY_TRAITS, ARRAY_EXPRESSIONS,
40 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value>::type>
42 using type =
typename ARRAY_TRAITS::OwnerType;
45 template <
typename ARRAY_TRAITS,
typename ARRAY_EXPRESSIONS>
46 struct array_owner_type<ARRAY_TRAITS, ARRAY_EXPRESSIONS,
47 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
48 has_owner_type<ARRAY_EXPRESSIONS>::value>::type>
50 using type =
typename ARRAY_EXPRESSIONS::OwnerType;
54 template <
typename T,
typename =
void>
55 struct packing_context_type
57 using type = DeltaContext;
61 struct packing_context_type<T, typename std::enable_if<has_zserio_packing_context<T>::value>::type>
63 using type =
typename T::ZserioPackingContext;
67 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
68 typename std::enable_if<has_initialize_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
69 void initializeOffset(OWNER_TYPE& owner,
size_t index,
size_t bitPosition)
71 ARRAY_EXPRESSIONS::initializeOffset(owner, index, bitPosition);
74 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
75 typename std::enable_if<!has_initialize_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
76 void initializeOffset(OWNER_TYPE&,
size_t,
size_t)
80 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
81 typename std::enable_if<has_check_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
82 void checkOffset(
const OWNER_TYPE& owner,
size_t index,
size_t bitPosition)
84 ARRAY_EXPRESSIONS::checkOffset(owner, index, bitPosition);
87 template <
typename ARRAY_EXPRESSIONS,
typename OWNER_TYPE,
88 typename std::enable_if<!has_check_offset<ARRAY_EXPRESSIONS>::value,
int>::type = 0>
89 void checkOffset(
const OWNER_TYPE&,
size_t,
size_t)
93 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
94 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
95 void packedArrayTraitsInitContext(
96 const OWNER_TYPE& owner, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
98 PACKED_ARRAY_TRAITS::initContext(owner, context, element);
101 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
102 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
103 void packedArrayTraitsInitContext(
104 const OWNER_TYPE&, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
106 PACKED_ARRAY_TRAITS::initContext(context, element);
110 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
111 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && has_owner_type<ARRAY_TRAITS>::value,
113 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE& owner)
118 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
119 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && !has_owner_type<ARRAY_TRAITS>::value,
121 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE&)
127 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
128 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
129 size_t arrayTraitsBitSizeOf(
130 const OWNER_TYPE& owner,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
135 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
136 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
137 size_t arrayTraitsBitSizeOf(
138 const OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
144 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
145 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
146 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
147 const typename PACKED_ARRAY_TRAITS::ElementType& element)
152 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
153 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
154 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
155 const typename PACKED_ARRAY_TRAITS::ElementType& element)
161 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
162 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
163 size_t arrayTraitsInitializeOffsets(
164 OWNER_TYPE& owner,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType& element)
169 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
170 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
171 !std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
173 size_t arrayTraitsInitializeOffsets(
174 OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
179 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
180 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
181 std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
183 size_t arrayTraitsInitializeOffsets(OWNER_TYPE&,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType element)
189 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
190 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
191 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
192 typename PACKED_ARRAY_TRAITS::ElementType& element)
197 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
198 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
199 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
201 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
202 const typename PACKED_ARRAY_TRAITS::ElementType& element)
207 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
208 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
209 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
211 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
212 typename PACKED_ARRAY_TRAITS::ElementType element)
218 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
219 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value && !has_allocator<ARRAY_TRAITS>::value,
221 void arrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
226 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
227 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
229 void arrayTraitsRead(OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
234 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
235 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && !has_allocator<ARRAY_TRAITS>::value,
237 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
242 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
243 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
245 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
251 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
252 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
253 has_allocator<PACKED_ARRAY_TRAITS>::value,
255 void packedArrayTraitsRead(
256 OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
261 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
262 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
263 !has_allocator<PACKED_ARRAY_TRAITS>::value,
265 void packedArrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
266 BitStreamReader& in,
size_t index)
274 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
275 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
276 !has_allocator<PACKED_ARRAY_TRAITS>::value,
278 void packedArrayTraitsRead(
279 const OWNER_TYPE&, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
285 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
286 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
287 void arrayTraitsWrite(
288 const OWNER_TYPE& owner, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
293 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
294 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
295 void arrayTraitsWrite(
296 const OWNER_TYPE&, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
302 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
303 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
304 void packedArrayTraitsWrite(
const OWNER_TYPE& owner, PACKING_CONTEXT& context, BitStreamWriter& out,
305 const typename PACKED_ARRAY_TRAITS::ElementType& element)
310 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
311 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
312 void packedArrayTraitsWrite(
const OWNER_TYPE&, PACKING_CONTEXT& context, BitStreamWriter& out,
313 const typename PACKED_ARRAY_TRAITS::ElementType& element)
339 template <
typename RAW_ARRAY,
typename ARRAY_TRAITS,
ArrayType ARRAY_TYPE,
340 typename ARRAY_EXPRESSIONS = detail::DummyArrayExpressions>
359 using OwnerType =
typename detail::array_owner_type<ArrayTraits, ArrayExpressions>::type;
370 m_rawArray(allocator)
388 m_rawArray(std::move(rawArray))
412 template <
typename T =
typename RAW_ARRAY::value_type,
413 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
416 other.m_rawArray.get_allocator()))
418 m_rawArray.reserve(other.m_rawArray.size());
419 for (
const auto& value : other.m_rawArray)
420 m_rawArray.emplace_back(
NoInit, value);
430 template <
typename T =
typename RAW_ARRAY::value_type,
431 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
434 const RawArray rawArray(other.m_rawArray.get_allocator());
435 m_rawArray = rawArray;
436 m_rawArray.reserve(other.m_rawArray.size());
437 for (
const auto& value : other.m_rawArray)
438 m_rawArray.emplace_back(
NoInit, value);
450 template <
typename T =
typename RAW_ARRAY::value_type,
451 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
453 Array(std::move(other))
464 template <
typename T =
typename RAW_ARRAY::value_type,
465 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
488 template <
typename T =
typename RAW_ARRAY::value_type,
489 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
503 return m_rawArray == other.m_rawArray;
515 return m_rawArray < other.m_rawArray;
554 typename std::enable_if<has_initialize_element<ARRAY_EXPRESSIONS_>::value,
int>::type = 0>
558 for (
auto&& element : m_rawArray)
560 ArrayExpressions::initializeElement(owner, element, index);
574 template <
typename OWNER_TYPE_ =
OwnerType,
575 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
578 return bitSizeOfImpl(detail::DummyArrayOwner(), bitPosition);
591 template <
typename OWNER_TYPE_ =
OwnerType,
592 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
595 return bitSizeOfImpl(owner, bitPosition);
607 template <
typename OWNER_TYPE_ =
OwnerType,
608 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
611 detail::DummyArrayOwner owner;
612 return initializeOffsetsImpl(owner, bitPosition);
625 template <
typename OWNER_TYPE_ =
OwnerType,
626 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
629 return initializeOffsetsImpl(owner, bitPosition);
640 template <
typename OWNER_TYPE_ =
OwnerType,
641 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
644 detail::DummyArrayOwner owner;
645 readImpl(owner, in, arrayLength);
657 template <
typename OWNER_TYPE_ =
OwnerType,
658 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
661 readImpl(owner, in, arrayLength);
671 template <
typename OWNER_TYPE_ =
OwnerType,
672 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
675 writeImpl(detail::DummyArrayOwner(), out);
686 template <
typename OWNER_TYPE_ =
OwnerType,
687 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
690 writeImpl(owner, out);
702 template <
typename OWNER_TYPE_ =
OwnerType,
703 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
706 return bitSizeOfPackedImpl(detail::DummyArrayOwner(), bitPosition);
719 template <
typename OWNER_TYPE_ =
OwnerType,
720 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
723 return bitSizeOfPackedImpl(ownerType, bitPosition);
735 template <
typename OWNER_TYPE_ =
OwnerType,
736 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
739 detail::DummyArrayOwner owner;
740 return initializeOffsetsPackedImpl(owner, bitPosition);
753 template <
typename OWNER_TYPE_ =
OwnerType,
754 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
757 return initializeOffsetsPackedImpl(owner, bitPosition);
768 template <
typename OWNER_TYPE_ =
OwnerType,
769 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
772 detail::DummyArrayOwner owner;
773 readPackedImpl(owner, in, arrayLength);
785 template <
typename OWNER_TYPE_ =
OwnerType,
786 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
789 readPackedImpl(owner, in, arrayLength);
799 template <
typename OWNER_TYPE_ =
OwnerType,
800 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
803 writePackedImpl(detail::DummyArrayOwner(), out);
814 template <
typename OWNER_TYPE_ =
OwnerType,
815 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
818 writePackedImpl(owner, out);
822 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
825 static void addBitSizeOfArrayLength(
size_t&,
size_t)
828 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
831 static void addBitSizeOfArrayLength(
size_t& bitPosition,
size_t arrayLength)
836 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
839 static void alignBitPosition(
size_t&)
842 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
845 static void alignBitPosition(
size_t& bitPosition)
847 bitPosition =
alignTo(8, bitPosition);
850 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
853 static void alignAndCheckOffset(IO&, OWNER_TYPE&,
size_t)
856 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
859 static void alignAndCheckOffset(IO& io, OWNER_TYPE& owner,
size_t index)
862 detail::checkOffset<ArrayExpressions>(owner, index, io.getBitPosition() / 8);
865 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
868 static void initializeOffset(
OwnerType&,
size_t,
size_t&)
871 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
874 static void initializeOffset(
OwnerType& owner,
size_t index,
size_t& bitPosition)
876 bitPosition =
alignTo(8, bitPosition);
877 detail::initializeOffset<ArrayExpressions>(owner, index, bitPosition / 8);
880 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
884 static size_t readArrayLength(
OwnerType&, BitStreamReader&,
size_t arrayLength)
889 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
892 static size_t readArrayLength(
OwnerType&, BitStreamReader& in,
size_t)
894 return in.readVarSize();
897 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
898 typename std::enable_if<ARRAY_TYPE_ == ArrayType::IMPLICIT, int>::type = 0>
899 static size_t readArrayLength(
OwnerType& owner, BitStreamReader& in,
size_t)
902 "Implicit array elements must have constant bit size!");
904 const size_t remainingBits = in.getBufferBitSize() - in.getBitPosition();
905 return remainingBits / detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
908 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
911 static void writeArrayLength(BitStreamWriter&,
size_t)
914 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
917 static void writeArrayLength(BitStreamWriter& out,
size_t arrayLength)
922 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
925 static size_t constBitSizeOfElements(
size_t,
size_t arrayLength,
size_t elementBitSize)
927 return arrayLength * elementBitSize;
930 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
933 static size_t constBitSizeOfElements(
size_t bitPosition,
size_t arrayLength,
size_t elementBitSize)
935 size_t endBitPosition =
alignTo(8, bitPosition);
936 endBitPosition += elementBitSize + (arrayLength - 1) *
alignTo(8, elementBitSize);
938 return endBitPosition - bitPosition;
942 typename std::enable_if<ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
943 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
945 size_t endBitPosition = bitPosition;
947 const size_t arrayLength = m_rawArray.size();
948 addBitSizeOfArrayLength(endBitPosition, arrayLength);
952 const size_t elementBitSize = detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
953 endBitPosition += constBitSizeOfElements(endBitPosition, arrayLength, elementBitSize);
956 return endBitPosition - bitPosition;
960 typename std::enable_if<!ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
961 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
963 size_t endBitPosition = bitPosition;
965 const size_t arrayLength = m_rawArray.size();
966 addBitSizeOfArrayLength(endBitPosition, arrayLength);
968 for (
size_t index = 0; index < arrayLength; ++index)
970 alignBitPosition(endBitPosition);
972 detail::arrayTraitsBitSizeOf<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
975 return endBitPosition - bitPosition;
978 size_t initializeOffsetsImpl(
OwnerType& owner,
size_t bitPosition)
980 size_t endBitPosition = bitPosition;
982 const size_t arrayLength = m_rawArray.size();
983 addBitSizeOfArrayLength(endBitPosition, arrayLength);
985 for (
size_t index = 0; index < arrayLength; ++index)
987 initializeOffset(owner, index, endBitPosition);
989 detail::arrayTraitsInitializeOffsets<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
992 return endBitPosition;
995 void readImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength)
997 size_t readLength = readArrayLength(owner, in, arrayLength);
1000 m_rawArray.reserve(readLength);
1001 for (
size_t index = 0; index < readLength; ++index)
1003 alignAndCheckOffset(in, owner, index);
1004 detail::arrayTraitsRead<ArrayTraits>(owner, m_rawArray, in, index);
1008 void writeImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1010 const size_t arrayLength = m_rawArray.size();
1011 writeArrayLength(out, arrayLength);
1013 for (
size_t index = 0; index < arrayLength; ++index)
1015 alignAndCheckOffset(out, owner, index);
1016 detail::arrayTraitsWrite<ArrayTraits>(owner, out, m_rawArray[index]);
1020 using PackingContext =
typename detail::packing_context_type<typename RawArray::value_type>::type;
1022 size_t bitSizeOfPackedImpl(
const OwnerType& owner,
size_t bitPosition)
const
1026 size_t endBitPosition = bitPosition;
1028 const size_t arrayLength = m_rawArray.size();
1029 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1031 if (arrayLength > 0)
1033 PackingContext context;
1035 for (
size_t index = 0; index < arrayLength; ++index)
1037 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1038 owner, context, m_rawArray[index]);
1041 for (
size_t index = 0; index < arrayLength; ++index)
1043 alignBitPosition(endBitPosition);
1044 endBitPosition += detail::packedArrayTraitsBitSizeOf<PackedArrayTraits<ArrayTraits>>(
1045 owner, context, endBitPosition, m_rawArray[index]);
1049 return endBitPosition - bitPosition;
1052 size_t initializeOffsetsPackedImpl(
OwnerType& owner,
size_t bitPosition)
1056 size_t endBitPosition = bitPosition;
1058 const size_t arrayLength = m_rawArray.size();
1059 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1061 if (arrayLength > 0)
1063 PackingContext context;
1065 for (
size_t index = 0; index < arrayLength; ++index)
1067 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1068 owner, context, m_rawArray[index]);
1071 for (
size_t index = 0; index < arrayLength; ++index)
1073 initializeOffset(owner, index, endBitPosition);
1074 endBitPosition = detail::packedArrayTraitsInitializeOffsets<PackedArrayTraits<ArrayTraits>>(
1075 owner, context, endBitPosition, m_rawArray[index]);
1079 return endBitPosition;
1082 void readPackedImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength = 0)
1086 size_t readLength = readArrayLength(owner, in, arrayLength);
1092 m_rawArray.reserve(readLength);
1094 PackingContext context;
1096 for (
size_t index = 0; index < readLength; ++index)
1098 alignAndCheckOffset(in, owner, index);
1099 detail::packedArrayTraitsRead<PackedArrayTraits<ArrayTraits>>(
1100 owner, m_rawArray, context, in, index);
1105 void writePackedImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1109 const size_t arrayLength = m_rawArray.size();
1110 writeArrayLength(out, arrayLength);
1112 if (arrayLength > 0)
1114 PackingContext context;
1116 for (
size_t index = 0; index < arrayLength; ++index)
1118 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1119 owner, context, m_rawArray[index]);
1122 for (
size_t index = 0; index < arrayLength; ++index)
1124 alignAndCheckOffset(out, owner, index);
1125 detail::packedArrayTraitsWrite<PackedArrayTraits<ArrayTraits>>(
1126 owner, context, out, m_rawArray[index]);
1138 template <
typename ARRAY,
typename RAW_ARRAY>
1141 return ARRAY(std::forward<RAW_ARRAY>(rawArray));
1147 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)
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)