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 &&
95 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
97 void packedArrayTraitsInitContext(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
98 const typename PACKED_ARRAY_TRAITS::ElementType& element)
100 PACKED_ARRAY_TRAITS::initContext(owner, context, element);
103 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
104 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
105 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
107 void packedArrayTraitsInitContext(
108 const OWNER_TYPE& owner, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
110 PACKED_ARRAY_TRAITS::initContext(owner, context, element);
113 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
114 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
115 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
117 void packedArrayTraitsInitContext(
118 const OWNER_TYPE&, PACKING_CONTEXT& context,
const typename PACKED_ARRAY_TRAITS::ElementType& element)
120 PACKED_ARRAY_TRAITS::initContext(context, element);
123 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
124 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
125 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
127 void packedArrayTraitsInitContext(
128 const OWNER_TYPE&, PACKING_CONTEXT& context,
typename PACKED_ARRAY_TRAITS::ElementType element)
130 PACKED_ARRAY_TRAITS::initContext(context, element);
134 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
135 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && has_owner_type<ARRAY_TRAITS>::value,
137 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE& owner)
142 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
143 typename std::enable_if<ARRAY_TRAITS::IS_BITSIZEOF_CONSTANT && !has_owner_type<ARRAY_TRAITS>::value,
145 size_t arrayTraitsConstBitSizeOf(
const OWNER_TYPE&)
151 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
152 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
153 size_t arrayTraitsBitSizeOf(
154 const OWNER_TYPE& owner,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
159 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
160 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
161 size_t arrayTraitsBitSizeOf(
162 const OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
168 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
169 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
170 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
171 const typename PACKED_ARRAY_TRAITS::ElementType& element)
176 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
177 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
178 size_t packedArrayTraitsBitSizeOf(
const OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
179 const typename PACKED_ARRAY_TRAITS::ElementType& element)
185 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
186 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
187 size_t arrayTraitsInitializeOffsets(
188 OWNER_TYPE& owner,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType& element)
193 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
194 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
195 !std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
197 size_t arrayTraitsInitializeOffsets(
198 OWNER_TYPE&,
size_t bitPosition,
const typename ARRAY_TRAITS::ElementType& element)
203 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
204 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value &&
205 std::is_scalar<typename ARRAY_TRAITS::ElementType>::value,
207 size_t arrayTraitsInitializeOffsets(OWNER_TYPE&,
size_t bitPosition,
typename ARRAY_TRAITS::ElementType element)
213 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
214 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
215 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE& owner, PACKING_CONTEXT& context,
size_t bitPosition,
216 typename PACKED_ARRAY_TRAITS::ElementType& element)
221 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
222 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
223 !std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
225 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
226 const typename PACKED_ARRAY_TRAITS::ElementType& element)
231 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
232 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
233 std::is_scalar<typename PACKED_ARRAY_TRAITS::ElementType>::value,
235 size_t packedArrayTraitsInitializeOffsets(OWNER_TYPE&, PACKING_CONTEXT& context,
size_t bitPosition,
236 typename PACKED_ARRAY_TRAITS::ElementType element)
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& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
250 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
251 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
253 void arrayTraitsRead(OWNER_TYPE& owner, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
258 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
259 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && !has_allocator<ARRAY_TRAITS>::value,
261 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
266 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
267 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value && has_allocator<ARRAY_TRAITS>::value,
269 void arrayTraitsRead(
const OWNER_TYPE&, RAW_ARRAY& rawArray, BitStreamReader& in,
size_t index)
275 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
276 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
277 has_allocator<PACKED_ARRAY_TRAITS>::value,
279 void packedArrayTraitsRead(
280 OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
285 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
286 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value &&
287 !has_allocator<PACKED_ARRAY_TRAITS>::value,
289 void packedArrayTraitsRead(
const OWNER_TYPE& owner, RAW_ARRAY& rawArray, PACKING_CONTEXT& context,
290 BitStreamReader& in,
size_t index)
298 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename RAW_ARRAY,
typename PACKING_CONTEXT,
299 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value &&
300 !has_allocator<PACKED_ARRAY_TRAITS>::value,
302 void packedArrayTraitsRead(
303 const OWNER_TYPE&, RAW_ARRAY& rawArray, PACKING_CONTEXT& context, BitStreamReader& in,
size_t index)
309 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
310 typename std::enable_if<has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
311 void arrayTraitsWrite(
312 const OWNER_TYPE& owner, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
317 template <
typename ARRAY_TRAITS,
typename OWNER_TYPE,
318 typename std::enable_if<!has_owner_type<ARRAY_TRAITS>::value,
int>::type = 0>
319 void arrayTraitsWrite(
320 const OWNER_TYPE&, BitStreamWriter& out,
const typename ARRAY_TRAITS::ElementType& element)
326 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
327 typename std::enable_if<has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
328 void packedArrayTraitsWrite(
const OWNER_TYPE& owner, PACKING_CONTEXT& context, BitStreamWriter& out,
329 const typename PACKED_ARRAY_TRAITS::ElementType& element)
334 template <
typename PACKED_ARRAY_TRAITS,
typename OWNER_TYPE,
typename PACKING_CONTEXT,
335 typename std::enable_if<!has_owner_type<PACKED_ARRAY_TRAITS>::value,
int>::type = 0>
336 void packedArrayTraitsWrite(
const OWNER_TYPE&, PACKING_CONTEXT& context, BitStreamWriter& out,
337 const typename PACKED_ARRAY_TRAITS::ElementType& element)
363 template <
typename RAW_ARRAY,
typename ARRAY_TRAITS,
ArrayType ARRAY_TYPE,
364 typename ARRAY_EXPRESSIONS = detail::DummyArrayExpressions>
383 using OwnerType =
typename detail::array_owner_type<ArrayTraits, ArrayExpressions>::type;
394 m_rawArray(allocator)
412 m_rawArray(std::move(rawArray))
436 template <
typename T =
typename RAW_ARRAY::value_type,
437 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
440 other.m_rawArray.get_allocator()))
442 m_rawArray.reserve(other.m_rawArray.size());
443 for (
const auto& value : other.m_rawArray)
445 m_rawArray.emplace_back(
NoInit, value);
456 template <
typename T =
typename RAW_ARRAY::value_type,
457 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
460 const RawArray rawArray(other.m_rawArray.get_allocator());
461 m_rawArray = rawArray;
462 m_rawArray.reserve(other.m_rawArray.size());
463 for (
const auto& value : other.m_rawArray)
465 m_rawArray.emplace_back(
NoInit, value);
478 template <
typename T =
typename RAW_ARRAY::value_type,
479 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
481 Array(std::move(other))
492 template <
typename T =
typename RAW_ARRAY::value_type,
493 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
516 template <
typename T =
typename RAW_ARRAY::value_type,
517 typename std::enable_if<std::is_constructible<T, NoInitT, T>::value,
int>::type = 0>
531 return m_rawArray == other.m_rawArray;
543 return m_rawArray < other.m_rawArray;
582 typename std::enable_if<has_initialize_element<ARRAY_EXPRESSIONS_>::value,
int>::type = 0>
586 for (
auto&& element : m_rawArray)
588 ArrayExpressions::initializeElement(owner, element, index);
602 template <
typename OWNER_TYPE_ =
OwnerType,
603 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
606 return bitSizeOfImpl(detail::DummyArrayOwner(), 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 bitSizeOfImpl(owner, bitPosition);
635 template <
typename OWNER_TYPE_ =
OwnerType,
636 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
639 detail::DummyArrayOwner owner;
640 return initializeOffsetsImpl(owner, bitPosition);
653 template <
typename OWNER_TYPE_ =
OwnerType,
654 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
657 return initializeOffsetsImpl(owner, bitPosition);
668 template <
typename OWNER_TYPE_ =
OwnerType,
669 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
672 detail::DummyArrayOwner owner;
673 readImpl(owner, in, arrayLength);
685 template <
typename OWNER_TYPE_ =
OwnerType,
686 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
689 readImpl(owner, in, arrayLength);
699 template <
typename OWNER_TYPE_ =
OwnerType,
700 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
703 writeImpl(detail::DummyArrayOwner(), out);
714 template <
typename OWNER_TYPE_ =
OwnerType,
715 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
718 writeImpl(owner, out);
730 template <
typename OWNER_TYPE_ =
OwnerType,
731 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
734 return bitSizeOfPackedImpl(detail::DummyArrayOwner(), 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 bitSizeOfPackedImpl(ownerType, bitPosition);
763 template <
typename OWNER_TYPE_ =
OwnerType,
764 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
767 detail::DummyArrayOwner owner;
768 return initializeOffsetsPackedImpl(owner, bitPosition);
781 template <
typename OWNER_TYPE_ =
OwnerType,
782 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
785 return initializeOffsetsPackedImpl(owner, bitPosition);
796 template <
typename OWNER_TYPE_ =
OwnerType,
797 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
800 detail::DummyArrayOwner owner;
801 readPackedImpl(owner, in, arrayLength);
813 template <
typename OWNER_TYPE_ =
OwnerType,
814 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
817 readPackedImpl(owner, in, arrayLength);
827 template <
typename OWNER_TYPE_ =
OwnerType,
828 typename std::enable_if<std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
831 writePackedImpl(detail::DummyArrayOwner(), out);
842 template <
typename OWNER_TYPE_ =
OwnerType,
843 typename std::enable_if<!std::is_same<OWNER_TYPE_, detail::DummyArrayOwner>::value,
int>::type = 0>
846 writePackedImpl(owner, out);
850 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
853 static void addBitSizeOfArrayLength(
size_t&,
size_t)
856 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
859 static void addBitSizeOfArrayLength(
size_t& bitPosition,
size_t arrayLength)
864 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
867 static void alignBitPosition(
size_t&)
870 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
873 static void alignBitPosition(
size_t& bitPosition)
875 bitPosition =
alignTo(8, bitPosition);
878 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
881 static void alignAndCheckOffset(IO&, OWNER_TYPE&,
size_t)
884 template <
typename IO,
typename OWNER_TYPE,
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
887 static void alignAndCheckOffset(IO& io, OWNER_TYPE& owner,
size_t index)
890 detail::checkOffset<ArrayExpressions>(owner, index, io.getBitPosition() / 8);
893 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
896 static void initializeOffset(
OwnerType&,
size_t,
size_t&)
899 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
902 static void initializeOffset(
OwnerType& owner,
size_t index,
size_t& bitPosition)
904 bitPosition =
alignTo(8, bitPosition);
905 detail::initializeOffset<ArrayExpressions>(owner, index, bitPosition / 8);
908 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
912 static size_t readArrayLength(
OwnerType&, BitStreamReader&,
size_t arrayLength)
917 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
920 static size_t readArrayLength(
OwnerType&, BitStreamReader& in,
size_t)
922 return in.readVarSize();
925 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
926 typename std::enable_if<ARRAY_TYPE_ == ArrayType::IMPLICIT, int>::type = 0>
927 static size_t readArrayLength(
OwnerType& owner, BitStreamReader& in,
size_t)
930 "Implicit array elements must have constant bit size!");
932 const size_t remainingBits = in.getBufferBitSize() - in.getBitPosition();
933 return remainingBits / detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
936 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
939 static void writeArrayLength(BitStreamWriter&,
size_t)
942 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
945 static void writeArrayLength(BitStreamWriter& out,
size_t arrayLength)
950 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
953 static size_t constBitSizeOfElements(
size_t,
size_t arrayLength,
size_t elementBitSize)
955 return arrayLength * elementBitSize;
958 template <
ArrayType ARRAY_TYPE_ = ARRAY_TYPE,
961 static size_t constBitSizeOfElements(
size_t bitPosition,
size_t arrayLength,
size_t elementBitSize)
963 size_t endBitPosition =
alignTo(8, bitPosition);
964 endBitPosition += elementBitSize + (arrayLength - 1) *
alignTo(8, elementBitSize);
966 return endBitPosition - bitPosition;
970 typename std::enable_if<ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
971 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
973 size_t endBitPosition = bitPosition;
975 const size_t arrayLength = m_rawArray.size();
976 addBitSizeOfArrayLength(endBitPosition, arrayLength);
980 const size_t elementBitSize = detail::arrayTraitsConstBitSizeOf<ArrayTraits>(owner);
981 endBitPosition += constBitSizeOfElements(endBitPosition, arrayLength, elementBitSize);
984 return endBitPosition - bitPosition;
988 typename std::enable_if<!ARRAY_TRAITS_::IS_BITSIZEOF_CONSTANT, int>::type = 0>
989 size_t bitSizeOfImpl(
const OwnerType& owner,
size_t bitPosition)
const
991 size_t endBitPosition = bitPosition;
993 const size_t arrayLength = m_rawArray.size();
994 addBitSizeOfArrayLength(endBitPosition, arrayLength);
996 for (
size_t index = 0; index < arrayLength; ++index)
998 alignBitPosition(endBitPosition);
1000 detail::arrayTraitsBitSizeOf<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
1003 return endBitPosition - bitPosition;
1006 size_t initializeOffsetsImpl(
OwnerType& owner,
size_t bitPosition)
1008 size_t endBitPosition = bitPosition;
1010 const size_t arrayLength = m_rawArray.size();
1011 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1013 for (
size_t index = 0; index < arrayLength; ++index)
1015 initializeOffset(owner, index, endBitPosition);
1017 detail::arrayTraitsInitializeOffsets<ArrayTraits>(owner, endBitPosition, m_rawArray[index]);
1020 return endBitPosition;
1023 void readImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength)
1025 size_t readLength = readArrayLength(owner, in, arrayLength);
1028 m_rawArray.reserve(readLength);
1029 for (
size_t index = 0; index < readLength; ++index)
1031 alignAndCheckOffset(in, owner, index);
1032 detail::arrayTraitsRead<ArrayTraits>(owner, m_rawArray, in, index);
1036 void writeImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1038 const size_t arrayLength = m_rawArray.size();
1039 writeArrayLength(out, arrayLength);
1041 for (
size_t index = 0; index < arrayLength; ++index)
1043 alignAndCheckOffset(out, owner, index);
1044 detail::arrayTraitsWrite<ArrayTraits>(owner, out, m_rawArray[index]);
1048 using PackingContext =
typename detail::packing_context_type<typename RawArray::value_type>::type;
1050 size_t bitSizeOfPackedImpl(
const OwnerType& owner,
size_t bitPosition)
const
1054 size_t endBitPosition = bitPosition;
1056 const size_t arrayLength = m_rawArray.size();
1057 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1059 if (arrayLength > 0)
1061 PackingContext context;
1063 for (
size_t index = 0; index < arrayLength; ++index)
1065 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1066 owner, context, m_rawArray[index]);
1069 for (
size_t index = 0; index < arrayLength; ++index)
1071 alignBitPosition(endBitPosition);
1072 endBitPosition += detail::packedArrayTraitsBitSizeOf<PackedArrayTraits<ArrayTraits>>(
1073 owner, context, endBitPosition, m_rawArray[index]);
1077 return endBitPosition - bitPosition;
1080 size_t initializeOffsetsPackedImpl(
OwnerType& owner,
size_t bitPosition)
1084 size_t endBitPosition = bitPosition;
1086 const size_t arrayLength = m_rawArray.size();
1087 addBitSizeOfArrayLength(endBitPosition, arrayLength);
1089 if (arrayLength > 0)
1091 PackingContext context;
1093 for (
size_t index = 0; index < arrayLength; ++index)
1095 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1096 owner, context, m_rawArray[index]);
1099 for (
size_t index = 0; index < arrayLength; ++index)
1101 initializeOffset(owner, index, endBitPosition);
1102 endBitPosition = detail::packedArrayTraitsInitializeOffsets<PackedArrayTraits<ArrayTraits>>(
1103 owner, context, endBitPosition, m_rawArray[index]);
1107 return endBitPosition;
1110 void readPackedImpl(
OwnerType& owner, BitStreamReader& in,
size_t arrayLength = 0)
1114 size_t readLength = readArrayLength(owner, in, arrayLength);
1120 m_rawArray.reserve(readLength);
1122 PackingContext context;
1124 for (
size_t index = 0; index < readLength; ++index)
1126 alignAndCheckOffset(in, owner, index);
1127 detail::packedArrayTraitsRead<PackedArrayTraits<ArrayTraits>>(
1128 owner, m_rawArray, context, in, index);
1133 void writePackedImpl(
const OwnerType& owner, BitStreamWriter& out)
const
1137 const size_t arrayLength = m_rawArray.size();
1138 writeArrayLength(out, arrayLength);
1140 if (arrayLength > 0)
1142 PackingContext context;
1144 for (
size_t index = 0; index < arrayLength; ++index)
1146 detail::packedArrayTraitsInitContext<PackedArrayTraits<ArrayTraits>>(
1147 owner, context, m_rawArray[index]);
1150 for (
size_t index = 0; index < arrayLength; ++index)
1152 alignAndCheckOffset(out, owner, index);
1153 detail::packedArrayTraitsWrite<PackedArrayTraits<ArrayTraits>>(
1154 owner, context, out, m_rawArray[index]);
1166 template <
typename ARRAY,
typename RAW_ARRAY>
1169 return ARRAY(std::forward<RAW_ARRAY>(rawArray));
1175 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)