20 #ifndef vtkDataArrayValueRange_Generic_h
21 #define vtkDataArrayValueRange_Generic_h
30 #include <type_traits>
41 template <
typename ArrayType, ComponentIdType>
43 template <
typename ArrayType, ComponentIdType>
45 template <
typename ArrayType, ComponentIdType>
47 template <
typename ArrayType, ComponentIdType>
49 template <
typename ArrayType, ComponentIdType>
60 template <ComponentIdType TupleSize>
76 , TupleId(static_cast<TupleIdType>(valueId) / static_cast<TupleIdType>(numComps.value))
77 , ComponentId(static_cast<ComponentIdType>(valueId % static_cast<ValueIdType>(numComps.value)))
84 : ValueId(tupleId * numComps.value + comp)
101 template <
typename ArrayType>
107 "Inconsistent internal state in IdStorage.");
110 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(),
"Invalid value id.");
112 "Invalid tuple id.");
116 this->
GetTupleId() == array->GetNumberOfTuples())),
117 "Invalid component id.");
119 "Invalid value id.");
129 this->ComponentId = 0;
138 auto v = this->ValueId++;
139 auto t = this->TupleId;
140 auto c = this->ComponentId++;
143 this->ComponentId = 0;
146 return IdStorage{ v, t, c, this->NumComps };
161 if (this->ComponentId < 0)
172 auto v = this->ValueId--;
173 auto t = this->TupleId;
174 auto c = this->ComponentId--;
175 if (this->ComponentId < 0)
180 return IdStorage{ v, t, c, this->NumComps };
186 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
192 return std::make_pair(static_cast<TupleIdType>(
value / this->NumComps.value),
193 static_cast<ComponentIdType>(
value % this->NumComps.value));
200 std::tie(this->TupleId, this->ComponentId) = this->
Convert(this->ValueId);
218 swap(lhs.ValueId, rhs.ValueId);
219 swap(lhs.TupleId, rhs.TupleId);
220 swap(lhs.ComponentId, rhs.ComponentId);
232 template <
typename ArrayType, ComponentIdType TupleSize>
233 struct ConstValueReference
239 using IdStorageType = IdStorage<TupleSize>;
278 this->
Array = o.Array;
288 this->
Array = std::move(o.Array);
289 this->
Id = std::move(o.Id);
294 operator APIType() const noexcept
309 template <
typename ArrayType, ComponentIdType TupleSize>
347 return *
this =
static_cast<APIType
>(o);
351 this->
Array = o.Array;
362 return *
this =
static_cast<APIType
>(o);
366 this->
Array = std::move(o.Array);
367 this->
Id = std::move(o.Id);
372 template <
typename OArray, ComponentIdType OSize>
375 const APIType tmp = o;
376 return *
this = std::move(tmp);
380 operator APIType() const noexcept
400 APIType tmp = std::move(static_cast<APIType>(lhs));
401 lhs = std::move(static_cast<APIType>(rhs));
402 rhs = std::move(tmp);
405 template <
typename OArray, ComponentIdType OSize>
412 APIType tmp = std::move(static_cast<APIType>(lhs));
413 lhs = std::move(static_cast<APIType>(rhs));
414 rhs = std::move(tmp);
419 APIType tmp = std::move(static_cast<APIType>(lhs));
420 lhs = std::move(rhs);
421 rhs = std::move(tmp);
426 APIType tmp = std::move(lhs);
427 lhs = std::move(static_cast<APIType>(rhs));
428 rhs = std::move(tmp);
434 const APIType newVal = *
this + 1;
442 const APIType retVal = *
this;
450 const APIType newVal = *
this - 1;
458 const APIType retVal = *
this;
463 #define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
464 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
466 const APIType newVal = lhs ImplOp val; \
470 friend VTK_ITER_INLINE ValueReference operator Op( \
471 ValueReference lhs, ValueReference val) noexcept \
473 const APIType newVal = lhs ImplOp val; \
477 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
479 const APIType newVal = lhs ImplOp val; \
489 #undef VTK_REF_OP_OVERLOADS
497 this->
Array = o.Array;
507 template <
typename ArrayType, ComponentIdType TupleSize>
541 : Array{ o.GetArray() }
562 auto ret = this->Id++;
578 auto ret = this->Id--;
586 return reference{ this->Array, this->Id + i };
594 #define VTK_TMP_MAKE_OPERATOR(OP) \
595 friend VTK_ITER_INLINE bool operator OP( \
596 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
598 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
599 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
609 #undef VTK_TMP_MAKE_OPERATOR
648 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
649 return it1.Id.GetValueId() - it2.Id.GetValueId();
655 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
658 swap(lhs.Id, rhs.Id);
662 mutable ArrayType* Array;
668 template <
typename ArrayType, ComponentIdType TupleSize>
676 using IdStorageType = IdStorage<TupleSize>;
692 this->DebugIdAsserts();
696 ValueIterator(
const ValueIterator& o) noexcept =
default;
701 this->Ref.CopyReference(o.Ref);
702 this->DebugIdAsserts();
710 this->DebugIdAsserts();
717 auto ret = this->Ref.Id++;
718 this->DebugIdAsserts();
726 this->DebugIdAsserts();
733 auto ret = this->Ref.Id--;
734 this->DebugIdAsserts();
750 #define VTK_TMP_MAKE_OPERATOR(OP) \
751 friend VTK_ITER_INLINE bool operator OP( \
752 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
755 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
756 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
766 #undef VTK_TMP_MAKE_OPERATOR
771 this->Ref.Id.AddOffset(
offset);
772 this->DebugIdAsserts();
791 this->Ref.Id.AddOffset(-
offset);
792 this->Ref.Id.DebugAsserts(this->Ref.Array);
806 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
807 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
814 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
817 swap(lhs.GetId(), rhs.GetId());
828 ArrayType*
GetArray() const noexcept {
return this->Ref.Array; }
837 template <
typename ArrayTypeT, ComponentIdType TupleSize>
874 , BeginValue(beginValue, this->NumComps)
875 , EndValue(endValue, this->NumComps)
878 assert(beginValue >= 0 && beginValue <= endValue);
879 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
885 const ValueIdType realBegin = this->BeginValue.GetValueId() + beginValue;
887 endValue >= 0 ? this->BeginValue.GetValueId() + endValue : this->EndValue.GetValueId();
889 return ValueRange{ this->Array, realBegin, realEnd };
906 return this->EndValue.GetValueId() - this->BeginValue.GetValueId();
912 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
927 return reference{ this->Array, this->BeginValue + i };
937 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
940 const_iterator NewConstIterator(IdStorageType
id)
const noexcept
942 return const_iterator{ this->Array,
id };
945 mutable ArrayType* Array{
nullptr };
946 NumCompsType NumComps{};
947 IdStorageType BeginValue{};
948 IdStorageType EndValue{};
952 template <
typename ArrayType, ComponentIdType TupleSize>
960 #endif // vtkDataArrayValueRange_Generic_h
friend VTK_ITER_INLINE void swap(IdStorage &lhs, IdStorage &rhs) noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) noexcept
VTK_ITER_INLINE ConstValueIterator(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE iterator end() noexcept
VTK_ITER_INLINE ValueIdType GetValueId() const noexcept
VTK_ITER_INLINE ValueReference() noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
friend VTK_ITER_INLINE IdStorage operator+(const IdStorage &id, ValueIdType offset) noexcept
VTK_ITER_INLINE APIType operator--(int) noexcept
IdStorageType & GetId() noexcept
VTK_ITER_INLINE ValueIterator & operator++() noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, NumCompsType numComps) noexcept
VTK_ITER_INLINE const_iterator end() const noexcept
VTK_ITER_INLINE ConstValueIterator & operator-=(difference_type offset) noexcept
#define VTK_REF_OP_OVERLOADS(Op, ImplOp)
VTK_ITER_INLINE ValueReference operator=(const ValueReference< OArray, OSize > &o) noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE const pointer & operator->() const noexcept
GetAPIType< ArrayTypeT > ValueType
VTK_ITER_INLINE IdStorage operator++(int) noexcept
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
GenericTupleSize< TupleSize > NumCompsType
VTK_ITER_INLINE ValueReference operator=(APIType val) noexcept
VTK_ITER_INLINE ValueIterator operator--(int) noexcept
std::random_access_iterator_tag iterator_category
VTK_ITER_INLINE ConstValueIterator & operator+=(difference_type offset) noexcept
VTK_ITER_INLINE iterator begin() noexcept
friend VTK_ITER_INLINE difference_type operator-(const ConstValueIterator &it1, const ConstValueIterator &it2) noexcept
VTK_ITER_INLINE IdStorage() noexcept
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
VTK_ITER_INLINE IdStorage & operator++() noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE TupleIdType GetTupleId() const noexcept
VTK_ITER_INLINE void AddOffset(ValueIdType offset) noexcept
GetAPIType< ArrayType > value_type
VTK_ITER_INLINE std::pair< TupleIdType, ComponentIdType > Convert(ValueIdType value) const noexcept
VTK_ITER_INLINE IdStorage & operator--() noexcept
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference< OArray, OSize > rhs) noexcept
void CopyReference(const ValueReference &o) noexcept
ValueReference< ArrayType, TupleSize > Ref
friend VTK_ITER_INLINE void swap(APIType &lhs, ValueReference rhs) noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
ValueIdType difference_type
VTK_ITER_INLINE IdStorage(TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
VTK_ITER_INLINE ConstValueIterator() noexcept
VTK_ITER_INLINE ComponentIdType GetComponentId() const noexcept
abstract superclass for arrays of numeric data
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
VTK_ITER_INLINE ValueIdType Convert(TupleIdType tuple, ComponentIdType comp) const noexcept
std::random_access_iterator_tag iterator_category
friend VTK_ITER_INLINE difference_type operator-(const ValueIterator &it1, const ValueIterator &it2) noexcept
#define VTK_TMP_MAKE_OPERATOR(OP)
friend VTK_ITER_INLINE ConstValueIterator operator-(const ConstValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ConstValueIterator & operator--() noexcept
VTK_ITER_INLINE ConstValueIterator(const ValueIterator< ArrayType, TupleSize > &o) noexcept
friend VTK_ITER_INLINE void swap(ValueIterator &lhs, ValueIterator &rhs) noexcept
ValueIdType difference_type
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator & operator=(const ValueIterator &o) noexcept
VTK_ITER_INLINE ConstValueIterator operator--(int) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType &rhs) noexcept
VTK_ITER_INLINE ConstValueReference operator=(ConstValueReference &&o) noexcept
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE ConstValueReference() noexcept
VTK_ITER_INLINE void DebugIdAsserts() const
VTK_ITER_INLINE ValueIterator operator++(int) noexcept
friend VTK_ITER_INLINE ValueIterator operator+(const ValueIterator &it, difference_type offset) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator+(difference_type offset, const ConstValueIterator &it) noexcept
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
friend VTK_ITER_INLINE ValueIterator operator-(const ValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ConstValueReference(const ValueReference< ArrayType, TupleSize > &o)
const IdStorageType & GetId() const noexcept
VTK_ITER_INLINE ValueIterator & operator--() noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
VTK_ITER_INLINE APIType operator++(int) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator+(const ConstValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
VTK_ITER_INLINE ValueReference(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueIterator & operator++() noexcept
Efficient templated access to vtkDataArray.
VTK_ITER_INLINE void DebugAsserts(ArrayType *array) const noexcept
VTK_ITER_INLINE IdStorage operator--(int) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) noexcept