8#ifndef vtkDataArrayValueRange_Generic_h
9#define vtkDataArrayValueRange_Generic_h
26VTK_ABI_NAMESPACE_BEGIN
29template <
typename ArrayType, ComponentIdType>
31template <
typename ArrayType, ComponentIdType>
32struct ConstValueReference;
33template <
typename ArrayType, ComponentIdType>
35template <
typename ArrayType, ComponentIdType>
36struct ConstValueIterator;
37template <
typename ArrayType, ComponentIdType>
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>
266 this->
Array = o.Array;
276 this->
Array = std::move(o.Array);
277 this->
Id = std::move(o.Id);
282 operator APIType() const noexcept
297template <
typename ArrayType, ComponentIdType TupleSize>
335 return *
this =
static_cast<APIType
>(o);
350 return *
this =
static_cast<APIType
>(o);
354 this->
Array = std::move(o.Array);
355 this->
Id = std::move(o.Id);
360 template <
typename OArray, ComponentIdType OSize>
363 const APIType tmp = o;
364 return *
this = std::move(tmp);
368 operator APIType() const noexcept
388 APIType tmp = std::move(
static_cast<APIType
>(lhs));
389 lhs = std::move(
static_cast<APIType
>(rhs));
390 rhs = std::move(tmp);
393 template <
typename OArray, ComponentIdType OSize>
398 std::is_same<APIType, OAPIType>::value,
"Cannot swap components with different types.");
400 APIType tmp = std::move(
static_cast<APIType
>(lhs));
401 lhs = std::move(
static_cast<APIType
>(rhs));
402 rhs = std::move(tmp);
407 APIType tmp = std::move(
static_cast<APIType
>(lhs));
408 lhs = std::move(rhs);
409 rhs = std::move(tmp);
414 APIType tmp = std::move(lhs);
415 lhs = std::move(
static_cast<APIType
>(rhs));
416 rhs = std::move(tmp);
422 const APIType newVal = *
this + 1;
430 const APIType retVal = *
this;
438 const APIType newVal = *
this - 1;
446 const APIType retVal = *
this;
451#define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
452 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
454 const APIType newVal = lhs ImplOp val; \
458 friend VTK_ITER_INLINE ValueReference operator Op( \
459 ValueReference lhs, ValueReference val) noexcept \
461 const APIType newVal = lhs ImplOp val; \
465 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
467 const APIType newVal = lhs ImplOp val; \
477#undef VTK_REF_OP_OVERLOADS
479 friend struct ConstValueReference<ArrayType, TupleSize>;
480 friend struct ValueIterator<ArrayType, TupleSize>;
485 this->
Array = o.Array;
495template <
typename ArrayType, ComponentIdType TupleSize>
529 : Array{ o.GetArray() }
550 auto ret = this->Id++;
566 auto ret = this->Id--;
574 return reference{ this->Array, this->Id + i };
582#define VTK_TMP_MAKE_OPERATOR(OP) \
583 friend VTK_ITER_INLINE bool operator OP( \
584 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
586 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
587 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
597#undef VTK_TMP_MAKE_OPERATOR
636 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
637 return it1.Id.GetValueId() - it2.Id.GetValueId();
643 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
646 swap(lhs.Id, rhs.Id);
650 mutable ArrayType* Array;
656template <
typename ArrayType, ComponentIdType TupleSize>
689 this->
Ref.CopyReference(o.Ref);
705 auto ret = this->
Ref.Id++;
721 auto ret = this->
Ref.Id--;
738#define VTK_TMP_MAKE_OPERATOR(OP) \
739 friend VTK_ITER_INLINE bool operator OP( \
740 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
743 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
744 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
754#undef VTK_TMP_MAKE_OPERATOR
759 this->
Ref.Id.AddOffset(offset);
779 this->
Ref.Id.AddOffset(-offset);
780 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
794 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
795 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
802 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
805 swap(lhs.GetId(), rhs.GetId());
825template <
typename ArrayTypeT, ComponentIdType TupleSize>
862 , BeginValue(beginValue, this->NumComps)
863 , EndValue(endValue, this->NumComps)
866 assert(beginValue >= 0 && beginValue <= endValue);
867 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
877 return ValueRange{ this->Array, realBegin, realEnd };
900 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
915 return reference{ this->Array, this->BeginValue + i };
925 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
934 NumCompsType NumComps{};
935 IdStorageType BeginValue{};
936 IdStorageType EndValue{};
940template <
typename ArrayType, ComponentIdType TupleSize>
abstract superclass for arrays of numeric data
ValueRange< AOSArrayType, TupleSize > DeclareValueRangeSpecialization(ArrayType *)
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
Efficient templated access to vtkDataArray.
VTK_ALWAYS_INLINE APIType Get(vtkIdType tupleIdx, int compIdx) const
VTK_ALWAYS_INLINE void Set(vtkIdType tupleIdx, int compIdx, APIType val) const
VTK_ITER_INLINE ConstValueIterator & operator--() noexcept
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) 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() noexcept
VTK_ITER_INLINE ConstValueIterator(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ConstValueIterator(ArrayType *array, IdStorageType id) noexcept
friend VTK_ITER_INLINE difference_type operator-(const ConstValueIterator &it1, const ConstValueIterator &it2) noexcept
VTK_ITER_INLINE ConstValueIterator(const ValueIterator< ArrayType, TupleSize > &o) noexcept
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
friend VTK_ITER_INLINE ConstValueIterator operator+(const ConstValueIterator &it, difference_type offset) noexcept
ValueIdType difference_type
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 reference operator*() const noexcept
std::random_access_iterator_tag iterator_category
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(const ValueReference< ArrayType, TupleSize > &o)
VTK_ITER_INLINE ConstValueReference operator=(const ConstValueReference &o) noexcept
VTK_ITER_INLINE ConstValueReference(ConstValueReference &&o) noexcept=default
VTK_ITER_INLINE ConstValueReference() noexcept
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ConstValueReference(const ConstValueReference &o) noexcept=default
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
VTK_ITER_INLINE reference operator*() const noexcept
VTK_ITER_INLINE reference operator[](difference_type i) const noexcept
VTK_ITER_INLINE ValueIterator & operator--() noexcept
VTK_ITER_INLINE ValueIterator operator--(int) noexcept
VTK_ITER_INLINE ValueIterator(const ValueIterator &o) noexcept=default
VTK_ITER_INLINE ValueIterator & operator=(const ValueIterator &o) noexcept
VTK_ITER_INLINE ValueIterator() noexcept=default
VTK_ITER_INLINE ValueIterator operator++(int) noexcept
IdStorageType & GetId() noexcept
const IdStorageType & GetId() const noexcept
VTK_ITER_INLINE void DebugIdAsserts() const
ValueIdType difference_type
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
ArrayType * GetArray() const noexcept
VTK_ITER_INLINE const pointer & operator->() const noexcept
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
GetAPIType< ArrayType > value_type
friend VTK_ITER_INLINE ValueIterator operator-(const ValueIterator &it, difference_type offset) noexcept
ValueReference< ArrayType, TupleSize > Ref
friend VTK_ITER_INLINE void swap(ValueIterator &lhs, ValueIterator &rhs) noexcept
std::random_access_iterator_tag iterator_category
friend VTK_ITER_INLINE difference_type operator-(const ValueIterator &it1, const ValueIterator &it2) noexcept
VTK_ITER_INLINE ValueIterator & operator++() noexcept
VTK_ITER_INLINE ValueRange() noexcept=default
ConstIteratorType const_iterator
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
GetAPIType< ArrayTypeT > ValueType
VTK_ITER_INLINE iterator end() noexcept
ConstValueReference< ArrayType, TupleSize > ConstReferenceType
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
ValueIterator< ArrayType, TupleSize > IteratorType
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE ValueIdType GetEndValueId() const noexcept
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
ValueReference< ArrayType, TupleSize > ReferenceType
VTK_ITER_INLINE iterator begin() noexcept
static constexpr ComponentIdType TupleSizeTag
VTK_ITER_INLINE const_iterator end() const noexcept
ConstValueIterator< ArrayType, TupleSize > ConstIteratorType
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE ValueReference() noexcept
VTK_ITER_INLINE ValueReference(ArrayType *array, IdStorageType id) noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference &o) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, APIType &rhs) noexcept
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference< OArray, OSize > rhs) noexcept
VTK_ITER_INLINE ValueReference(const ValueReference &o) noexcept=default
friend VTK_ITER_INLINE void swap(APIType &lhs, ValueReference rhs) noexcept
VTK_ITER_INLINE ValueReference operator=(const ValueReference< OArray, OSize > &o) noexcept
void CopyReference(const ValueReference &o) noexcept
VTK_ITER_INLINE ValueReference operator=(APIType val) noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
VTK_ITER_INLINE APIType operator++(int) noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
VTK_ITER_INLINE ValueReference(ValueReference &&o) noexcept=default
friend VTK_ITER_INLINE void swap(ValueReference lhs, ValueReference rhs) noexcept
#define VTK_TMP_MAKE_OPERATOR(OP)
#define VTK_REF_OP_OVERLOADS(Op, ImplOp)