10 #ifndef vtk_m_cont_internal_IteratorFromArrayPortal_h
11 #define vtk_m_cont_internal_IteratorFromArrayPortal_h
24 template <
class ArrayPortalType>
25 class IteratorFromArrayPortal
28 using value_type =
typename std::remove_const<typename ArrayPortalType::ValueType>::type;
29 using reference = vtkm::internal::ArrayPortalValueReference<ArrayPortalType>;
30 using pointer =
typename std::add_pointer<value_type>::type;
32 using difference_type = std::ptrdiff_t;
34 using iterator_category = std::random_access_iterator_tag;
36 using iter = IteratorFromArrayPortal<ArrayPortalType>;
40 IteratorFromArrayPortal()
48 explicit IteratorFromArrayPortal(
const ArrayPortalType& portal,
vtkm::Id index = 0)
57 reference
operator*()
const {
return reference(this->Portal, this->
Index); }
60 reference operator->()
const {
return reference(this->Portal, this->
Index); }
63 reference operator[](difference_type idx)
const
65 return reference(this->Portal, this->
Index +
static_cast<vtkm::Id>(idx));
72 VTKM_ASSERT(this->Index <= this->Portal.GetNumberOfValues());
77 iter operator++(
int) {
return iter(this->Portal, this->
Index++); }
88 iter operator--(
int) {
return iter(this->Portal, this->
Index--); }
91 iter& operator+=(difference_type n)
94 VTKM_ASSERT(this->Index <= this->Portal.GetNumberOfValues());
99 iter& operator-=(difference_type n)
109 return iter(this->Portal, this->
Index -
static_cast<vtkm::Id>(n));
112 ArrayPortalType Portal;
116 template <
class ArrayPortalType>
117 VTKM_EXEC_CONT IteratorFromArrayPortal<ArrayPortalType> make_IteratorBegin(
118 const ArrayPortalType& portal)
120 return IteratorFromArrayPortal<ArrayPortalType>(portal, 0);
123 template <
class ArrayPortalType>
124 VTKM_EXEC_CONT IteratorFromArrayPortal<ArrayPortalType> make_IteratorEnd(
125 const ArrayPortalType& portal)
127 return IteratorFromArrayPortal<ArrayPortalType>(portal, portal.GetNumberOfValues());
130 template <
typename PortalType>
132 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
134 return lhs.Index == rhs.Index;
137 template <
typename PortalType>
139 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
141 return lhs.Index != rhs.Index;
144 template <
typename PortalType>
145 VTKM_EXEC_CONT bool operator<(vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& lhs,
146 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
148 return lhs.Index < rhs.Index;
151 template <
typename PortalType>
152 VTKM_EXEC_CONT bool operator<=(vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& lhs,
153 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
155 return lhs.Index <= rhs.Index;
158 template <
typename PortalType>
159 VTKM_EXEC_CONT bool operator>(vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& lhs,
160 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
162 return lhs.Index > rhs.Index;
165 template <
typename PortalType>
166 VTKM_EXEC_CONT bool operator>=(vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& lhs,
167 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
169 return lhs.Index >= rhs.Index;
172 template <
typename PortalType>
174 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& lhs,
175 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& rhs)
177 return lhs.Index - rhs.Index;
180 template <
typename PortalType>
182 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& iter,
185 return vtkm::cont::internal::IteratorFromArrayPortal<PortalType>(
186 iter.Portal, iter.Index +
static_cast<vtkm::Id>(n));
189 template <
typename PortalType>
192 vtkm::cont::internal::IteratorFromArrayPortal<PortalType>
const& iter)
194 return vtkm::cont::internal::IteratorFromArrayPortal<PortalType>(
195 iter.Portal, iter.Index +
static_cast<vtkm::Id>(n));
201 #endif //vtk_m_cont_internal_IteratorFromArrayPortal_h