20 #ifndef vtkDataArrayTupleRange_Generic_h 
   21 #define vtkDataArrayTupleRange_Generic_h 
   30 #include <type_traits> 
   43 template <
typename ArrayType, ComponentIdType>
 
   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>
 
   55 template <
typename ArrayType, ComponentIdType>
 
   57 template <
typename ArrayType, ComponentIdType>
 
   59 template <
typename ArrayType, ComponentIdType>
 
   64 template <
typename ArrayType, ComponentIdType TupleSize>
 
   95       tuple >= 0 && tuple <= array->GetNumberOfTuples(), 
"Invalid tuple accessed by iterator.");
 
   97       "Invalid component accessed by iterator.");
 
  120     this->
Array = o.Array;
 
  131     this->
Array = std::move(o.Array);
 
  132     this->
NumComps = std::move(o.NumComps);
 
  133     this->
TupleId = std::move(o.TupleId);
 
  138   operator APIType() const noexcept
 
  155 template <
typename ArrayType, ComponentIdType TupleSize>
 
  186       tuple >= 0 && tuple <= array->GetNumberOfTuples(), 
"Invalid tuple accessed by iterator.");
 
  188       "Invalid component accessed by iterator.");
 
  201       return *
this = 
static_cast<APIType
>(o);
 
  205       this->
Array = o.Array;
 
  219       return *
this = std::move(
static_cast<APIType
>(o));
 
  223       this->
Array = std::move(o.Array);
 
  224       this->
NumComps = std::move(o.NumComps);
 
  225       this->
TupleId = std::move(o.TupleId);
 
  232   template <
typename OArray, ComponentIdType OSize>
 
  235     const APIType tmp = o;
 
  236     return *
this = std::move(tmp);
 
  240   operator APIType() const noexcept
 
  260     APIType tmp = std::move(
static_cast<APIType
>(lhs));
 
  261     lhs = std::move(
static_cast<APIType
>(rhs));
 
  262     rhs = std::move(tmp);
 
  265   template <
typename OArray, ComponentIdType OSize>
 
  273     APIType tmp = std::move(
static_cast<APIType
>(lhs));
 
  274     lhs = std::move(
static_cast<APIType
>(rhs));
 
  275     rhs = std::move(tmp);
 
  280     APIType tmp = std::move(
static_cast<APIType
>(lhs));
 
  281     lhs = std::move(rhs);
 
  282     rhs = std::move(tmp);
 
  287     APIType tmp = std::move(lhs);
 
  288     lhs = std::move(
static_cast<APIType
>(rhs));
 
  289     rhs = std::move(tmp);
 
  295     const APIType newVal = *
this + 1;
 
  303     const APIType retVal = *
this;
 
  311     const APIType newVal = *
this - 1;
 
  319     const APIType retVal = *
this;
 
  324 #define VTK_REF_OP_OVERLOADS(Op, ImplOp)                                                           \ 
  325   friend VTK_ITER_INLINE ComponentReference operator Op(ComponentReference lhs, APIType val)       \ 
  328     const APIType newVal = lhs ImplOp val;                                                         \ 
  332   friend VTK_ITER_INLINE ComponentReference operator Op(                                           \ 
  333     ComponentReference lhs, ComponentReference val) noexcept                                       \ 
  335     const APIType newVal = lhs ImplOp val;                                                         \ 
  339   friend VTK_ITER_INLINE APIType& operator Op(APIType& lhs, ComponentReference val) noexcept       \ 
  341     const APIType newVal = lhs ImplOp val;                                                         \ 
  351 #undef VTK_REF_OP_OVERLOADS 
  360     this->
Array = o.Array;
 
  374 template <
typename ArrayType, ComponentIdType TupleSize>
 
  376   : 
