8#ifndef vtkDataArrayValueRange_Generic_h
9#define vtkDataArrayValueRange_Generic_h
25VTK_ABI_NAMESPACE_BEGIN
28template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
30template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
32template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
34template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
36template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
47template <ComponentIdType TupleSize>
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),
186 this->ValueId += offset;
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);
219template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
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>)
286 return this->
Array->GetComponent(this->
Id.GetTupleId(), this->Id.GetComponentId());
288 else if constexpr (TupleSize == 1)
290 return this->
Array->GetValue(this->
Id.GetValueId());
294 return this->
Array->GetTypedComponent(this->
Id.GetTupleId(), this->Id.GetComponentId());
304template <
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>)
381 return this->
Array->GetComponent(this->
Id.GetTupleId(), this->Id.GetComponentId());
383 else if constexpr (TupleSize == 1)
385 return this->
Array->GetValue(this->
Id.GetValueId());
389 return this->
Array->GetTypedComponent(this->
Id.GetTupleId(), this->Id.GetComponentId());
397 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
399 this->
Array->SetComponent(this->
Id.GetTupleId(), this->Id.GetComponentId(), val);
401 else if constexpr (TupleSize == 1)
403 this->
Array->SetValue(this->
Id.GetValueId(), val);
407 this->
Array->SetTypedComponent(this->
Id.GetTupleId(), this->Id.GetComponentId(), val);
414 APIType tmp =
static_cast<APIType
>(lhs);
415 lhs =
static_cast<APIType
>(rhs);
416 rhs = std::move(tmp);
419 template <
typename OArray, ComponentIdType OSize>
426 std::is_same<APIType, OAPIType>::value,
"Cannot swap components with different types.");
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; \
505#undef VTK_REF_OP_OVERLOADS
507 friend struct ConstValueReference<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
508 friend struct ValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
513 this->
Array = o.Array;
523template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
552 this->Id.DebugAsserts(this->Array);
558 : Array{ o.GetArray() }
572 this->Id.DebugAsserts(this->Array);
579 auto ret = this->Id++;
580 this->Id.DebugAsserts(this->Array);
588 this->Id.DebugAsserts(this->Array);
595 auto ret = this->Id--;
596 this->Id.DebugAsserts(this->Array);
603 return reference{ this->Array, this->Id + i };
611#define VTK_TMP_MAKE_OPERATOR(OP) \
612 friend VTK_ITER_INLINE bool operator OP( \
613 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
615 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
616 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
626#undef VTK_TMP_MAKE_OPERATOR
631 this->Id.AddOffset(offset);
632 this->Id.DebugAsserts(this->Array);
651 this->Id.AddOffset(-offset);
652 this->Id.DebugAsserts(this->Array);
665 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
666 return it1.Id.GetValueId() - it2.Id.GetValueId();
672 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
675 swap(lhs.Id, rhs.Id);
679 mutable ArrayType* Array;
685template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
718 this->
Ref.CopyReference(o.Ref);
734 auto ret = this->
Ref.Id++;
750 auto ret = this->
Ref.Id--;
767#define VTK_TMP_MAKE_OPERATOR(OP) \
768 friend VTK_ITER_INLINE bool operator OP( \
769 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
772 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
773 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
783#undef VTK_TMP_MAKE_OPERATOR
788 this->
Ref.Id.AddOffset(offset);
808 this->
Ref.Id.AddOffset(-offset);
809 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
816 return ValueIterator{ it.GetArray(), it.GetId() + (-offset) };
823 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
824 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
831 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
834 swap(lhs.GetId(), rhs.GetId());
837 friend struct ConstValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
846 IdStorageType&
GetId() noexcept {
return this->
Ref.Id; }
847 const IdStorageType&
GetId() const noexcept {
return this->
Ref.Id; }
854template <
typename ArrayTypeT, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
892 , BeginValue(beginValue, this->NumComps)
893 , EndValue(endValue, this->NumComps)
896 assert(beginValue >= 0 && beginValue <= endValue);
897 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
903 const ValueIdType realBegin = this->BeginValue.GetValueId() + beginValue;
905 endValue >= 0 ? this->BeginValue.GetValueId() + endValue : this->EndValue.GetValueId();
907 return ValueRange{ this->Array, realBegin, realEnd };
924 return this->EndValue.GetValueId() - this->BeginValue.GetValueId();
930 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
945 return reference{ this->Array, this->BeginValue + i };
965 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
971 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
977 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
986 NumCompsType NumComps{};
987 IdStorageType BeginValue{};
988 IdStorageType EndValue{};
992template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
Abstract superclass for all arrays.
ValueRange< AOSArrayType, TupleSize, ForceValueTypeForVtkDataArray > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
typename detail::GetAPITypeImpl< ArrayType, ForceValueTypeForVtkDataArray >::APIType GetAPIType
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) noexcept
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE ConstValueIterator(const ValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o) noexcept
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator-(const ConstValueIterator &it, difference_type offset) noexcept
std::random_access_iterator_tag iterator_category
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
friend VTK_ITER_INLINE difference_type operator-(const ConstValueIterator &it1, const ConstValueIterator &it2) noexcept
VTK_ITER_INLINE ConstValueIterator operator--(int) noexcept
VTK_ITER_INLINE ConstValueIterator & operator-=(difference_type offset) noexcept
ConstValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > reference
friend VTK_ITER_INLINE ConstValueIterator operator+(const ConstValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ConstValueIterator & operator--() noexcept
VTK_ITER_INLINE ConstValueIterator & operator++() noexcept
VTK_ITER_INLINE ConstValueIterator(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
ValueIdType difference_type
VTK_ITER_INLINE ConstValueIterator(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueIterator() noexcept
VTK_ITER_INLINE ConstValueIterator & operator+=(difference_type offset) noexcept
friend VTK_ITER_INLINE ConstValueIterator operator+(difference_type offset, const ConstValueIterator &it) noexcept
VTK_ITER_INLINE ConstValueReference() noexcept
VTK_ITER_INLINE ConstValueReference(const ConstValueReference &o) noexcept=default
VTK_ITER_INLINE ConstValueReference(const ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o)
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueReference(ConstValueReference &&o) noexcept=default
VTK_ITER_INLINE ConstValueReference operator=(const ConstValueReference &o) noexcept
VTK_ITER_INLINE ConstValueReference operator=(ConstValueReference &&o) noexcept
GenericTupleSize< TupleSize > NumCompsType
VTK_ITER_INLINE ComponentIdType GetComponentId() const noexcept
VTK_ITER_INLINE IdStorage operator--(int) noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, NumCompsType numComps) noexcept
VTK_ITER_INLINE IdStorage & operator++() noexcept
VTK_ITER_INLINE std::pair< TupleIdType, ComponentIdType > Convert(ValueIdType value) const noexcept
VTK_ITER_INLINE void DebugAsserts(ArrayType *array) const noexcept
VTK_ITER_INLINE void AddOffset(ValueIdType offset) noexcept
VTK_ITER_INLINE IdStorage operator++(int) noexcept
VTK_ITER_INLINE IdStorage & operator--() noexcept
VTK_ITER_INLINE IdStorage() noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
friend VTK_ITER_INLINE void swap(IdStorage &lhs, IdStorage &rhs) noexcept
friend VTK_ITER_INLINE IdStorage operator+(const IdStorage &id, ValueIdType offset) noexcept
VTK_ITER_INLINE ValueIdType GetValueId() const noexcept
VTK_ITER_INLINE IdStorage(TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
VTK_ITER_INLINE ValueIdType Convert(TupleIdType tuple, ComponentIdType comp) const noexcept
VTK_ITER_INLINE TupleIdType GetTupleId() const noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, TupleIdType tupleId, ComponentIdType comp, NumCompsType numComps) noexcept
static constexpr bool value
friend VTK_ITER_INLINE ValueIterator operator+(const ValueIterator &it, difference_type offset) noexcept
IdStorageType & GetId() noexcept
VTK_ITER_INLINE ValueIterator & operator++() noexcept
VTK_ITER_INLINE reference operator*() const noexcept
std::random_access_iterator_tag iterator_category
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > reference
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator operator--(int) noexcept
VTK_ITER_INLINE ValueIterator & operator=(const ValueIterator &o) noexcept
VTK_ITER_INLINE void DebugIdAsserts() const
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > Ref
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > pointer
VTK_ITER_INLINE ValueIterator & operator--() noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > value_type
ValueIdType difference_type
VTK_ITER_INLINE ValueIterator() noexcept=default
friend VTK_ITER_INLINE ValueIterator operator-(const ValueIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE ValueIterator operator++(int) noexcept
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) noexcept
ArrayType * GetArray() const noexcept
friend VTK_ITER_INLINE void swap(ValueIterator &lhs, ValueIterator &rhs) noexcept
VTK_ITER_INLINE const pointer & operator->() const noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
const IdStorageType & GetId() const noexcept
friend VTK_ITER_INLINE difference_type operator-(const ValueIterator &it1, const ValueIterator &it2) noexcept
VTK_ITER_INLINE ValueIterator(const ValueIterator &o) noexcept=default
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
static constexpr ComponentIdType TupleSizeTag
GetAPIType< ArrayType, ForceValueTypeForVtkDataArray > ValueType
value_type * data() noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
VTK_ITER_INLINE iterator begin() noexcept
VTK_ITER_INLINE const_iterator end() const noexcept
ConstIteratorType const_iterator
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
VTK_ITER_INLINE ValueRange() noexcept=default
VTK_ITER_INLINE size_type size() const noexcept
ConstReferenceType const_reference
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ReferenceType
ConstValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ConstReferenceType
VTK_ITER_INLINE iterator end() noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
ConstValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ConstIteratorType
ValueIterator< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > IteratorType
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
VTK_ITER_INLINE ValueReference operator=(APIType val) noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > &o) noexcept
void CopyReference(const ValueReference &o) noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference &o) noexcept
VTK_ITER_INLINE ValueReference(const ValueReference &o) noexcept=default
friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType &rhs) noexcept
VTK_ITER_INLINE ValueReference() noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference< OArray, OSize, ForceValueTypeForVtkDataArray > rhs) noexcept
friend VTK_ITER_INLINE void swap(APIType &lhs, ValueReference rhs) noexcept
VTK_ITER_INLINE APIType operator++(int) noexcept
VTK_ITER_INLINE ValueReference(ValueReference &&o) noexcept=default
VTK_ITER_INLINE ValueReference(ArrayType *array, IdStorageType id) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) noexcept
#define VTK_TMP_MAKE_OPERATOR(OP)
#define VTK_REF_OP_OVERLOADS(Op, ImplOp)
#define VTK_DEPRECATED_IN_9_6_0(reason)