8#ifndef vtkDataArrayValueRange_Generic_h
9#define vtkDataArrayValueRange_Generic_h
26VTK_ABI_NAMESPACE_BEGIN
29template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
31template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
32struct ConstValueReference;
33template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
35template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
36struct ConstValueIterator;
37template <
typename ArrayType, ComponentIdType,
typename ForceValueTypeForVtkDataArray>
48template <ComponentIdType TupleSize>
72 : ValueId(tupleId * numComps.value + comp)
89 template <
typename ArrayType>
95 "Inconsistent internal state in IdStorage.");
98 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(),
"Invalid value id.");
100 "Invalid tuple id.");
104 this->
GetTupleId() == array->GetNumberOfTuples())),
105 "Invalid component id.");
107 "Invalid value id.");
117 this->ComponentId = 0;
126 auto v = this->ValueId++;
127 auto t = this->TupleId;
128 auto c = this->ComponentId++;
131 this->ComponentId = 0;
134 return IdStorage{ v, t, c, this->NumComps };
149 if (this->ComponentId < 0)
160 auto v = this->ValueId--;
161 auto t = this->TupleId;
162 auto c = this->ComponentId--;
163 if (this->ComponentId < 0)
168 return IdStorage{ v, t, c, this->NumComps };
174 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
180 return std::make_pair(
static_cast<TupleIdType>(value / this->NumComps.value),
187 this->ValueId += offset;
188 std::tie(this->TupleId, this->ComponentId) = this->
Convert(this->ValueId);
206 swap(lhs.ValueId, rhs.ValueId);
207 swap(lhs.TupleId, rhs.TupleId);
208 swap(lhs.ComponentId, rhs.ComponentId);
220template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
266 this->
Array = o.Array;
276 this->
Array = std::move(o.Array);
277 this->
Id = std::move(o.Id);
285 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
289 else if constexpr (TupleSize == 1)
305template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
343 return *
this =
static_cast<APIType
>(o);
347 this->
Array = o.Array;
358 return *
this =
static_cast<APIType
>(o);
362 this->
Array = std::move(o.Array);
363 this->
Id = std::move(o.Id);
368 template <
typename OArray, ComponentIdType OSize>
372 const APIType tmp = o;
373 return *
this = std::move(tmp);
380 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
384 else if constexpr (TupleSize == 1)
398 if constexpr (std::is_same_v<ArrayType, vtkDataArray>)
402 else if constexpr (TupleSize == 1)
415 APIType tmp = std::move(
static_cast<APIType
>(lhs));
416 lhs = std::move(
static_cast<APIType
>(rhs));
417 rhs = std::move(tmp);
420 template <
typename OArray, ComponentIdType OSize>
427 std::is_same<APIType, OAPIType>::value,
"Cannot swap components with different types.");
429 APIType tmp = std::move(
static_cast<APIType
>(lhs));
430 lhs = std::move(
static_cast<APIType
>(rhs));
431 rhs = std::move(tmp);
436 APIType tmp = std::move(
static_cast<APIType
>(lhs));
437 lhs = std::move(rhs);
438 rhs = std::move(tmp);
443 APIType tmp = std::move(lhs);
444 lhs = std::move(
static_cast<APIType
>(rhs));
445 rhs = std::move(tmp);
451 const APIType newVal = *
this + 1;
459 const APIType retVal = *
this;
467 const APIType newVal = *
this - 1;
475 const APIType retVal = *
this;
480#define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
481 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
483 const APIType newVal = lhs ImplOp val; \
487 friend VTK_ITER_INLINE ValueReference operator Op( \
488 ValueReference lhs, ValueReference val) noexcept \
490 const APIType newVal = lhs ImplOp val; \
494 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
496 const APIType newVal = lhs ImplOp val; \
506#undef VTK_REF_OP_OVERLOADS
508 friend struct ConstValueReference<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
509 friend struct ValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
514 this->
Array = o.Array;
524template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
559 : Array{ o.GetArray() }
580 auto ret = this->Id++;
596 auto ret = this->Id--;
604 return reference{ this->Array, this->Id + i };
612#define VTK_TMP_MAKE_OPERATOR(OP) \
613 friend VTK_ITER_INLINE bool operator OP( \
614 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
616 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
617 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
627#undef VTK_TMP_MAKE_OPERATOR
666 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
667 return it1.Id.GetValueId() - it2.Id.GetValueId();
673 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
676 swap(lhs.Id, rhs.Id);
680 mutable ArrayType* Array;
686template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
719 this->
Ref.CopyReference(o.Ref);
735 auto ret = this->
Ref.Id++;
751 auto ret = this->
Ref.Id--;
768#define VTK_TMP_MAKE_OPERATOR(OP) \
769 friend VTK_ITER_INLINE bool operator OP( \
770 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
773 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
774 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
784#undef VTK_TMP_MAKE_OPERATOR
789 this->
Ref.Id.AddOffset(offset);
809 this->
Ref.Id.AddOffset(-offset);
810 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
824 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
825 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
832 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
835 swap(lhs.GetId(), rhs.GetId());
838 friend struct ConstValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
855template <
typename ArrayTypeT, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
893 , BeginValue(beginValue, this->NumComps)
894 , EndValue(endValue, this->NumComps)
897 assert(beginValue >= 0 && beginValue <= endValue);
898 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
908 return ValueRange{ this->Array, realBegin, realEnd };
931 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
946 return reference{ this->Array, this->BeginValue + i };
965 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
970 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
976 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
985 NumCompsType NumComps{};
986 IdStorageType BeginValue{};
987 IdStorageType EndValue{};
991template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
abstract superclass for arrays of numeric data
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
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
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
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
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
ConstValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > ConstReferenceType
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
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
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)