public std::iterator<std::random_access_iterator_tag, GetAPIType<ArrayType>, ComponentIdType,
 
  378       void, ConstComponentReference<ArrayType, TupleSize> >
 
  385   using Superclass = std::iterator<std::random_access_iterator_tag, GetAPIType<ArrayType>,
 
  414       "Const component iterator at invalid tuple id.");
 
  416       "Const component iterator at invalid component id.");
 
  421     : Array{ o.GetArray() }
 
  422     , NumComps{ o.GetNumComps() }
 
  423     , TupleId{ o.GetTupleId() }
 
  424     , ComponentId{ o.GetComponentId() }
 
  437     VTK_ITER_ASSERT(this->ComponentId >= 0 && this->ComponentId <= this->NumComps.value,
 
  438       "Const component iterator at invalid component id.");
 
  446       this->ComponentId++ };
 
  453     VTK_ITER_ASSERT(this->ComponentId >= 0 && this->ComponentId <= this->NumComps.value,
 
  454       "Const component iterator at invalid component id.");
 
  462       this->ComponentId-- };
 
  468     return reference{ this->Array, this->NumComps, this->TupleId, this->ComponentId + i };
 
  474     return reference{ this->Array, this->NumComps, this->TupleId, this->ComponentId };
 
  477 #define VTK_TMP_MAKE_OPERATOR(OP)                                                                  \ 
  478   friend VTK_ITER_INLINE bool operator OP(                                                         \ 
  479     const ConstComponentIterator& lhs, const ConstComponentIterator& rhs) noexcept                 \ 
  481     VTK_ITER_ASSERT(lhs.Array == rhs.Array, "Mismatched arrays in iterator comparison.");          \ 
  482     VTK_ITER_ASSERT(lhs.TupleId == rhs.TupleId, "Mismatched tuple ids in iterator comparison.");   \ 
  483     VTK_ITER_ASSUME(lhs.NumComps.value > 0);                                                       \ 
  484     VTK_ITER_ASSUME(lhs.NumComps.value == rhs.NumComps.value);                                     \ 
  485     return lhs.ComponentId OP rhs.ComponentId;                                                     \ 
  495 #undef VTK_TMP_MAKE_OPERATOR 
  500     this->ComponentId += 
offset;
 
  501     VTK_ITER_ASSERT(this->ComponentId >= 0 && this->ComponentId <= this->NumComps.value,
 
  502       "Const component iterator at invalid component id.");
 
  521     this->ComponentId -= 
offset;
 
  522     VTK_ITER_ASSERT(this->ComponentId >= 0 && this->ComponentId <= this->NumComps.value,
 
  523       "Const component iterator at invalid component id.");
 
  536     VTK_ITER_ASSERT(it1.Array == it2.Array, 
"Cannot do math with iterators from different arrays.");
 
  538       "Cannot do math with component iterators from different " 
  540     return it1.ComponentId - it2.ComponentId;
 
  547     VTK_ITER_ASSERT(lhs.Array == rhs.Array, 
"Cannot swap iterators from different arrays.");
 
  550     swap(lhs.TupleId, rhs.TupleId);
 
  551     swap(lhs.ComponentId, rhs.ComponentId);
 
  555   mutable ArrayType* Array;
 
  556   NumCompsType NumComps;
 
  563 template <
typename ArrayType, ComponentIdType TupleSize>
 
  564 struct ComponentIterator
 
  565   : 
public std::iterator<std::random_access_iterator_tag, GetAPIType<ArrayType>, ComponentIdType,
 
  566       ComponentReference<ArrayType, TupleSize>, ComponentReference<ArrayType, TupleSize> >
 
  572   using NumCompsType = GenericTupleSize<TupleSize>;
 
  574   using Superclass = std::iterator<std::random_access_iterator_tag, APIType, 
ComponentIdType,
 
  575     ComponentReference<ArrayType, TupleSize>, ComponentReference<ArrayType, TupleSize> >;
 
  594       "Component iterator at invalid tuple id.");
 
  596       comp >= 0 && comp <= numComps.value, 
"Component iterator at invalid component id.");
 
  605     this->
Ref.CopyReference(o.Ref);
 
  612     ++this->
Ref.ComponentId;
 
  613     VTK_ITER_ASSERT(this->
Ref.ComponentId >= 0 && this->Ref.ComponentId <= this->Ref.NumComps.value,
 
  614       "Component iterator at invalid component id.");
 
  622       this->
Ref.ComponentId++ };
 
  628     --this->
Ref.ComponentId;
 
  629     VTK_ITER_ASSERT(this->
Ref.ComponentId >= 0 && this->Ref.ComponentId <= this->Ref.NumComps.value,
 
  630       "Component iterator at invalid component id.");
 
  638       this->
Ref.ComponentId-- };
 
  645       this->
