19#ifndef vtkDataArrayTupleRange_AOS_h
20#define vtkDataArrayTupleRange_AOS_h
25#include "vtkDebugRangeIterators.h"
35#ifndef VTK_DEBUG_RANGE_ITERATORS
46template <
typename ArrayType, ComponentIdType>
47struct ConstTupleReference;
48template <
typename ArrayType, ComponentIdType>
50template <
typename ArrayType, ComponentIdType>
51struct ConstTupleIterator;
52template <
typename ArrayType, ComponentIdType>
54template <
typename ArrayType, ComponentIdType>
59template <
typename ValueType, ComponentIdType TupleSize>
65 using APIType = ValueType;
120 tuple[i] = this->Tuple[i];
125 template <
typename OArrayType, ComponentIdType OSize>
132 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
135 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
137 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
141 template <
typename OArrayType, ComponentIdType OSize>
148 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
151 if (other.size() != this->
NumComps.value)
156 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
160 template <
typename OArrayType, ComponentIdType OSize>
167 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
170 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
172 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
176 template <
typename OArrayType, ComponentIdType OSize>
183 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
186 if (other.size() != this->
NumComps.value)
191 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
194 template <
typename OArrayType, ComponentIdType OSize>
197 return !(*
this == o);
200 template <
typename OArray, ComponentIdType OSize>
203 return !(*
this == o);
243template <
typename ValueType, ComponentIdType TupleSize>
249 using APIType = ValueType;
285 void GetTuple(
volatile APIType* tuple)
const noexcept
299 tuple[i] = this->Tuple[i];
307 volatile APIType* out = this->Tuple;
320 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
324 template <
typename OArrayType, ComponentIdType OSize>
331 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
334 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
336 std::copy_n(other.cbegin(), OSize, this->begin());
340 template <
typename OArrayType, ComponentIdType OSize>
347 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
351 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
355 template <
typename OArrayType, ComponentIdType OSize>
362 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
365 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
367 std::copy_n(other.cbegin(), OSize, this->begin());
371 template <
typename OArrayType, ComponentIdType OSize>
378 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
382 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
387 template <
typename OArrayType, ComponentIdType OSize>
394 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
397 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
399 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
403 template <
typename OArrayType, ComponentIdType OSize>
410 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
414 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
418 template <
typename OArrayType, ComponentIdType OSize>
425 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
428 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
430 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
434 template <
typename OArrayType, ComponentIdType OSize>
441 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
445 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
448 template <
typename OArrayType, ComponentIdType OSize>
451 return !(*
this == o);
454 template <
typename OArray, ComponentIdType OSize>
457 return !(*
this == o);
461 template <
typename OArrayType, ComponentIdType OSize>
467 static_assert((std::is_same<OAPIType, APIType>{}),
"Incompatible types when swapping tuples.");
470 static_assert(TupleSize == OSize,
"Cannot swap tuples with different sizes.");
472 std::swap_ranges(this->
begin(), this->
end(), other.begin());
476 template <
typename OArrayType, ComponentIdType OSize>
482 static_assert((std::is_same<OAPIType, APIType>{}),
"Incompatible types when swapping tuples.");
486 std::swap_ranges(this->
begin(), this->
end(), other.begin());
491 template <
typename OArray, ComponentIdType OSize>
540 this->Tuple = o.Tuple;
550template <
typename ValueType, ComponentIdType TupleSize>
569 : Ref(tuple, numComps)
587 this->Ref.Tuple += this->Ref.NumComps.value;
594 auto tuple = this->Ref.Tuple;
595 this->Ref.Tuple += this->Ref.NumComps.value;
602 this->Ref.Tuple -= this->Ref.NumComps.value;
609 auto tuple = this->Ref.Tuple;
610 this->Ref.Tuple -= this->Ref.NumComps.value;
617 return reference{ this->Ref.Tuple + i * this->Ref.NumComps, this->Ref.NumComps };
626#define VTK_TMP_MAKE_OPERATOR(OP) \
627 friend VTK_ITER_INLINE bool operator OP( \
628 const ConstTupleIterator& lhs, const ConstTupleIterator& rhs) noexcept \
630 return lhs.GetTuple() OP rhs.GetTuple(); \
640#undef VTK_TMP_MAKE_OPERATOR
645 this->Ref.Tuple += offset * this->Ref.NumComps.value;
652 return ConstTupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
658 return ConstTupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
664 this->Ref.Tuple -= offset * this->Ref.NumComps.value;
671 return ConstTupleIterator{ it.GetTuple() - offset * it.GetNumComps().value, it.GetNumComps() };
678 (it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
684 swap(lhs.GetTuple(), rhs.GetTuple());
685 swap(lhs.GetNumComps(), rhs.GetNumComps());
690 const ValueType*& GetTuple() noexcept {
return this->Ref.Tuple; }
692 const ValueType* GetTuple() const noexcept {
return this->Ref.Tuple; }
694 NumCompsType& GetNumComps() noexcept {
return this->Ref.NumComps; }
696 NumCompsType GetNumComps() const noexcept {
return this->Ref.NumComps; }
698 ConstTupleReference<ArrayType, TupleSize> Ref;
703template <
typename ValueType, ComponentIdType TupleSize>
722 :
Ref(tuple, numComps)
732 this->
Ref.CopyReference(o.Ref);
739 this->
Ref.Tuple += this->
Ref.NumComps.value;
746 auto tuple = this->
Ref.Tuple;
747 this->
Ref.Tuple += this->
Ref.NumComps.value;
754 this->
Ref.Tuple -= this->
Ref.NumComps.value;
761 auto tuple = this->
Ref.Tuple;
762 this->
Ref.Tuple -= this->
Ref.NumComps.value;
769 return reference{ this->
Ref.Tuple + i * this->
Ref.NumComps.value, this->
Ref.NumComps };
776#define VTK_TMP_MAKE_OPERATOR(OP) \
777 friend VTK_ITER_INLINE bool operator OP( \
778 const TupleIterator& lhs, const TupleIterator& rhs) noexcept \
780 return lhs.GetTuple() OP rhs.GetTuple(); \
790#undef VTK_TMP_MAKE_OPERATOR
795 this->
Ref.Tuple += offset * this->
Ref.NumComps.value;
802 return TupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
808 return TupleIterator{ it.GetTuple() + offset * it.GetNumComps().value, it.GetNumComps() };
814 this->
Ref.Tuple -= offset * this->
Ref.NumComps.value;
821 return TupleIterator{ it.GetTuple() - offset * it.GetNumComps().value, it.GetNumComps() };
828 (it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
834 swap(lhs.GetTuple(), rhs.GetTuple());
835 swap(lhs.GetNumComps(), rhs.GetNumComps());
855template <
typename ValueType, ComponentIdType TupleSize>
894 , BeginTuple(
TupleRange::GetTuplePointer(arr, beginTuple))
895 , EndTuple(
TupleRange::GetTuplePointer(arr, endTuple))
898 assert(beginTuple >= 0 && beginTuple <= endTuple);
899 assert(endTuple >= 0 && endTuple <= this->Array->GetNumberOfTuples());
905 const TupleIdType curBegin = this->GetTupleId(this->BeginTuple);
906 const TupleIdType realBegin = curBegin + beginTuple;
908 endTuple >= 0 ? curBegin + endTuple : this->GetTupleId(this->EndTuple);
910 return TupleRange{ this->Array, realBegin, realEnd };
928 return static_cast<size_type>(this->EndTuple - this->BeginTuple) /
929 static_cast<size_type>(this->NumComps.value);
956 return reference{ this->BeginTuple + i * this->NumComps.value, this->NumComps };
962 return const_reference{ this->BeginTuple + i * this->NumComps.value, this->NumComps };
969 return array->GetPointer(tuple * this->NumComps.value);
973 TupleIdType GetTupleId(
const ValueType* ptr)
const noexcept
975 return static_cast<TupleIdType>((ptr - this->Array->GetPointer(0)) / this->NumComps.value);
979 NumCompsType NumComps{};
980 ValueType* BeginTuple{
nullptr };
981 ValueType* EndTuple{
nullptr };
987 typename ValueType =
typename ArrayType::ValueType,
990 typename =
typename std::enable_if<IsAOSDataArray<ArrayType>::value>::type>
Array-Of-Structs implementation of vtkGenericDataArray.
typename std::enable_if< AreStaticTupleSizes< S1, S2 >::value, T >::type EnableIfStaticTupleSizes
TupleRange< AOSArrayType, TupleSize > DeclareTupleRangeSpecialization(ArrayType *)
typename std::enable_if< IsEitherTupleSizeDynamic< S1, S2 >::value, T >::type EnableIfEitherTupleSizeIsDynamic
Specialization of tuple ranges and iterators for vtkAOSDataArrayTemplate.
typename detail::GetAPITypeImpl< ArrayType >::APIType GetAPIType
TupleIdType difference_type
friend VTK_ITER_INLINE void swap(ConstTupleIterator &lhs, ConstTupleIterator &rhs) noexcept
VTK_ITER_INLINE ConstTupleIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE ConstTupleIterator operator--(int) noexcept
std::random_access_iterator_tag iterator_category
friend VTK_ITER_INLINE ConstTupleIterator operator+(difference_type offset, const ConstTupleIterator &it) noexcept
friend VTK_ITER_INLINE ConstTupleIterator operator+(const ConstTupleIterator &it, difference_type offset) noexcept
friend VTK_ITER_INLINE ConstTupleIterator operator-(const ConstTupleIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE reference operator[](difference_type i) noexcept
VTK_ITER_INLINE ConstTupleIterator & operator+=(difference_type offset) noexcept
VTK_ITER_INLINE ConstTupleIterator & operator--() noexcept
VTK_ITER_INLINE pointer & operator->() noexcept
VTK_ITER_INLINE ConstTupleIterator(const TupleIterator< ArrayType, TupleSize > &o) noexcept
friend VTK_ITER_INLINE difference_type operator-(const ConstTupleIterator &it1, const ConstTupleIterator &it2) noexcept
VTK_ITER_INLINE ConstTupleIterator & operator=(const ConstTupleIterator &o) noexcept=default
VTK_ITER_INLINE ConstTupleIterator(const ConstTupleIterator &o) noexcept=default
VTK_ITER_INLINE reference operator*() noexcept
VTK_ITER_INLINE ConstTupleIterator operator++(int) noexcept
VTK_ITER_INLINE ConstTupleIterator & operator++() noexcept
VTK_ITER_INLINE ConstTupleIterator() noexcept=default
friend VTK_ITER_INLINE void swap(ConstTupleIterator &lhs, ConstTupleIterator &rhs) noexcept
VTK_ITER_INLINE bool operator!=(const ConstTupleReference< OArray, OSize > &o) const noexcept
VTK_ITER_INLINE ConstTupleReference(const ConstTupleReference &) noexcept=default
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, bool > operator==(const TupleReference< OArrayType, OSize > &other) const noexcept
const ValueType & const_reference
VTK_ITER_INLINE const ConstTupleReference * operator->() const noexcept
ComponentIdType size_type
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
VTK_ITER_INLINE ConstTupleReference(ConstTupleReference &&) noexcept=default
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, bool > operator==(const ConstTupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE bool operator!=(const TupleReference< OArrayType, OSize > &o) const noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE ConstTupleReference & operator=(const ConstTupleReference &) noexcept=default
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, bool > operator==(const ConstTupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE void GetTuple(volatile APIType *tuple) const noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, bool > operator==(const TupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE ConstTupleReference(const ValueType *tuple, NumCompsType numComps) noexcept
VTK_ITER_INLINE ConstTupleReference() noexcept
const ValueType * iterator
VTK_ITER_INLINE ConstTupleReference(const TupleReference< ArrayType, TupleSize > &o) noexcept
const ValueType * const_iterator
VTK_ITER_INLINE const_iterator end() const noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE TupleIterator() noexcept=default
VTK_ITER_INLINE NumCompsType GetNumComps() const noexcept
VTK_ITER_INLINE TupleIterator & operator--() noexcept
VTK_ITER_INLINE TupleIterator operator++(int) noexcept
friend VTK_ITER_INLINE TupleIterator operator+(const TupleIterator &it, difference_type offset) noexcept
TupleIdType difference_type
std::random_access_iterator_tag iterator_category
VTK_ITER_INLINE TupleIterator operator--(int) noexcept
VTK_ITER_INLINE TupleIterator & operator++() noexcept
VTK_ITER_INLINE NumCompsType & GetNumComps() noexcept
friend VTK_ITER_INLINE TupleIterator operator-(const TupleIterator &it, difference_type offset) noexcept
VTK_ITER_INLINE TupleIterator & operator=(const TupleIterator &o) noexcept
reference operator*() noexcept
VTK_ITER_INLINE ValueType * GetTuple() const noexcept
VTK_ITER_INLINE TupleIterator(const TupleIterator &o) noexcept=default
pointer & operator->() noexcept
TupleReference< ArrayType, TupleSize > Ref
friend VTK_ITER_INLINE TupleIterator operator+(difference_type offset, const TupleIterator &it) noexcept
VTK_ITER_INLINE TupleIterator & operator-=(difference_type offset) noexcept
VTK_ITER_INLINE ValueType *& GetTuple() noexcept
VTK_ITER_INLINE TupleIterator & operator+=(difference_type offset) noexcept
friend VTK_ITER_INLINE difference_type operator-(const TupleIterator &it1, const TupleIterator &it2) noexcept
VTK_ITER_INLINE reference operator[](difference_type i) noexcept
friend VTK_ITER_INLINE void swap(TupleIterator &lhs, TupleIterator &rhs) noexcept
TupleReference< ArrayType, TupleSize > Ref
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
VTK_ITER_INLINE size_type size() const noexcept
VTK_ITER_INLINE const_iterator end() const noexcept
GetAPIType< ArrayType > APIType
VTK_ITER_INLINE TupleRange() noexcept=default
APIType & ComponentReferenceType
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
VTK_ITER_INLINE TupleIdType GetEndTupleId() const noexcept
APIType * ComponentIteratorType
VTK_ITER_INLINE ArrayType * GetArray() const noexcept
VTK_ITER_INLINE ComponentIdType GetTupleSize() const noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE TupleIdType GetBeginTupleId() const noexcept
VTK_ITER_INLINE TupleRange GetSubRange(TupleIdType beginTuple=0, TupleIdType endTuple=-1) const noexcept
const APIType & ConstComponentReferenceType
VTK_ITER_INLINE iterator end() noexcept
APIType const * ConstComponentIteratorType
VTK_ITER_INLINE iterator begin() noexcept
GetAPIType< ArrayType > APIType
static constexpr ComponentIdType TupleSizeTag
TupleIterator< ArrayType, TupleSize > TupleIteratorType
ConstTupleIterator< ArrayType, TupleSize > ConstTupleIteratorType
ConstTupleIteratorType const_iterator
TupleReference< ArrayType, TupleSize > TupleReferenceType
ConstTupleReference< ArrayType, TupleSize > ConstTupleReferenceType
TupleIteratorType iterator
VTK_ITER_INLINE TupleReference() noexcept
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, TupleReference & > operator=(const ConstTupleReference< OArrayType, OSize > &other) noexcept
VTK_ITER_INLINE const_iterator begin() const noexcept
VTK_ITER_INLINE const TupleReference * operator->() const noexcept
VTK_ITER_INLINE TupleReference & operator=(const TupleReference &other) noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, void > swap(TupleReference< OArrayType, OSize > other) noexcept
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, void > swap(TupleReference< OArrayType, OSize > other) noexcept
friend VTK_ITER_INLINE void swap(TupleReference a, TupleReference b) noexcept
VTK_ITER_INLINE void GetTuple(volatile APIType *tuple) const noexcept
VTK_ITER_INLINE TupleReference(ValueType *tuple, NumCompsType numComps) noexcept
const ValueType * const_iterator
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, TupleReference & > operator=(const TupleReference< OArrayType, OSize > &other) noexcept
ValueType const & const_reference
VTK_ITER_INLINE const_iterator end() const noexcept
VTK_ITER_INLINE iterator end() noexcept
VTK_ITER_INLINE bool operator!=(const TupleReference< OArrayType, OSize > &o) const noexcept
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, bool > operator==(const ConstTupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, bool > operator==(const TupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE EnableIfStaticTupleSizes< TupleSize, OSize, bool > operator==(const TupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE reference operator[](size_type i) noexcept
VTK_ITER_INLINE const_reference operator[](size_type i) const noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, bool > operator==(const ConstTupleReference< OArrayType, OSize > &other) const noexcept
VTK_ITER_INLINE void fill(const value_type &v) noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, TupleReference & > operator=(const TupleReference< OArrayType, OSize > &other) noexcept
VTK_ITER_INLINE EnableIfEitherTupleSizeIsDynamic< TupleSize, OSize, TupleReference & > operator=(const ConstTupleReference< OArrayType, OSize > &other) noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE void SetTuple(const APIType *tuple) noexcept
VTK_ITER_INLINE iterator begin() noexcept
VTK_ITER_INLINE TupleReference(const TupleReference &) noexcept=default
VTK_ITER_INLINE TupleReference(TupleReference &&) noexcept=default
VTK_ITER_INLINE void CopyReference(const TupleReference &o) noexcept
ComponentIdType size_type
VTK_ITER_INLINE size_type size() const noexcept
friend VTK_ITER_INLINE void swap(TupleReference a, TupleReference< OArray, OSize > b) noexcept
VTK_ITER_INLINE bool operator!=(const ConstTupleReference< OArray, OSize > &o) const noexcept
VTK_ITER_INLINE const_iterator cbegin() const noexcept
VTK_ITER_INLINE const_iterator cend() const noexcept
VTK_ITER_INLINE iterator begin() noexcept
VTK_ITER_INLINE iterator end() noexcept
#define VTK_TMP_MAKE_OPERATOR(OP)