VTK-m  2.2
ArrayPortalToIterators.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_ArrayPortalToIterators_h
11 #define vtk_m_cont_ArrayPortalToIterators_h
12 
13 #include <vtkm/cont/ArrayPortal.h>
15 
17 
18 #include <vtkmstd/void_t.h>
19 
20 namespace vtkm
21 {
22 namespace cont
23 {
24 
25 template <typename PortalType,
26  typename CustomIterators = vtkm::internal::PortalSupportsIterators<PortalType>>
28 
41 template <typename PortalType>
42 class ArrayPortalToIterators<PortalType, std::false_type>
43 {
44 public:
50  explicit ArrayPortalToIterators(const PortalType& portal)
51  : Portal(portal)
52  {
53  }
54 
55  // These are the same as the default implementation, but explicitly created to prevent warnings
56  // from the CUDA compiler where it tries to compile for the device when the underlying portal
57  // only works for the host.
61  : Portal(src.Portal)
62  {
63  }
67  : Portal(std::move(rhs.Portal))
68  {
69  }
76  {
77  this->Portal = src.Portal;
78  return *this;
79  }
83  {
84  this->Portal = std::move(rhs.Portal);
85  return *this;
86  }
87 
90  using IteratorType = vtkm::cont::internal::IteratorFromArrayPortal<PortalType>;
91 
96  IteratorType GetBegin() const { return vtkm::cont::internal::make_IteratorBegin(this->Portal); }
97 
102  IteratorType GetEnd() const { return vtkm::cont::internal::make_IteratorEnd(this->Portal); }
103 
104 private:
105  PortalType Portal;
106 };
107 
108 // Specialize for custom iterator types:
109 template <typename PortalType>
110 class ArrayPortalToIterators<PortalType, std::true_type>
111 {
112 public:
113  using IteratorType = decltype(std::declval<PortalType>().GetIteratorBegin());
114 
117  explicit ArrayPortalToIterators(const PortalType& portal)
118  : Begin(portal.GetIteratorBegin())
119  , End(portal.GetIteratorEnd())
120  {
121  }
122 
125  IteratorType GetBegin() const { return this->Begin; }
126 
129  IteratorType GetEnd() const { return this->End; }
130 
131  // These are the same as the default implementation, but explicitly created to prevent warnings
132  // from the CUDA compiler where it tries to compile for the device when the underlying portal
133  // only works for the host.
137  : Begin(src.Begin)
138  , End(src.End)
139  {
140  }
144  : Begin(std::move(rhs.Begin))
145  , End(std::move(rhs.End))
146  {
147  }
154  {
155  this->Begin = src.Begin;
156  this->End = src.End;
157  return *this;
158  }
162  {
163  this->Begin = std::move(rhs.Begin);
164  this->End = std::move(rhs.End);
165  return *this;
166  }
167 
168 private:
171 };
172 
176 template <typename PortalType>
178 ArrayPortalToIteratorBegin(const PortalType& portal)
179 {
181  return iterators.GetBegin();
182 }
183 
187 template <typename PortalType>
189 ArrayPortalToIteratorEnd(const PortalType& portal)
190 {
192  return iterators.GetEnd();
193 }
194 }
195 } // namespace vtkm::cont
196 
197 #endif //vtk_m_cont_ArrayPortalToIterators_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::IteratorType
decltype(std::declval< PortalType >().GetIteratorBegin()) IteratorType
Definition: ArrayPortalToIterators.h:113
ArrayPortalHelpers.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::IteratorType
vtkm::cont::internal::IteratorFromArrayPortal< PortalType > IteratorType
The type of the iterator.
Definition: ArrayPortalToIterators.h:90
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:136
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::Begin
IteratorType Begin
Definition: ArrayPortalToIterators.h:169
IteratorFromArrayPortal.h
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::operator=
ArrayPortalToIterators & operator=(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:161
vtkm::cont::ArrayPortalToIteratorEnd
vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorEnd(const PortalType &portal)
Convenience function for converting an ArrayPortal to an end iterator.
Definition: ArrayPortalToIterators.h:189
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::GetEnd
IteratorType GetEnd() const
Returns an iterator pointing to one past the end of the ArrayPortal.
Definition: ArrayPortalToIterators.h:102
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::operator=
ArrayPortalToIterators & operator=(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:82
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::Portal
PortalType Portal
Definition: ArrayPortalToIterators.h:105
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::ArrayPortalToIterators
ArrayPortalToIterators(const PortalType &portal)
ArrayPortaltoIterators should be constructed with an instance of the array portal.
Definition: ArrayPortalToIterators.h:50
ArrayPortal.h
vtkm::cont::ArrayPortalToIterators
Definition: ArrayPortalToIterators.h:27
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::~ArrayPortalToIterators
~ArrayPortalToIterators()
Definition: ArrayPortalToIterators.h:150
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::ArrayPortalToIterators
ArrayPortalToIterators(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:60
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::GetBegin
IteratorType GetBegin() const
Returns an iterator pointing to the beginning of the ArrayPortal.
Definition: ArrayPortalToIterators.h:96
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::~ArrayPortalToIterators
~ArrayPortalToIterators()
Definition: ArrayPortalToIterators.h:72
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(const PortalType &portal)
Definition: ArrayPortalToIterators.h:117
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::operator=
ArrayPortalToIterators & operator=(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:75
vtkm::cont::ArrayPortalToIteratorBegin
vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:178
vtkm::cont::ArrayPortalToIterators< PortalType, std::false_type >::ArrayPortalToIterators
ArrayPortalToIterators(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:66
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:143
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::GetBegin
IteratorType GetBegin() const
Definition: ArrayPortalToIterators.h:125
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::operator=
ArrayPortalToIterators & operator=(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:153
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::GetEnd
IteratorType GetEnd() const
Definition: ArrayPortalToIterators.h:129
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
vtkm::cont::ArrayPortalToIterators< PortalType, std::true_type >::End
IteratorType End
Definition: ArrayPortalToIterators.h:170