Ref.ComponentId + i };
 
  654 #define VTK_TMP_MAKE_OPERATOR(OP)                                                                  \ 
  655   friend VTK_ITER_INLINE bool operator OP(                                                         \ 
  656     const ComponentIterator& lhs, const ComponentIterator& rhs) noexcept                           \ 
  659       lhs.GetArray() == rhs.GetArray(), "Mismatched arrays in iterator comparison.");              \ 
  661       lhs.GetTupleId() == rhs.GetTupleId(), "Mismatched tuple ids in iterator comparison.");       \ 
  662     VTK_ITER_ASSUME(lhs.GetNumComps().value > 0);                                                  \ 
  663     VTK_ITER_ASSUME(lhs.GetNumComps().value == rhs.GetNumComps().value);                           \ 
  664     return lhs.GetComponentId() OP rhs.GetComponentId();                                           \ 
  674 #undef VTK_TMP_MAKE_OPERATOR 
  680     VTK_ITER_ASSERT(this->
Ref.ComponentId >= 0 && this->Ref.ComponentId <= this->Ref.NumComps.value,
 
  681       "Component iterator at invalid component id.");
 
  689       it.GetComponentId() + 
offset };
 
  696       it.GetComponentId() + 
offset };
 
  703     VTK_ITER_ASSERT(this->
Ref.ComponentId >= 0 && this->Ref.ComponentId <= this->Ref.NumComps.value,
 
  704       "Component iterator at invalid component id.");
 
  712       it.GetComponentId() - 
offset };
 
  719       "Cannot do math with component iterators from different " 
  722       "Cannot do math with component iterators from different " 
  724     return it1.GetComponentId() - it2.GetComponentId();
 
  731       lhs.GetArray() == rhs.GetArray(), 
"Cannot swap iterators from different arrays.");
 
  734     swap(lhs.GetTupleId(), rhs.GetTupleId());
 
  735     swap(lhs.GetComponentId(), rhs.GetComponentId());
 
  751   ComponentReference<ArrayType, TupleSize> 
Ref;
 
  756 template <
typename ArrayType, ComponentIdType TupleSize>
 
  789       "Const tuple reference at invalid tuple id.");
 
  822   template <
typename OArrayType, ComponentIdType OSize>
 
  829       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
  832     static_assert(TupleSize == OSize, 
"Cannot compare tuples with different sizes.");
 
  834     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
  838   template <
typename OArrayType, ComponentIdType OSize>
 
  845       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
  848       other.size() == this->NumComps.value, 
"Cannot compare tuples with different sizes.");
 
  850     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
  854   template <
typename OArrayType, ComponentIdType OSize>
 
  861       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
  864     static_assert(TupleSize == OSize, 
"Cannot compare tuples with different sizes.");
 
  866     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
  870   template <
typename OArrayType, ComponentIdType OSize>
 
  877       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
  880       other.size() == this->NumComps.value, 
"Cannot compare tuples with different sizes.");
 
  882     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
  885   template <
typename OArrayType, ComponentIdType OSize>
 
  888     return !(*
this == o);
 
  891   template <
typename OArrayT, ComponentIdType OSize>
 
  894     return !(*
this == o);
 
  946 template <
typename ArrayType, ComponentIdType TupleSize>
 
  980       "Tuple reference at invalid tuple id.");
 
 1001     acc.Get(this->
TupleId, tuple);
 
 1011     acc.Set(this->
TupleId, tuple);
 
 1017     std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
 
 1022   template <
typename OArrayType, ComponentIdType OSize>
 
 1029       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when assigning tuples.");
 
 1032     static_assert(TupleSize == OSize, 
"Cannot assign tuples with different sizes.");
 
 1034     std::copy_n(other.cbegin(), OSize, this->begin());
 
 1039   template <
typename OArrayType, ComponentIdType OSize>
 
 1046       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when assigning tuples.");
 
 1049       other.size() == this->NumComps.value, 
"Cannot assign tuples with different sizes.");
 
 1051     std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
 
 1056   template <
typename OArrayType, ComponentIdType OSize>
 
 1063       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when assigning tuples.");
 
 1066     static_assert(TupleSize == OSize, 
"Cannot assign tuples with different sizes.");
 
 1068     std::copy_n(other.cbegin(), OSize, this->begin());
 
 1073   template <
typename OArrayType, ComponentIdType OSize>
 
 1080       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when assigning tuples.");
 
 1083       other.size() == this->NumComps.value, 
"Cannot assign tuples with different sizes.");
 
 1085     std::copy_n(other.cbegin(), this->NumComps.value, this->begin());
 
 1090   template <
typename OArrayType, ComponentIdType OSize>
 
 1097       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
 1100     static_assert(TupleSize == OSize, 
"Cannot compare tuples with different sizes.");
 
 1102     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
 1106   template <
