8 #ifndef vtkDataArrayValueRange_Generic_h
9 #define vtkDataArrayValueRange_Generic_h
17 #include <type_traits>
25 VTK_ABI_NAMESPACE_BEGIN
28 template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
30 template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
32 template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
34 template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
36 template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
47 template <ComponentIdType TupleSize>
63 , TupleId(static_cast<TupleIdType>(valueId) / static_cast<TupleIdType>(numComps.value))
64 , ComponentId(static_cast<ComponentIdType>(valueId % static_cast<ValueIdType>(numComps.value)))
71 : ValueId(tupleId * numComps.value + comp)
88 template <
typename ArrayType>
94 "Inconsistent internal state in IdStorage.");
97 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(),
"Invalid value id.");
103 this->
GetTupleId() == array->GetNumberOfTuples())),
104 "Invalid component id.");
106 "Invalid value id.");
116 this->ComponentId = 0;
125 auto v = this->ValueId++;
126 auto t = this->TupleId;
127 auto c = this->ComponentId++;
130 this->ComponentId = 0;
133 return IdStorage{ v, t, c, this->NumComps };
148 if (this->ComponentId < 0)
159 auto v = this->ValueId--;
160 auto t = this->TupleId;
161 auto c = this->ComponentId--;
162 if (this->ComponentId < 0)
167 return IdStorage{ v, t, c, this->NumComps };
173 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
179 return std::make_pair(static_cast<TupleIdType>(
value / this->NumComps.value),
180 static_cast<ComponentIdType>(
value % this->NumComps.value));
187 std::tie(this->TupleId, this->ComponentId) = this->
Convert(this->ValueId);
205 swap(lhs.ValueId, rhs.ValueId);
206 swap(lhs.TupleId, rhs.TupleId);
207 swap(lhs.ComponentId, rhs.ComponentId);
219 template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
220 struct ConstValueReference
226 using IdStorageType = IdStorage<TupleSize>;
265 this->
Array = o.Array;
275 this->
Array = std::move(o.Array);
276 this->
Id = std::move(o.Id);
284 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
288 else if constexpr (TupleSize == 1)
304 template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
342 return *
this =
static_cast<APIType
>(o);
346 this->
Array = o.Array;
357 return *
this =
static_cast<APIType
>(o);
361 this->
Array = std::move(o.Array);
362 this->
Id = std::move(o.Id);
367 template <
typename OArray, ComponentIdType OSize>
371 const APIType tmp = o;
372 return *
this = std::move(tmp);
379 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
383 else if constexpr (TupleSize == 1)
397 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
401 else if constexpr (TupleSize == 1)
414 APIType tmp =
static_cast<APIType
>(lhs);
415 lhs =
static_cast<APIType
>(rhs);
416 rhs = std::move(tmp);
419 template <
typename OArray, ComponentIdType OSize>
428 APIType tmp =
static_cast<APIType
>(lhs);
429 lhs =
static_cast<APIType
>(rhs);
430 rhs = std::move(tmp);
435 APIType tmp =
static_cast<APIType
>(lhs);
436 lhs = std::move(rhs);
437 rhs = std::move(tmp);
442 APIType tmp = std::move(lhs);
443 lhs =
static_cast<APIType
>(rhs);
444 rhs = std::move(tmp);
450 const APIType newVal = *
this + 1;
458 const APIType retVal = *
this;
466 const APIType newVal = *
this - 1;
474 const APIType retVal = *
this;
479 #define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
480 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
482 const APIType newVal = lhs ImplOp val; \
486 friend VTK_ITER_INLINE ValueReference operator Op( \
487 ValueReference lhs, ValueReference val) noexcept \
489 const APIType newVal = lhs ImplOp val; \
493 friend VTK_ITER_INLINE APIType& operator Op(APIType & lhs, ValueReference val) noexcept \
495 const APIType newVal = lhs ImplOp val; \
508 #undef VTK_REF_OP_OVERLOADS
511 friend struct ValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
516 this->
Array = o.Array;
526 template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
561 : Array{ o.GetArray() }
582 auto ret = this->Id++;
598 auto ret = this->Id--;
606 return reference{ this->Array, this->Id + i };
614 #define VTK_TMP_MAKE_OPERATOR(OP) \
615 friend VTK_ITER_INLINE bool operator OP( \
616 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
618 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
619 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
629 #undef VTK_TMP_MAKE_OPERATOR
668 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
669 return it1.Id.GetValueId() - it2.Id.GetValueId();
675 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
678 swap(lhs.Id, rhs.Id);
682 mutable ArrayType* Array;
688 template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
696 using IdStorageType = IdStorage<TupleSize>;
712 this->DebugIdAsserts();
716 ValueIterator(
const ValueIterator& o) noexcept =
default;
721 this->Ref.CopyReference(o.Ref);
722 this->DebugIdAsserts();
730 this->DebugIdAsserts();
737 auto ret = this->Ref.Id++;
738 this->DebugIdAsserts();
746 this->DebugIdAsserts();
753 auto ret = this->Ref.Id--;
754 this->DebugIdAsserts();
770 #define VTK_TMP_MAKE_OPERATOR(OP) \
771 friend VTK_ITER_INLINE bool operator OP( \
772 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
775 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
776 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
786 #undef VTK_TMP_MAKE_OPERATOR
791 this->Ref.Id.AddOffset(
offset);
792 this->DebugIdAsserts();
811 this->Ref.Id.AddOffset(-
offset);
812 this->Ref.Id.DebugAsserts(this->Ref.Array);
826 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
827 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
834 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
837 swap(lhs.GetId(), rhs.GetId());
848 ArrayType*
GetArray() const noexcept {
return this->Ref.Array; }
857 template <
typename ArrayTypeT, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
895 , BeginValue(beginValue, this->NumComps)
896 , EndValue(endValue, this->NumComps)
899 assert(beginValue >= 0 && beginValue <= endValue);
900 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
903 assert(arr->GetNumberOfComponents() == TupleSize);
910 const ValueIdType realBegin = this->BeginValue.GetValueId() + beginValue;
912 endValue >= 0 ? this->BeginValue.GetValueId() + endValue : this->EndValue.GetValueId();
914 return ValueRange{ this->Array, realBegin, realEnd };
931 return this->EndValue.GetValueId() - this->BeginValue.GetValueId();
937 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
952 return reference{ this->Array, this->BeginValue + i };
972 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
978 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
984 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
987 const_iterator NewConstIterator(IdStorageType
id)
const noexcept
989 return const_iterator{ this->Array,
id };
992 mutable ArrayType* Array{
nullptr };
993 NumCompsType NumComps{};
994 IdStorageType BeginValue{};
995 IdStorageType EndValue{};
999 template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
1003 VTK_ABI_NAMESPACE_END
1009 #endif // vtkDataArrayValueRange_Generic_h
friend VTK_ITER_INLINE void swap(IdStorage &lhs, IdStorage &rhs) noexcept
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
IdStorageType & GetId() noexcept
VTK_ITER_INLINE ValueIterator operator++(int) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > rhs) noexcept
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) noexcept
VTK_ITER_INLINE ValueReference operator=(APIType val) noexcept
VTK_ITER_INLINE ConstValueIterator(const ValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o) noexcept
VTK_ITER_INLINE ValueIdType GetValueId() const noexcept
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ValueIterator & operator++() noexcept
VTK_ITER_INLINE const pointer & operator->() const noexcept
friend VTK_ITER_INLINE IdStorage operator+(const IdStorage &id, ValueIdType offset) noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
VTK_ITER_INLINE ConstValueIterator() noexcept
VTK_ITER_INLINE ConstValueReference(const ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o)
Abstract superclass for all arrays.
typename detail::GetAPITypeImpl< ArrayType, ForceValueTypeForVtkDataArray >::APIType GetAPIType
VTK_ITER_INLINE IdStorage(ValueIdType valueId, NumCompsType numComps) noexcept
#define VTK_REF_OP_OVERLOADS(Op, ImplOp)
VTK_ITER_INLINE ValueIterator & operator=(const ValueIterator &o) noexcept
VTK_ITER_INLINE ConstValueIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE reference operator*() const noexcept
ArrayType * GetArray() const noexcept
ValueIdType difference_type
VTK_ITER_INLINE IdStorage operator++(int) noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
GenericTupleSize< TupleSize > NumCompsType
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
VTK_ITER_INLINE ConstValueReference operator=(ConstValueReference &&o) noexcept
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
std::random_access_iterator_tag iterator_category
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > ValueType
friend VTK_ITER_INLINE difference_type operator-(const ConstValueIterator &it1, const ConstValueIterator &it2) noexcept
VTK_ITER_INLINE IdStorage() noexcept
VTK_ITER_INLINE APIType operator++(int) noexcept
VTK_ITER_INLINE IdStorage & operator++() noexcept
VTK_ITER_INLINE ConstValueIterator & operator++() noexcept
VTK_ITER_INLINE TupleIdType GetTupleId() const noexcept
std::random_access_iterator_tag iterator_category
ValueRange< AOSArrayType, TupleSize, ForceValueTypeForVtkDataArray > DeclareValueRangeSpecialization(ArrayType *)
VTK_ITER_INLINE void AddOffset(ValueIdType offset) noexcept
void CopyReference(const ValueReference &o) noexcept
VTK_ITER_INLINE std::pair< TupleIdType, ComponentIdType > Convert(ValueIdType value) const noexcept
VTK_ITER_INLINE IdStorage & operator--() noexcept
#define VTK_DEPRECATED_IN_9_6_0(reason)
ValueIdType difference_type
friend VTK_ITER_INLINE void swap(APIType &lhs, ValueReference rhs) noexcept
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ValueReference operator=(const ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > &o) noexcept
VTK_ITER_INLINE IdStorage(TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
VTK_ITER_INLINE ComponentIdType GetComponentId() const noexcept
VTK_ITER_INLINE ValueReference() noexcept
VTK_ITER_INLINE ValueIdType Convert(TupleIdType tuple, ComponentIdType comp) const noexcept
VTK_ITER_INLINE APIType operator--(int) noexcept
friend VTK_ITER_INLINE difference_type operator-(const ValueIterator &it1, const ValueIterator &it2) noexcept
#define VTK_TMP_MAKE_OPERATOR(OP)
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
friend VTK_ITER_INLINE ConstValueIterator operator-(const ConstValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE ConstValueIterator & operator+=(difference_type offset) noexcept
friend VTK_ITER_INLINE void swap(ValueIterator &lhs, ValueIterator &rhs) noexcept
VTK_ITER_INLINE void DebugIdAsserts() const
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) noexcept
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > Ref
VTK_ITER_INLINE iterator end() noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType &rhs) noexcept
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE ConstValueIterator(ArrayType *array, IdStorageType id) noexcept
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
VTK_ITER_INLINE const_iterator begin() const noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
friend VTK_ITER_INLINE ValueIterator operator-(const ValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ConstValueReference() noexcept
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > value_type
VTK_ITER_INLINE iterator begin() noexcept
VTK_ITER_INLINE ValueReference(ArrayType *array, IdStorageType id) noexcept
const IdStorageType & GetId() const noexcept
VTK_ITER_INLINE const_iterator end() const 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 ValueIterator & operator--() noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE void DebugAsserts(ArrayType *array) const noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
VTK_ITER_INLINE ConstValueIterator operator--(int) noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
VTK_ITER_INLINE ConstValueIterator & operator--() noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE IdStorage operator--(int) noexcept
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) noexcept