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(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
96 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(
const OWNER_TYPE&, PACKING_CONTEXT& context,
104 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<
112 ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
113 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE& owner)
118 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
119 typename std::enable_if<
120 ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && !has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
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(
const OWNER_TYPE& owner,
size_t bitPosition,
130 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(
const OWNER_TYPE&,
size_t bitPosition,
138 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,
147 size_t bitPosition,
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(OWNER_TYPE& owner,
size_t bitPosition,
164 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,
int>::type = 0>
172 size_t arrayTraitsInitializeOffsets(OWNER_TYPE&,
size_t bitPosition,
173 const typename ARRAY_TRAITS::ElementType& element)
178 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
179 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
180 std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
int>::type = 0>
181 size_t arrayTraitsInitializeOffsets(OWNER_TYPE&,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType element)
187 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
188 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
189 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE& owner, PACKING_CONTEXT& context,
190 size_t bitPosition,
typename PACKED_ARRAY_TRAITS::ElementType& element)
195 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
196 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
197 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
int>::type = 0>
198 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
199 size_t bitPosition,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
204 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
205 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
206 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
int>::type = 0>
207 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
208 size_t bitPosition,
typename PACKED_ARRAY_TRAITS::ElementType element)
214 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
215 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value &&
216 !has_allocator<ARRAY_TRAITS>::value,
int>::type = 0>
217 void arrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
222 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
223 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value &&
224 has_allocator<ARRAY_TRAITS>::value,
int>::type = 0>
225 void arrayTraitsRead(OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
230 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
231 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
232 !has_allocator<ARRAY_TRAITS>::value,
int>::type = 0>
233 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
238 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
239 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
240 has_allocator<ARRAY_TRAITS>::value,
int>::type = 0>
241 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
247 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
248 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
249 has_allocator<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
250 void packedArrayTraitsRead(OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
251 BitStreamReader& in,
size_t index)
256 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
257 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
258 !has_allocator<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
259 void packedArrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
260 BitStreamReader& in,
size_t index)
268 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
269 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
270 !has_allocator<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
271 void packedArrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
272 BitStreamReader& in,
size_t index)
278 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
279 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
280 void arrayTraitsWrite(
const OWNER_TYPE& owner,
281 BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
286 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
287 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
288 void arrayTraitsWrite(
const OWNER_TYPE&,
289 BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
295 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
296 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
297 void packedArrayTraitsWrite(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
298 BitStreamWriter& out,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
303 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
304 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
305 void packedArrayTraitsWrite(
const OWNER_TYPE&, PACKING_CONTEXT& context,
306 BitStreamWriter& out,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
332 template <
typename RAW_ARRAY,
typename ARRAY_TRAITS,
ArrayType ARRAY_TYPE,
333 typename ARRAY_EXPRESSIONS = detail::DummyArrayExpressions>
352 using OwnerType =
typename detail::array_owner_type<ArrayTraits, ArrayExpressions>::type;
363 m_rawArray(allocator)
381 m_rawArray(std::move(rawArray))
391 Array& operator=(
const Array& other) =
default;
405 template <
typename T =
typename RAW_ARRAY::value_type,
406 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
409 other.m_rawArray.get_allocator()))
411 m_rawArray.reserve(other.m_rawArray.size());
412 for (
const auto& value : other.m_rawArray)
413 m_rawArray.emplace_back(
NoInit, value);
423 template <
typename T =
typename RAW_ARRAY::value_type,
424 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
427 const RawArray rawArray(other.m_rawArray.get_allocator());
428 m_rawArray = rawArray;
429 m_rawArray.reserve(other.m_rawArray.size());
430 for (
const auto& value : other.m_rawArray)
431 m_rawArray.emplace_back(
NoInit, value);
443 template <
typename T =
typename RAW_ARRAY::value_type,
444 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
446 Array(std::move(other))
458 template <
typename T =
typename RAW_ARRAY::value_type,
459 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
462 return operator=(std::move(other));
482 template <
typename T =
typename RAW_ARRAY::value_type,
483 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
497 return m_rawArray == other.m_rawArray;
509 return m_rawArray < other.m_rawArray;
548 typename std::enable_if<has_initialize_element<ARRAY_EXPRESSIONS_>::value,
int>::type = 0>
552 for (
auto&& element : m_rawArray)
554 ArrayExpressions::initializeElement(owner, element, index);
568 template <
typename OWNER_TYPE_ =
OwnerType,
569 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
572 return bitSizeOfImpl(detail::DummyArrayOwner(), bitPosition);
585 template <
typename OWNER_TYPE_ =
OwnerType,
586 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
589 return bitSizeOfImpl(owner, bitPosition);
601 template <
typename OWNER_TYPE_ =
OwnerType,
602 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
605 detail::DummyArrayOwner owner;
606 return initializeOffsetsImpl(owner, bitPosition);
619 template <
typename OWNER_TYPE_ =
OwnerType,
620 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
623 return initializeOffsetsImpl(owner, bitPosition);
634 template <
typename OWNER_TYPE_ =
OwnerType,
635 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
638 detail::DummyArrayOwner owner;
639 readImpl(owner, in, arrayLength);
651 template <
typename OWNER_TYPE_ =
OwnerType,
652 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
655 readImpl(owner, in, arrayLength);
665 template <
typename OWNER_TYPE_ =
OwnerType,
666 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
669 writeImpl(detail::DummyArrayOwner(), out);
680 template <
typename OWNER_TYPE_ =
OwnerType,
681 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
684 writeImpl(owner, out);
696 template <
typename OWNER_TYPE_ =
OwnerType,
697 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
700 return bitSizeOfPackedImpl(detail::DummyArrayOwner(), bitPosition);
713 template <
typename OWNER_TYPE_ =
OwnerType,
714 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
717 return bitSizeOfPackedImpl(ownerType, bitPosition);
729 template <
typename OWNER_TYPE_ =
OwnerType,
730 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
733 detail::DummyArrayOwner owner;
734 return initializeOffsetsPackedImpl(owner, bitPosition);
747 template <
typename OWNER_TYPE_ =
OwnerType,
748 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
751 return initializeOffsetsPackedImpl(owner, bitPosition);
762 template <
typename OWNER_TYPE_ =
OwnerType,
763 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
766 detail::DummyArrayOwner owner;
767 readPackedImpl(owner, in, arrayLength);
779 template <
typename OWNER_TYPE_ =
OwnerType,
780 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
783 readPackedImpl(owner, in, arrayLength);
793 template <
typename OWNER_TYPE_ =
OwnerType,
794 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
797 writePackedImpl(detail::DummyArrayOwner(), out);
808 template <
typename OWNER_TYPE_ =
OwnerType,
809 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
812 writePackedImpl(owner, out);
816 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
817 typename std::enable_if<
819 static void addBitSizeOfArrayLength(
size_t&,
size_t)
822 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
823 typename std::enable_if<
825 static void addBitSizeOfArrayLength(
size_t& bitPosition,
size_t arrayLength)
830 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
831 typename std::enable_if<
833 static void alignBitPosition(
size_t&)
836 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
837 typename std::enable_if<
839 static void alignBitPosition(
size_t& bitPosition)
841 bitPosition =
alignTo(8, bitPosition);
844 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
845 typename std::enable_if<
847 static void alignAndCheckOffset(IO&, OWNER_TYPE&,
size_t)
850 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
851 typename std::enable_if<
853 static void alignAndCheckOffset(IO& io, OWNER_TYPE& owner,
size_t index)
856 detail::checkOffset<ArrayExpressions>(owner, index, io.getBitPosition() / 8);
859 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
860 typename std::enable_if<
862 static void initializeOffset(
OwnerType&,
size_t,
size_t&)
865 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
866 typename std::enable_if<
868 static void initializeOffset(
OwnerType& owner,
size_t index,
size_t& bitPosition)
870 bitPosition =
alignTo(8, bitPosition);
871 detail::initializeOffset<ArrayExpressions>(owner, index, bitPosition / 8);
874 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
875 typename std::enable_if<
884 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
885 typename std::enable_if<
892 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
893 typename std::enable_if<ARRAY_TYPE_ == ArrayType::IMPLICIT, int>::type = 0>
897 "Implicit array elements must have constant bit size!");
900 return remainingBits / detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
903 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
904 typename std::enable_if<
909 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
910 typename std::enable_if<
917 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
918 typename std::enable_if<
920 static size_t constBitSizeOfElements(
size_t,
size_t arrayLength,
size_t elementBitSize)
922 return arrayLength * elementBitSize;
925 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
926 typename std::enable_if<
928 static size_t constBitSizeOfElements(
size_t bitPosition,
size_t arrayLength,
size_t elementBitSize)
930 size_t endBitPosition =
alignTo(8, bitPosition);
931 endBitPosition += elementBitSize + (arrayLength - 1) *
alignTo(8, elementBitSize);
933 return endBitPosition - bitPosition;
937 typename std::enable_if<ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
938 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const 940 size_t endBitPosition = bitPosition;
942 const size_t arrayLength = m_rawArray.size();
943 addBitSizeOfArrayLength(endBitPosition, arrayLength);
947 const size_t elementBitSize = detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
948 endBitPosition += constBitSizeOfElements(endBitPosition, arrayLength, elementBitSize);
951 return endBitPosition - bitPosition;
955 typename std::enable_if<!ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
956 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const 958 size_t endBitPosition = bitPosition;
960 const size_t arrayLength = m_rawArray.size();
961 addBitSizeOfArrayLength(endBitPosition, arrayLength);
963 for (
size_t index = 0; index < arrayLength; ++index)
965 alignBitPosition(endBitPosition);
966 endBitPosition += detail::arrayTraitsBitSizeOf<ArrayTraits>(
967 owner, endBitPosition, m_rawArray[index]);
970 return endBitPosition - bitPosition;
973 size_t initializeOffsetsImpl(
OwnerType& owner,
size_t bitPosition)
975 size_t endBitPosition = bitPosition;
977 const size_t arrayLength = m_rawArray.size();
978 addBitSizeOfArrayLength(endBitPosition, arrayLength);
980 for (
size_t index = 0; index < arrayLength; ++index)
982 initializeOffset(owner, index, endBitPosition);
983 endBitPosition = detail::arrayTraitsInitializeOffsets<ArrayTraits>(
984 owner, endBitPosition, m_rawArray[index]);
987 return endBitPosition;
992 size_t readLength = readArrayLength(owner, in, arrayLength);
995 m_rawArray.reserve(readLength);
996 for (
size_t index = 0; index < readLength; ++index)
998 alignAndCheckOffset(in, owner, index);
999 detail::arrayTraitsRead<ArrayTraits>(owner, m_rawArray, in, index);
1005 const size_t arrayLength = m_rawArray.size();
1006 writeArrayLength(out, arrayLength);
1008 for (
size_t index = 0; index < arrayLength; ++index)
1010 alignAndCheckOffset(out, owner, index);
1011 detail::arrayTraitsWrite<ArrayTraits>(owner, out, m_rawArray[index]);
1017 size_t bitSizeOfPackedImpl(
const OwnerType& owner,
size_t bitPosition)
const 1021 size_t endBitPosition = bitPosition;
1023 const size_t arrayLength = m_rawArray.size();
1024 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1026 if (arrayLength > 0)
1028 PackingContext context;
1030 for (
size_t index = 0; index < arrayLength; ++index)
1032 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1033 owner, context, m_rawArray[index]);
1036 for (
size_t index = 0; index < arrayLength; ++index)
1038 alignBitPosition(endBitPosition);
1039 endBitPosition += detail::packedArrayTraitsBitSizeOf<PackedArrayTraits<ArrayTraits>>(
1040 owner, context, endBitPosition, m_rawArray[index]);
1044 return endBitPosition - bitPosition;
1047 size_t initializeOffsetsPackedImpl(
OwnerType& owner,
size_t bitPosition)
1051 size_t endBitPosition = bitPosition;
1053 const size_t arrayLength = m_rawArray.size();
1054 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1056 if (arrayLength > 0)
1058 PackingContext context;
1060 for (
size_t index = 0; index < arrayLength; ++index)
1062 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1063 owner, context, m_rawArray[index]);
1066 for (
size_t index = 0; index < arrayLength; ++index)
1068 initializeOffset(owner, index, endBitPosition);
1069 endBitPosition = detail::packedArrayTraitsInitializeOffsets<PackedArrayTraits<ArrayTraits>>(
1070 owner, context, endBitPosition, m_rawArray[index]);
1074 return endBitPosition;
1081 size_t readLength = readArrayLength(owner, in, arrayLength);
1087 m_rawArray.reserve(readLength);
1089 PackingContext context;
1091 for (
size_t index = 0; index < readLength; ++index)
1093 alignAndCheckOffset(in, owner, index);
1094 detail::packedArrayTraitsRead<PackedArrayTraits<ArrayTraits>>(
1095 owner, m_rawArray, context, in, index);
1104 const size_t arrayLength = m_rawArray.size();
1105 writeArrayLength(out, arrayLength);
1107 if (arrayLength > 0)
1109 PackingContext context;
1111 for (
size_t index = 0; index < arrayLength; ++index)
1113 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1114 owner, context, m_rawArray[index]);
1117 for (
size_t index = 0; index < arrayLength; ++index)
1119 alignAndCheckOffset(out, owner, index);
1120 detail::packedArrayTraitsWrite<PackedArrayTraits<ArrayTraits>>(
1121 owner, context, out, m_rawArray[index]);
1133 template <
typename ARRAY,
typename RAW_ARRAY>
1136 return ARRAY(std::forward<RAW_ARRAY>(rawArray));
1142 template <
typename ARRAY>
1150 #endif // ZSERIO_ARRAY_H_INC
size_t initializeOffsets(OwnerType &owner, size_t bitPosition)
size_t alignTo(size_t alignmentValue, size_t bitPosition)
Array(NoInitT, const Array &other)
Array(const allocator_type &allocator=allocator_type())
typename detail::array_owner_type< ArrayTraits, ArrayExpressions >::type OwnerType
Array(const RawArray &rawArray)
bool operator<(const Array &other) const
void write(const OwnerType &owner, BitStreamWriter &out) const
Array & assign(NoInitT, Array &&other)
size_t initializeOffsetsPacked(size_t bitPosition)
Array(NoInitT, Array &&other)
size_t initializeOffsets(size_t bitPosition)
size_t bitSizeOf(const OwnerType &owner, size_t bitPosition) const
void writeVarSize(uint32_t data)
T allocatorPropagatingCopy(const T &source, const ALLOC &allocator)
size_t bitSizeOfVarSize(uint32_t value)
uint32_t convertSizeToUInt32(size_t value)
T read(BitStreamReader &in)
void writePacked(const OwnerType &owner, BitStreamWriter &out) const
size_t bitSizeOfPacked(const OwnerType &ownerType, size_t bitPosition) const
size_t bitSizeOf(size_t bitPosition) const
void write(BitStreamWriter &out, T value)
BitPosType getBitPosition() const
size_t initializeOffsetsPacked(OwnerType &owner, size_t bitPosition)
void readPacked(OwnerType &owner, BitStreamReader &in, size_t arrayLength=0)
constexpr NullOptType NullOpt
void readPacked(BitStreamReader &in, size_t arrayLength=0)
size_t bitSizeOfPacked(size_t bitPosition) const
void writePacked(BitStreamWriter &out) const
Array & assign(NoInitT, const Array &other)
void read(OwnerType &owner, BitStreamReader &in, size_t arrayLength=0)
typename RawArray::allocator_type allocator_type
Array(PropagateAllocatorT, const Array &other, const allocator_type &allocator)
size_t initializeOffsets(size_t bitPosition, T value)
bool operator==(const Array &other) const
std::enable_if< std::is_integral< T >::value &&(sizeof(T)<=4), uint32_t >::type calcHashCode(uint32_t seedValue, T value)
void write(BitStreamWriter &out) const
uint32_t hashCode() const
ARRAY createOptionalArray(RAW_ARRAY &&rawArray)
ARRAY_EXPRESSIONS ArrayExpressions
size_t getBufferBitSize() const
const RawArray & getRawArray() const
size_t bitSizeOf(T value)
Array(PropagateAllocatorT, NoInitT, const Array &other, const allocator_type &allocator)
void initializeElements(OwnerType &owner)
void read(BitStreamReader &in, size_t arrayLength=0)
Array(RawArray &&rawArray)