typename OArrayType, ComponentIdType OSize>
 
 1113       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
 1116       other.size() == this->NumComps.value, 
"Cannot compare tuples with different sizes.");
 
 1118     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
 1122   template <
typename OArrayType, ComponentIdType OSize>
 
 1129       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
 1132     static_assert(TupleSize == OSize, 
"Cannot compare tuples with different sizes.");
 
 1134     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
 1138   template <
typename OArrayType, ComponentIdType OSize>
 
 1145       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when comparing tuples.");
 
 1148       other.size() == this->NumComps.value, 
"Cannot compare tuples with different sizes.");
 
 1150     return std::equal(this->
cbegin(), this->
cend(), other.cbegin());
 
 1153   template <
typename OArrayType, ComponentIdType OSize>
 
 1156     return !(*
this == o);
 
 1159   template <
typename OArray, ComponentIdType OSize>
 
 1162     return !(*
this == o);
 
 1166   template <
typename OArrayType, ComponentIdType OSize>
 
 1173       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when swapping tuples.");
 
 1176     static_assert(TupleSize == OSize, 
"Cannot swap tuples with different sizes.");
 
 1178     std::swap_ranges(this->
begin(), this->
end(), other.begin());
 
 1182   template <
typename OArrayType, ComponentIdType OSize>
 
 1189       (std::is_convertible<OAPIType, APIType>{}), 
"Incompatible types when swapping tuples.");
 
 1192       other.size() == this->NumComps.value, 
"Cannot swap tuples with different sizes.");
 
 1194     std::swap_ranges(this->
begin(), this->
end(), other.begin());
 
 1199   template <
typename OArray, ComponentIdType OSize>
 
 1273 template <
typename ArrayType, ComponentIdType TupleSize>
 
 1275   : 
public std::iterator<std::random_access_iterator_tag, ConstTupleReference<ArrayType, TupleSize>,
 
 1276       TupleIdType, ConstTupleReference<ArrayType, TupleSize>,
 
 1277       ConstTupleReference<ArrayType, TupleSize> >
 
 1284   using Superclass = std::iterator<std::random_access_iterator_tag,
 
 1300     : Ref(array, numComps, tupleId)
 
 1304     VTK_ITER_ASSERT(tupleId >= 0 && tupleId <= array->GetNumberOfTuples(),
 
 1305       "Const tuple iterator at invalid tuple id.");
 
 1316     this->Ref.CopyReference(o.Ref);
 
 1323     ++this->Ref.TupleId;
 
 1325       this->Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1326       "Const tuple iterator at invalid component id.");
 
 1333     return ConstTupleIterator{ this->Ref.Array, this->Ref.NumComps, this->Ref.TupleId++ };
 
 1339     --this->Ref.TupleId;
 
 1341       this->Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1342       "Const tuple iterator at invalid component id.");
 
 1349     return ConstTupleIterator{ this->Ref.Array, this->Ref.NumComps, this->Ref.TupleId-- };
 
 1355     return reference{ this->GetArray(), this->GetNumComps(), this->GetTupleId() + i };
 
 1364 #define VTK_TMP_MAKE_OPERATOR(OP)                                                                  \ 
 1365   friend VTK_ITER_INLINE bool operator OP(                                                         \ 
 1366     const ConstTupleIterator& lhs, const ConstTupleIterator& rhs) noexcept                         \ 
 1369       lhs.GetArray() == rhs.GetArray(), "Cannot compare iterators from different arrays.");        \ 
 1370     VTK_ITER_ASSUME(lhs.GetNumComps().value > 0);                                                  \ 
 1371     VTK_ITER_ASSUME(lhs.GetNumComps().value == rhs.GetNumComps().value);                           \ 
 1372     return lhs.GetTupleId() OP rhs.GetTupleId();                                                   \ 
 1382 #undef VTK_TMP_MAKE_OPERATOR 
 1387     this->Ref.TupleId += 
offset;
 
 1389       this->Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1390       "Const tuple iterator at invalid component id.");
 
 1409     this->Ref.TupleId -= 
offset;
 
 1411       this->Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1412       "Const tuple iterator at invalid component id.");
 
 1426       "Cannot do math with tuple iterators from different " 
 1428     return it1.GetTupleId() - it2.GetTupleId();
 
 1435       lhs.GetArray() == rhs.GetArray(), 
