10 #ifndef vtk_m_cont_ArrayHandleImplicit_h
11 #define vtk_m_cont_ArrayHandleImplicit_h
15 #include <vtkmstd/is_trivial.h>
32 template <
class FunctorType_>
36 using FunctorType = FunctorType_;
37 using ValueType = decltype(FunctorType{}(
vtkm::Id{}));
49 ArrayPortalImplicit(FunctorType f,
vtkm::Id numValues)
51 , NumberOfValues(numValues)
56 const FunctorType& GetFunctor()
const {
return this->Functor; }
59 vtkm::Id GetNumberOfValues()
const {
return this->NumberOfValues; }
63 ValueType
Get(
vtkm::Id index)
const {
return this->Functor(index); }
85 template <
class ArrayPortalType>
96 template <
typename PortalType>
97 VTKM_CONT inline std::vector<vtkm::cont::internal::Buffer> PortalToArrayHandleImplicitBuffers(
98 const PortalType& portal)
100 std::vector<vtkm::cont::internal::Buffer> buffers(1);
101 buffers[0].SetMetaData(portal);
107 template <
typename FunctorType>
108 VTKM_CONT inline std::vector<vtkm::cont::internal::Buffer> FunctorToArrayHandleImplicitBuffers(
109 const FunctorType& functor,
112 return PortalToArrayHandleImplicitBuffers(
113 vtkm::internal::ArrayPortalImplicit<FunctorType>(functor, numValues));
116 template <
class ArrayPortalType>
118 Storage<typename ArrayPortalType::ValueType, StorageTagImplicit<ArrayPortalType>>
120 VTKM_IS_TRIVIALLY_COPYABLE(ArrayPortalType);
125 using ReadPortalType = ArrayPortalType;
127 VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers()
129 return vtkm::cont::internal::PortalToArrayHandleImplicitBuffers(ArrayPortalType{});
133 const std::vector<vtkm::cont::internal::Buffer>&)
139 const std::vector<vtkm::cont::internal::Buffer>& buffers)
141 return buffers[0].GetMetaData<ArrayPortalType>().GetNumberOfValues();
144 VTKM_CONT static ReadPortalType CreateReadPortal(
145 const std::vector<vtkm::cont::internal::Buffer>& buffers,
149 return buffers[0].GetMetaData<ArrayPortalType>();
160 template <
typename FunctorType>
161 struct ArrayHandleImplicitTraits
163 using ValueType = decltype(FunctorType{}(
vtkm::Id{}));
164 using PortalType = vtkm::internal::ArrayPortalImplicit<FunctorType>;
178 template <
class FunctorType>
180 :
public detail::ArrayHandleImplicitTraits<FunctorType>
::Superclass
183 using ArrayTraits =
typename detail::ArrayHandleImplicitTraits<FunctorType>;
189 (
typename ArrayTraits::Superclass));
202 template <
typename FunctorType>
219 template <
typename Functor>
220 struct SerializableTypeString<
vtkm::cont::ArrayHandleImplicit<Functor>>
229 template <
typename Functor>
230 struct SerializableTypeString<
vtkm::cont::ArrayHandle<
231 typename vtkm::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
232 vtkm::cont::StorageTagImplicit<vtkm::internal::ArrayPortalImplicit<Functor>>>>
233 : SerializableTypeString<vtkm::cont::ArrayHandleImplicit<Functor>>
242 template <
typename Functor>
243 struct Serialization<
vtkm::cont::ArrayHandleImplicit<Functor>>
250 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
252 vtkmdiy::save(bb, obj.GetNumberOfValues());
253 vtkmdiy::save(bb, obj.ReadPortal().GetFunctor());
268 template <
typename Functor>
269 struct Serialization<
vtkm::cont::ArrayHandle<
270 typename vtkm::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
271 vtkm::cont::StorageTagImplicit<vtkm::internal::ArrayPortalImplicit<Functor>>>>
272 : Serialization<vtkm::cont::ArrayHandleImplicit<Functor>>
279 #endif //vtk_m_cont_ArrayHandleImplicit_h