20 #ifndef vtkDataArrayValueRange_Generic_h
21 #define vtkDataArrayValueRange_Generic_h
30 #include <type_traits>
38 VTK_ABI_NAMESPACE_BEGIN
41 template <
typename ArrayType, ComponentIdType>
42 struct ValueReference;
43 template <
typename ArrayType, ComponentIdType>
44 struct ConstValueReference;
45 template <
typename ArrayType, ComponentIdType>
47 template <
typename ArrayType, ComponentIdType>
48 struct ConstValueIterator;
49 template <
typename ArrayType, ComponentIdType>
60 template <ComponentIdType TupleSize>
84 : ValueId(tupleId * numComps.value + comp)
101 template <
typename ArrayType>
107 "Inconsistent internal state in IdStorage.");
110 this->ValueId >= 0 && this->ValueId <= array->GetNumberOfValues(),
"Invalid value id.");
112 "Invalid tuple id.");
116 this->
GetTupleId() == array->GetNumberOfTuples())),
117 "Invalid component id.");
119 "Invalid value id.");
129 this->ComponentId = 0;
138 auto v = this->ValueId++;
139 auto t = this->TupleId;
140 auto c = this->ComponentId++;
143 this->ComponentId = 0;
146 return IdStorage{ v, t, c, this->NumComps };
161 if (this->ComponentId < 0)
172 auto v = this->ValueId--;
173 auto t = this->TupleId;
174 auto c = this->ComponentId--;
175 if (this->ComponentId < 0)
180 return IdStorage{ v, t, c, this->NumComps };
186 return static_cast<ValueIdType>(tuple) * this->NumComps.value + comp;
192 return std::make_pair(
static_cast<TupleIdType>(
value / this->NumComps.value),
200 std::tie(this->TupleId, this->ComponentId) = this->
Convert(this->ValueId);
218 swap(lhs.ValueId, rhs.ValueId);
219 swap(lhs.TupleId, rhs.TupleId);
220 swap(lhs.ComponentId, rhs.ComponentId);
232 template <
typename ArrayType, ComponentIdType TupleSize>
278 this->
Array = o.Array;
288 this->
Array = std::move(o.Array);
289 this->
Id = std::move(o.Id);
294 operator APIType() const noexcept
299 return acc.Get(this->
Id.
GetTupleId(), this->Id.GetComponentId());
309 template <
typename ArrayType, ComponentIdType TupleSize>
347 return *
this =
static_cast<APIType
>(o);
351 this->
Array = o.Array;
362 return *
this =
static_cast<APIType
>(o);
366 this->
Array = std::move(o.Array);
367 this->
Id = std::move(o.Id);
372 template <
typename OArray, ComponentIdType OSize>
375 const APIType tmp = o;
376 return *
this = std::move(tmp);
380 operator APIType() const noexcept
385 return acc.Get(this->
Id.
GetTupleId(), this->Id.GetComponentId());
394 acc.Set(this->
Id.
GetTupleId(), this->Id.GetComponentId(), val);
400 APIType tmp = std::move(
static_cast<APIType
>(lhs));
401 lhs = std::move(
static_cast<APIType
>(rhs));
402 rhs = std::move(tmp);
405 template <
typename OArray, ComponentIdType OSize>
412 APIType tmp = std::move(
static_cast<APIType
>(lhs));
413 lhs = std::move(
static_cast<APIType
>(rhs));
414 rhs = std::move(tmp);
419 APIType tmp = std::move(
static_cast<APIType
>(lhs));
420 lhs = std::move(rhs);
421 rhs = std::move(tmp);
426 APIType tmp = std::move(lhs);
427 lhs = std::move(
static_cast<APIType
>(rhs));
428 rhs = std::move(tmp);
434 const APIType newVal = *
this + 1;
442 const APIType retVal = *
this;
450 const APIType newVal = *
this - 1;
458 const APIType retVal = *
this;
463 #define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
464 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
466 const APIType newVal = lhs ImplOp val; \
470 friend VTK_ITER_INLINE ValueReference operator Op( \
471 ValueReference lhs, ValueReference val) noexcept \
473 const APIType newVal = lhs ImplOp val; \
477 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
479 const APIType newVal = lhs ImplOp val; \
489 #undef VTK_REF_OP_OVERLOADS
491 friend struct ConstValueReference<ArrayType, TupleSize>;
492 friend struct ValueIterator<ArrayType, TupleSize>;
497 this->
Array = o.Array;
507 template <
typename ArrayType, ComponentIdType TupleSize>
541 : Array{ o.GetArray() }
562 auto ret = this->Id++;
578 auto ret = this->Id--;
586 return reference{ this->Array, this->Id + i };
594 #define VTK_TMP_MAKE_OPERATOR(OP) \
595 friend VTK_ITER_INLINE bool operator OP( \
596 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
598 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
599 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
609 #undef VTK_TMP_MAKE_OPERATOR
648 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
649 return it1.Id.GetValueId() - it2.Id.GetValueId();
655 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
658 swap(lhs.Id, rhs.Id);
662 mutable ArrayType* Array;
668 template <
typename ArrayType, ComponentIdType TupleSize>
701 this->
Ref.CopyReference(o.Ref);
717 auto ret = this->
Ref.Id++;
733 auto ret = this->
Ref.Id--;
750 #define VTK_TMP_MAKE_OPERATOR(OP) \
751 friend VTK_ITER_INLINE bool operator OP( \
752 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
755 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
756 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
766 #undef VTK_TMP_MAKE_OPERATOR
792 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
806 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
807 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
814 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
817 swap(lhs.GetId(), rhs.GetId());
837 template <
typename ArrayTypeT, ComponentIdType TupleSize>
874 , BeginValue(beginValue, this->NumComps)
875 , EndValue(endValue, this->NumComps)
878 assert(beginValue >= 0 && beginValue <= endValue);
879 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
889 return ValueRange{ this->Array, realBegin, realEnd };
912 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
927 return reference{ this->Array, this->BeginValue + i };
937 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
946 NumCompsType NumComps{};
947 IdStorageType BeginValue{};
948 IdStorageType EndValue{};
952 template <
typename ArrayType, ComponentIdType TupleSize>
955 VTK_ABI_NAMESPACE_END
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.
friend VTK_ITER_INLINE void swap(ConstValueIterator &lhs, ConstValueIterator &rhs) noexcept
VTK_ITER_INLINE ConstValueIterator & operator=(const ConstValueIterator &o) noexcept=default
VTK_ITER_INLINE ConstValueIterator & operator++() 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+=(difference_type offset) noexcept
VTK_ITER_INLINE ConstValueIterator operator++(int) noexcept
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++() noexcept
VTK_ITER_INLINE IdStorage operator--(int) noexcept
VTK_ITER_INLINE IdStorage(ValueIdType valueId, NumCompsType numComps) 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 std::pair< TupleIdType, ComponentIdType > Convert(ValueIdType value) const 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
VTK_ITER_INLINE IdStorage & operator--() 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--(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
VTK_ITER_INLINE void DebugIdAsserts() const
VTK_ITER_INLINE const pointer & operator->() const noexcept
ValueIdType difference_type
const IdStorageType & GetId() const noexcept
friend VTK_ITER_INLINE ValueIterator operator+(difference_type offset, const ValueIterator &it) noexcept
VTK_ITER_INLINE ValueIterator & operator-=(difference_type offset) noexcept
ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ValueIterator & operator--() 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
VTK_ITER_INLINE ValueIterator & operator++() noexcept
IdStorageType & GetId() noexcept
VTK_ITER_INLINE ValueIterator & operator+=(difference_type offset) 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 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 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 ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ValueIdType GetBeginValueId() const noexcept
constexpr static ComponentIdType TupleSizeTag
VTK_ITER_INLINE ValueRange GetSubRange(ValueIdType beginValue=0, ValueIdType endValue=-1) const noexcept
ValueReference< ArrayType, TupleSize > ReferenceType
VTK_ITER_INLINE iterator begin() noexcept
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)