"Cannot swap iterators from different arrays.");
 
 1438     swap(lhs.GetTupleId(), rhs.GetTupleId());
 
 1443   ArrayType* GetArray() const noexcept { 
return this->Ref.Array; }
 
 1445   ArrayType*& GetArray() noexcept { 
return this->Ref.Array; }
 
 1447   NumCompsType GetNumComps() const noexcept { 
return this->Ref.NumComps; }
 
 1449   NumCompsType& GetNumComps() noexcept { 
return this->Ref.NumComps; }
 
 1451   TupleIdType GetTupleId() const noexcept { 
return this->Ref.TupleId; }
 
 1453   TupleIdType& GetTupleId() noexcept { 
return this->Ref.TupleId; }
 
 1455   ConstTupleReference<ArrayType, TupleSize> Ref;
 
 1460 template <
typename ArrayType, ComponentIdType TupleSize>
 
 1461 struct TupleIterator
 
 1462   : 
public std::iterator<std::random_access_iterator_tag, TupleReference<ArrayType, TupleSize>,
 
 1463       TupleIdType, TupleReference<ArrayType, TupleSize>, TupleReference<ArrayType, TupleSize> >
 
 1469   using NumCompsType = GenericTupleSize<TupleSize>;
 
 1471     std::iterator<std::random_access_iterator_tag, TupleReference<ArrayType, TupleSize>,
 
 1472       TupleIdType, TupleReference<ArrayType, TupleSize>, TupleReference<ArrayType, TupleSize> >;
 
 1486     : 
Ref(array, numComps, tupleId)
 
 1491       tupleId >= 0 && tupleId <= array->GetNumberOfTuples(), 
"Tuple iterator at invalid tuple id.");
 
 1500     this->
Ref.CopyReference(o.Ref);
 
 1507     ++this->
Ref.TupleId;
 
 1509       this->
Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1510       "Tuple iterator at invalid component id.");
 
 1523     --this->
Ref.TupleId;
 
 1525       this->
Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1526       "Tuple iterator at invalid component id.");
 
 1548 #define VTK_TMP_MAKE_OPERATOR(OP)                                                                  \ 
 1549   friend VTK_ITER_INLINE bool operator OP(const TupleIterator& lhs, const TupleIterator& rhs)      \ 
 1553       lhs.GetArray() == rhs.GetArray(), "Cannot compare iterators from different arrays.");        \ 
 1554     VTK_ITER_ASSUME(lhs.GetNumComps().value > 0);                                                  \ 
 1555     VTK_ITER_ASSUME(lhs.GetNumComps().value == rhs.GetNumComps().value);                           \ 
 1556     return lhs.GetTupleId() OP rhs.GetTupleId();                                                   \ 
 1566 #undef VTK_TMP_MAKE_OPERATOR 
 1573       this->
Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1574       "Tuple iterator at invalid component id.");
 
 1595       this->
Ref.TupleId >= 0 && this->Ref.TupleId <= this->Ref.Array->GetNumberOfTuples(),
 
 1596       "Tuple iterator at invalid component id.");
 
 1610       "Cannot do math with tuple iterators from different " 
 1612     return it1.GetTupleId() - it2.GetTupleId();
 
 1619       lhs.GetArray() == rhs.GetArray(), 
"Cannot swap iterators from different arrays.");
 
 1622     swap(lhs.GetTupleId(), rhs.GetTupleId());
 
 1642   TupleReference<ArrayType, TupleSize> 
Ref;
 
 1647 template <
typename ArrayTypeT, ComponentIdType TupleSize>
 
 1684     , BeginTuple(beginTuple)
 
 1685     , EndTuple(endTuple)
 
 1687     assert(this->Array);
 
 1688     assert(beginTuple >= 0 && beginTuple <= endTuple);
 
 1689     assert(endTuple >= 0 && endTuple <= this->Array->GetNumberOfTuples());
 
 1695     const TupleIdType realBegin = this->BeginTuple + beginTuple;
 
 1696     const TupleIdType realEnd = endTuple >= 0 ? this->BeginTuple + endTuple : this->EndTuple;
 
 1698     return TupleRange{ this->Array, realBegin, realEnd };
 
 1731     return reference{ this->Array, this->NumComps, this->BeginTuple + i };
 
 1737     return const_reference{ this->Array, this->NumComps, this->BeginTuple + i };
 
 1751   NumCompsType NumComps{};
 
 1757 template <
typename ArrayType, ComponentIdType TupleSize>
 
 1765 #endif // __VTK_WRAP__ 
 1766 #endif // vtkDataArrayTupleRange_Generic_h