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);
284 template <
typename AT = ArrayType>
285 typename std::enable_if<std::is_same<AT, vtkDataArray>::value, APIType>::type
VTK_ITER_INLINE
290 return this->
Array->GetComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId());
293 template <
typename AT = ArrayType>
294 typename std::enable_if<!std::is_same<AT, vtkDataArray>::value, APIType>::type
VTK_ITER_INLINE
299 return this->
Array->GetTypedComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId());
308template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
346 return *
this =
static_cast<APIType
>(o);
350 this->
Array = o.Array;
361 return *
this =
static_cast<APIType
>(o);
365 this->
Array = std::move(o.Array);
366 this->
Id = std::move(o.Id);
371 template <
typename OArray, ComponentIdType OSize>
375 const APIType tmp = o;
376 return *
this = std::move(tmp);
381 template <
typename AT = ArrayType>
382 typename std::enable_if<std::is_same<AT, vtkDataArray>::value,
ValueReference>::type
388 this->
Array->SetComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId(), val);
392 template <
typename AT = ArrayType>
393 typename std::enable_if<!std::is_same<AT, vtkDataArray>::value,
ValueReference>::type
399 this->
Array->SetTypedComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId(), val);
405 APIType tmp = std::move(
static_cast<APIType
>(lhs));
406 lhs = std::move(
static_cast<APIType
>(rhs));
407 rhs = std::move(tmp);
410 template <
typename OArray, ComponentIdType OSize>
417 std::is_same<APIType, OAPIType>::value,
"Cannot swap components with different types.");
419 APIType tmp = std::move(
static_cast<APIType
>(lhs));
420 lhs = std::move(
static_cast<APIType
>(rhs));
421 rhs = std::move(tmp);
426 APIType tmp = std::move(
static_cast<APIType
>(lhs));
427 lhs = std::move(rhs);
428 rhs = std::move(tmp);
433 APIType tmp = std::move(lhs);
434 lhs = std::move(
static_cast<APIType
>(rhs));
435 rhs = std::move(tmp);
441 const APIType newVal = *
this + 1;
449 const APIType retVal = *
this;
457 const APIType newVal = *
this - 1;
465 const APIType retVal = *
this;
470#define VTK_REF_OP_OVERLOADS(Op, ImplOp) \
471 friend VTK_ITER_INLINE ValueReference operator Op(ValueReference lhs, APIType val) noexcept \
473 const APIType newVal = lhs ImplOp val; \
477 friend VTK_ITER_INLINE ValueReference operator Op( \
478 ValueReference lhs, ValueReference val) noexcept \
480 const APIType newVal = lhs ImplOp val; \
484 friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ValueReference val) noexcept \
486 const APIType newVal = lhs ImplOp val; \
496#undef VTK_REF_OP_OVERLOADS
498 friend struct ConstValueReference<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
499 friend struct ValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
502 template <
typename AT = ArrayType>
503 typename std::enable_if<std::is_same<AT, vtkDataArray>::value, APIType>::type
VTK_ITER_INLINE
508 return this->
Array->GetComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId());
511 template <
typename AT = ArrayType>
512 typename std::enable_if<!std::is_same<AT, vtkDataArray>::value, APIType>::type
VTK_ITER_INLINE
517 return this->
Array->GetTypedComponent(this->
Id.
GetTupleId(), this->Id.GetComponentId());
522 this->
Array = o.Array;
532template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
567 : Array{ o.GetArray() }
588 auto ret = this->Id++;
604 auto ret = this->Id--;
612 return reference{ this->Array, this->Id + i };
620#define VTK_TMP_MAKE_OPERATOR(OP) \
621 friend VTK_ITER_INLINE bool operator OP( \
622 const ConstValueIterator& lhs, const ConstValueIterator& rhs) noexcept \
624 VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison."); \
625 return lhs.Id.GetValueId() OP rhs.Id.GetValueId(); \
635#undef VTK_TMP_MAKE_OPERATOR
674 VTK_ITER_ASSERT(it1.Array == it2.Array,
"Cannot do math with iterators from different arrays.");
675 return it1.Id.GetValueId() - it2.Id.GetValueId();
681 VTK_ITER_ASSERT(lhs.Array == rhs.Array,
"Cannot swap iterators from different arrays.");
684 swap(lhs.Id, rhs.Id);
688 mutable ArrayType* Array;
694template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
727 this->
Ref.CopyReference(o.Ref);
743 auto ret = this->
Ref.Id++;
759 auto ret = this->
Ref.Id--;
776#define VTK_TMP_MAKE_OPERATOR(OP) \
777 friend VTK_ITER_INLINE bool operator OP( \
778 const ValueIterator& lhs, const ValueIterator& rhs) noexcept \
781 lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison."); \
782 return lhs.GetId().GetValueId() OP rhs.GetId().GetValueId(); \
792#undef VTK_TMP_MAKE_OPERATOR
797 this->
Ref.Id.AddOffset(offset);
817 this->
Ref.Id.AddOffset(-offset);
818 this->
Ref.Id.DebugAsserts(this->
Ref.Array);
832 it1.Ref.Array == it2.Ref.Array,
"Cannot do math with iterators from different arrays.");
833 return it1.GetId().GetValueId() - it2.GetId().GetValueId();
840 lhs.GetArray() == rhs.GetArray(),
"Cannot swap iterators from different arrays.");
843 swap(lhs.GetId(), rhs.GetId());
846 friend struct ConstValueIterator<ArrayType, TupleSize, ForceValueTypeForVtkDataArray>;
863template <
typename ArrayTypeT, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
901 , BeginValue(beginValue, this->NumComps)
902 , EndValue(endValue, this->NumComps)
905 assert(beginValue >= 0 && beginValue <= endValue);
906 assert(endValue >= 0 && endValue <= this->Array->GetNumberOfValues());
916 return ValueRange{ this->Array, realBegin, realEnd };
939 iterator end() noexcept {
return this->NewIterator(this->EndValue); }
954 return reference{ this->Array, this->BeginValue + i };
972 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
976 return reinterpret_cast<value_type*
>(this->Array->GetVoidPointer(0));
982 iterator NewIterator(IdStorageType
id)
const noexcept {
return iterator{ this->Array,
id }; }
991 NumCompsType NumComps{};
992 IdStorageType BeginValue{};
993 IdStorageType EndValue{};
997template <
typename ArrayType, ComponentIdType TupleSize,
typename ForceValueTypeForVtkDataArray>
1001VTK_ABI_NAMESPACE_END
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
std::enable_if< std::is_same< AT, vtkDataArray >::value, APIType >::type VTK_ITER_INLINE castOperator() const noexcept
VTK_ITER_INLINE ConstValueReference(const ValueReference< ArrayType, TupleSize, ForceValueTypeForVtkDataArray > &o)
VTK_ITER_INLINE ConstValueReference(ArrayType *array, IdStorageType id) noexcept
std::enable_if<!std::is_same< AT, vtkDataArray >::value, APIType >::type VTK_ITER_INLINE castOperator() const 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
value_type * data() const noexcept
VTK_ITER_INLINE ValueReference operator++() noexcept
std::enable_if< std::is_same< AT, vtkDataArray >::value, ValueReference >::type VTK_ITER_INLINE operator=(APIType val) noexcept
VTK_ITER_INLINE ValueReference operator=(ValueReference &&o) noexcept
VTK_ITER_INLINE ValueReference operator--() noexcept
std::enable_if<!std::is_same< AT, vtkDataArray >::value, APIType >::type VTK_ITER_INLINE castOperator() const 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
std::enable_if< std::is_same< AT, vtkDataArray >::value, APIType >::type VTK_ITER_INLINE castOperator() const noexcept
std::enable_if<!std::is_same< AT, vtkDataArray >::value, ValueReference >::type VTK_ITER_INLINE operator=(APIType val) 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)