19 #ifndef vtkDataArrayTupleRange_AOS_h
20 #define vtkDataArrayTupleRange_AOS_h
29 #include <type_traits>
34 #ifndef VTK_DEBUG_RANGE_ITERATORS
45 template <
typename ArrayType, ComponentIdType>
47 template <
typename ArrayType, ComponentIdType>
49 template <
typename ArrayType, ComponentIdType>
51 template <
typename ArrayType, ComponentIdType>
53 template <
typename ArrayType, ComponentIdType>
58 template <
typename ValueType, ComponentIdType TupleSize>
64 using APIType = ValueType;
116 tuple[i] = this->Tuple[i];
121 template <
typename OArrayType, ComponentIdType OSize>
128 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
131 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
133 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
137 template <
typename OArrayType, ComponentIdType OSize>
144 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
147 if (other.size() != this->NumComps.value)
152 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
156 template <
typename OArrayType, ComponentIdType OSize>
163 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
166 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
168 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
172 template <
typename OArrayType, ComponentIdType OSize>
179 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
182 if (other.size() != this->NumComps.value)
187 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
190 template <
typename OArrayType, ComponentIdType OSize>
193 return !(*
this == o);
196 template <
typename OArray, ComponentIdType OSize>
199 return !(*
this == o);
239 template <
typename ValueType, ComponentIdType TupleSize>
245 using APIType = ValueType;
278 void GetTuple(
volatile APIType* tuple)
const noexcept
292 tuple[i] = this->Tuple[i];
300 volatile APIType* out = this->Tuple;
313 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
317 template <
typename OArrayType, ComponentIdType OSize>
324 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
327 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
329 std::copy_n(other.cbegin(), OSize, this->begin());
333 template <
typename OArrayType, ComponentIdType OSize>
340 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
344 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
348 template <
typename OArrayType, ComponentIdType OSize>
355 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
358 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
360 std::copy_n(other.cbegin(), OSize, this->begin());
364 template <
typename OArrayType, ComponentIdType OSize>
371 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
375 std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
380 template <
typename OArrayType, ComponentIdType OSize>
387 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
390 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
392 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
396 template <
typename OArrayType, ComponentIdType OSize>
403 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
407 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
411 template <
typename OArrayType, ComponentIdType OSize>
418 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
421 static_assert(TupleSize == OSize,
"Cannot assign tuples with different sizes.");
423 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
427 template <
typename OArrayType, ComponentIdType OSize>
434 (std::is_convertible<OAPIType, APIType>{}),
"Incompatible types when assigning tuples.");
438 return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
441 template <
typename OArrayType, ComponentIdType OSize>
444 return !(*
this == o);
447 template <
typename OArray, ComponentIdType OSize>
450 return !(*
this == o);
454 template <
typename OArrayType, ComponentIdType OSize>
460 static_assert((std::is_same<OAPIType, APIType>{}),
"Incompatible types when swapping tuples.");
463 static_assert(TupleSize == OSize,
"Cannot swap tuples with different sizes.");
465 std::swap_ranges(this->
begin(), this->
end(), other.begin());
469 template <
typename OArrayType, ComponentIdType OSize>
475 static_assert((std::is_same<OAPIType, APIType>{}),
"Incompatible types when swapping tuples.");
479 std::swap_ranges(this->
begin(), this->
end(), other.begin());
484 template <
typename OArray, ComponentIdType OSize>
533 this->Tuple = o.Tuple;
543 template <
typename ValueType, ComponentIdType TupleSize>
545 :
public std::iterator<std::random_access_iterator_tag,
546 ConstTupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>, TupleIdType,
547 ConstTupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>,
548 ConstTupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize> >
553 using Superclass = std::iterator<std::random_access_iterator_tag,
583 this->Ref.Tuple += this->Ref.NumComps.value;
590 auto tuple = this->Ref.Tuple;
591 this->Ref.Tuple += this->Ref.NumComps.value;
598 this->Ref.Tuple -= this->Ref.NumComps.value;
605 auto tuple = this->Ref.Tuple;
606 this->Ref.Tuple -= this->Ref.NumComps.value;
613 return reference{ this->Ref.Tuple + i * this->Ref.NumComps, this->Ref.NumComps };
622 #define VTK_TMP_MAKE_OPERATOR(OP) \
623 friend VTK_ITER_INLINE bool operator OP( \
624 const ConstTupleIterator& lhs, const ConstTupleIterator& rhs) noexcept \
626 return lhs.GetTuple() OP rhs.GetTuple(); \
636 #undef VTK_TMP_MAKE_OPERATOR
641 this->Ref.Tuple +=
offset * this->Ref.NumComps.value;
660 this->Ref.Tuple -=
offset * this->Ref.NumComps.value;
674 (it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
680 swap(lhs.GetTuple(), rhs.GetTuple());
681 swap(lhs.GetNumComps(), rhs.GetNumComps());
686 const ValueType*& GetTuple() noexcept {
return this->Ref.Tuple; }
688 const ValueType* GetTuple() const noexcept {
return this->Ref.Tuple; }
690 NumCompsType& GetNumComps() noexcept {
return this->Ref.NumComps; }
692 NumCompsType GetNumComps() const noexcept {
return this->Ref.NumComps; }
694 ConstTupleReference<ArrayType, TupleSize> Ref;
699 template <
typename ValueType, ComponentIdType TupleSize>
701 :
public std::iterator<std::random_access_iterator_tag,
702 TupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>, TupleIdType,
703 TupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize>,
704 TupleReference<vtkAOSDataArrayTemplate<ValueType>, TupleSize> >
710 std::iterator<std::random_access_iterator_tag, TupleReference<ArrayType, TupleSize>,
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(const TupleIterator& lhs, const TupleIterator& rhs) \
780 return lhs.GetTuple() OP rhs.GetTuple(); \
790 #undef VTK_TMP_MAKE_OPERATOR
828 (it1.GetTuple() - it2.GetTuple()) / it1.GetNumComps().value);
834 swap(lhs.GetTuple(), rhs.GetTuple());
835 swap(lhs.GetNumComps(), rhs.GetNumComps());
850 TupleReference<ArrayType, TupleSize>
Ref;
855 template <
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,
998 #endif // VTK_DEBUG_RANGE_ITERATORS
999 #endif // __VTK_WRAP__
1000 #endif // vtkDataArrayTupleRange_AOS_h