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>& buffers)
135 return buffers[0].GetMetaData<ArrayPortalType>().GetNumberOfValues();
138 VTKM_CONT static ReadPortalType CreateReadPortal(
139 const std::vector<vtkm::cont::internal::Buffer>& buffers,
143 return buffers[0].GetMetaData<ArrayPortalType>();
154 template <
typename FunctorType>
155 struct ArrayHandleImplicitTraits
157 using ValueType = decltype(FunctorType{}(
vtkm::Id{}));
158 using PortalType = vtkm::internal::ArrayPortalImplicit<FunctorType>;
161 using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
173 template <
class FunctorType>
175 :
public detail::ArrayHandleImplicitTraits<FunctorType>::Superclass
178 using ArrayTraits =
typename detail::ArrayHandleImplicitTraits<FunctorType>;
184 (
typename ArrayTraits::Superclass));
188 : Superclass(internal::PortalToArrayHandleImplicitBuffers(
PortalType(functor, length)))
197 template <
typename FunctorType>
214 template <
typename Functor>
215 struct SerializableTypeString<
vtkm::cont::ArrayHandleImplicit<Functor>>
224 template <
typename Functor>
225 struct SerializableTypeString<
vtkm::cont::ArrayHandle<
226 typename vtkm::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
227 vtkm::cont::StorageTagImplicit<vtkm::internal::ArrayPortalImplicit<Functor>>>>
228 : SerializableTypeString<vtkm::cont::ArrayHandleImplicit<Functor>>
237 template <
typename Functor>
238 struct Serialization<
vtkm::cont::ArrayHandleImplicit<Functor>>
245 static VTKM_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
247 vtkmdiy::save(bb, obj.GetNumberOfValues());
248 vtkmdiy::save(bb, obj.ReadPortal().GetFunctor());
263 template <
typename Functor>
264 struct Serialization<
vtkm::cont::ArrayHandle<
265 typename vtkm::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
266 vtkm::cont::StorageTagImplicit<vtkm::internal::ArrayPortalImplicit<Functor>>>>
267 : Serialization<vtkm::cont::ArrayHandleImplicit<Functor>>
274 #endif //vtk_m_cont_ArrayHandleImplicit_h