20#ifndef vtkDataArrayValueRange_Generic_h
21#define vtkDataArrayValueRange_Generic_h
43template <
typename ArrayType, ComponentIdType>
45template <
typename ArrayType, ComponentIdType>
46struct ConstValueReference;
47template <
typename ArrayType, ComponentIdType>
49template <
typename ArrayType, ComponentIdType>
50struct ConstValueIterator;
51template <
typename ArrayType, ComponentIdType>
62template <ComponentIdType TupleSize>
86 : ValueId(tupleId * numComps.value + comp)
103 template <
typename ArrayType>
109 "Inconsistent internal state in IdStorage.");
112 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(),
"Invalid value id.");
114 "Invalid tuple id.");
118 this->
GetTupleId() == array->GetNumberOfTuples())),
119 "Invalid component id.");
121 "Invalid value id.");
131 this->ComponentId = 0;
140 auto v = this->ValueId++;
141 auto t = this->TupleId;
142 auto c = this->ComponentId++;
145 this->ComponentId = 0;
148 return IdStorage{ v, t, c, this->NumComps };
163 if (this->ComponentId < 0)
174 auto v = this->ValueId--;
175 auto t = this->TupleId;
176 auto c = this->ComponentId--;
177 if (this->ComponentId < 0)
182 return IdStorage{ v, t, c, this->NumComps };
188 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
194 return std::make_pair(
static_cast<TupleIdType>(
value / this->NumComps.value),
202 std::tie(this->TupleId, this->ComponentId) = this->
Convert(this->ValueId);
220 swap(lhs.ValueId, rhs.ValueId);
221 swap(lhs.TupleId, rhs.TupleId);
222 swap(lhs.ComponentId, rhs.ComponentId);
234template <
typename ArrayType, ComponentIdType TupleSize>
280 this->
Array = o.Array;
290 this->
Array = std::move(o.Array);
291 this->
Id = std::move(o.Id);
296 operator APIType() const noexcept
301 return acc.Get(this->
Id.
GetTupleId(), this->Id.GetComponentId());
311template <
typename ArrayType, ComponentIdType TupleSize>
349 return *
this =
static_cast<APIType
>(o);
353 this->
Array = o.Array;
364 return *
this =
static_cast<APIType
>(o);
368 this->
Array = std::move(o.Array);
369 this->
Id = std::move(o.Id);
374 template <
typename OArray, ComponentIdType OSize>
377 const APIType tmp = o;
378 return *
this = std::move(tmp);
382 operator APIType() const noexcept
387 return acc.Get(this->
Id.
GetTupleId(), this->Id.GetComponentId());
396 acc.Set(this->
Id.
GetTupleId(), this->Id.GetComponentId(), val);
402 APIType tmp = std::move(
static_cast<APIType
>(lhs));
403 lhs = std::move(
static_cast<APIType
>(rhs));
404 rhs = std::move(tmp);
407 template <
typename OArray, ComponentIdType OSize>
414 APIType tmp = std::move(
static_cast<APIType
>(lhs));
415 lhs = std::move(
static_cast<APIType
>(rhs));
416 rhs = std::move(tmp);
421 APIType tmp = std::move(
static_cast<APIType
>(lhs));
422 lhs = std::move(rhs);
423 rhs = std::move(tmp);
428 APIType tmp = std::move(lhs);
429 lhs = std::move(
static_cast<APIType
>(rhs));
430 rhs = std::move(tmp);
436 const APIType newVal = *
this + 1;
444 const APIType retVal = *
this;
452 const APIType newVal = *
this - 1;
460 const APIType retVal = *
this;
465#define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
466 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
468 const APIType newVal = lhs ImplOp val; \
472 friend VTK_ITER_INLINE ValueReference operator Op( \
473 ValueReference lhs, ValueReference val) noexcept \
475 const APIType newVal = lhs ImplOp val; \
479 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
481 const APIType newVal = lhs ImplOp val; \
491#undef VTK_REF_OP_OVERLOADS
493 friend struct ConstValueReference<ArrayType, TupleSize>;
494 friend struct ValueIterator<ArrayType, TupleSize>;
499 this->
Array = o.Array;
509template <
typename ArrayType, ComponentIdType TupleSize>
543 : Array{ o.GetArray() }
564 auto ret = this->Id++;
580 auto ret = this->Id--;
588 return reference{ this->Array, this->Id + i };
596#define VTK_TMP_MAKE_OPERATOR(OP) \
597 friend VTK_ITER_INLINE bool operator OP( \
598 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
600 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
601 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
611#undef VTK_TMP_MAKE_OPERATOR
650 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
651 return it1.Id.GetValueId() - it2.Id.GetValueId();
657 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
660 swap(lhs.Id, rhs.Id);
664 mutable ArrayType* Array;
670template <
typename ArrayType, ComponentIdType TupleSize>
703 this->
Ref.CopyReference(o.Ref);
719 auto ret = this->
Ref.Id++;
735 auto ret = this->
Ref.Id--;
752#define VTK_TMP_MAKE_OPERATOR(OP) \
753 friend VTK_ITER_INLINE bool operator OP( \
754 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
757 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
758 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
768#undef VTK_TMP_MAKE_OPERATOR
794 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
808 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
809 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
816 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
819 swap(lhs.GetId(), rhs.GetId());
839template <
typename ArrayTypeT, ComponentIdType TupleSize>
876 , BeginValue(beginValue, this->NumComps)
877 , EndValue(endValue, this->NumComps)
880 assert(beginValue >= 0 && beginValue <= endValue);
881 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
891 return ValueRange{ this->Array, realBegin, realEnd };
914 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
929 return reference{ this->Array, this->BeginValue + i };
939 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
948 NumCompsType NumComps{};
949 IdStorageType BeginValue{};
950 IdStorageType EndValue{};
954template <
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_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)