Viskores  1.0
ArrayPortalToIterators.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_ArrayPortalToIterators_h
19 #define viskores_cont_ArrayPortalToIterators_h
20 
23 
25 
26 #include <viskoresstd/void_t.h>
27 
28 namespace viskores
29 {
30 namespace cont
31 {
32 
33 template <typename PortalType,
34  typename CustomIterators = viskores::internal::PortalSupportsIterators<PortalType>>
36 
49 template <typename PortalType>
50 class ArrayPortalToIterators<PortalType, std::false_type>
51 {
52 public:
58  explicit ArrayPortalToIterators(const PortalType& portal)
59  : Portal(portal)
60  {
61  }
62 
63  // These are the same as the default implementation, but explicitly created to prevent warnings
64  // from the CUDA compiler where it tries to compile for the device when the underlying portal
65  // only works for the host.
69  : Portal(src.Portal)
70  {
71  }
75  : Portal(std::move(rhs.Portal))
76  {
77  }
84  {
85  this->Portal = src.Portal;
86  return *this;
87  }
91  {
92  this->Portal = std::move(rhs.Portal);
93  return *this;
94  }
95 
98  using IteratorType = viskores::cont::internal::IteratorFromArrayPortal<PortalType>;
99 
105  {
106  return viskores::cont::internal::make_IteratorBegin(this->Portal);
107  }
108 
113  IteratorType GetEnd() const { return viskores::cont::internal::make_IteratorEnd(this->Portal); }
114 
115 private:
116  PortalType Portal;
117 };
118 
119 // Specialize for custom iterator types:
120 template <typename PortalType>
121 class ArrayPortalToIterators<PortalType, std::true_type>
122 {
123 public:
124  using IteratorType = decltype(std::declval<PortalType>().GetIteratorBegin());
125 
128  explicit ArrayPortalToIterators(const PortalType& portal)
129  : Begin(portal.GetIteratorBegin())
130  , End(portal.GetIteratorEnd())
131  {
132  }
133 
136  IteratorType GetBegin() const { return this->Begin; }
137 
140  IteratorType GetEnd() const { return this->End; }
141 
142  // These are the same as the default implementation, but explicitly created to prevent warnings
143  // from the CUDA compiler where it tries to compile for the device when the underlying portal
144  // only works for the host.
148  : Begin(src.Begin)
149  , End(src.End)
150  {
151  }
155  : Begin(std::move(rhs.Begin))
156  , End(std::move(rhs.End))
157  {
158  }
165  {
166  this->Begin = src.Begin;
167  this->End = src.End;
168  return *this;
169  }
173  {
174  this->Begin = std::move(rhs.Begin);
175  this->End = std::move(rhs.End);
176  return *this;
177  }
178 
179 private:
182 };
183 
187 template <typename PortalType>
189 ArrayPortalToIteratorBegin(const PortalType& portal)
190 {
192  return iterators.GetBegin();
193 }
194 
198 template <typename PortalType>
200 ArrayPortalToIteratorEnd(const PortalType& portal)
201 {
203  return iterators.GetEnd();
204 }
205 }
206 } // namespace viskores::cont
207 
208 #endif //viskores_cont_ArrayPortalToIterators_h
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::ArrayPortalToIterators
ArrayPortalToIterators(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:74
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::ArrayPortalToIterators
ArrayPortalToIterators(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:68
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::GetEnd
IteratorType GetEnd() const
Definition: ArrayPortalToIterators.h:140
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:147
ArrayPortalHelpers.h
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::Begin
IteratorType Begin
Definition: ArrayPortalToIterators.h:180
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::operator=
ArrayPortalToIterators & operator=(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:172
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
IteratorFromArrayPortal.h
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::~ArrayPortalToIterators
~ArrayPortalToIterators()
Definition: ArrayPortalToIterators.h:161
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::IteratorType
viskores::cont::internal::IteratorFromArrayPortal< PortalType > IteratorType
The type of the iterator.
Definition: ArrayPortalToIterators.h:98
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(const PortalType &portal)
Definition: ArrayPortalToIterators.h:128
viskores::cont::ArrayPortalToIteratorEnd
viskores::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorEnd(const PortalType &portal)
Convenience function for converting an ArrayPortal to an end iterator.
Definition: ArrayPortalToIterators.h:200
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
viskores::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:113
ArrayPortal.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::End
IteratorType End
Definition: ArrayPortalToIterators.h:181
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::~ArrayPortalToIterators
~ArrayPortalToIterators()
Definition: ArrayPortalToIterators.h:80
viskores::cont::ArrayPortalToIteratorBegin
viskores::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:189
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::GetBegin
IteratorType GetBegin() const
Definition: ArrayPortalToIterators.h:136
viskores::cont::ArrayPortalToIterators
Definition: ArrayPortalToIterators.h:35
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::GetBegin
IteratorType GetBegin() const
Returns an iterator pointing to the beginning of the ArrayPortal.
Definition: ArrayPortalToIterators.h:104
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::ArrayPortalToIterators
ArrayPortalToIterators(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:154
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::operator=
ArrayPortalToIterators & operator=(ArrayPortalToIterators &&rhs)
Definition: ArrayPortalToIterators.h:90
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::operator=
ArrayPortalToIterators & operator=(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:164
viskores::cont::ArrayPortalToIterators< PortalType, std::true_type >::IteratorType
decltype(std::declval< PortalType >().GetIteratorBegin()) IteratorType
Definition: ArrayPortalToIterators.h:124
viskores::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:58
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::Portal
PortalType Portal
Definition: ArrayPortalToIterators.h:116
viskores::cont::ArrayPortalToIterators< PortalType, std::false_type >::operator=
ArrayPortalToIterators & operator=(const ArrayPortalToIterators &src)
Definition: ArrayPortalToIterators.h:83