18 #ifndef viskores_cont_ArrayHandleImplicit_h
19 #define viskores_cont_ArrayHandleImplicit_h
23 #include <viskoresstd/is_trivial.h>
40 template <
class FunctorType_>
41 class VISKORES_ALWAYS_EXPORT ArrayPortalImplicit
44 using FunctorType = FunctorType_;
45 using ValueType = decltype(FunctorType{}(
viskores::Id{}));
57 ArrayPortalImplicit(FunctorType f,
viskores::Id numValues)
59 , NumberOfValues(numValues)
64 const FunctorType& GetFunctor()
const {
return this->Functor; }
67 viskores::Id GetNumberOfValues()
const {
return this->NumberOfValues; }
71 ValueType
Get(
viskores::Id index)
const {
return this->Functor(index); }
93 template <
class ArrayPortalType>
104 template <
typename PortalType>
105 VISKORES_CONT inline std::vector<viskores::cont::internal::Buffer>
106 PortalToArrayHandleImplicitBuffers(
const PortalType& portal)
108 std::vector<viskores::cont::internal::Buffer> buffers(1);
109 buffers[0].SetMetaData(portal);
115 template <
typename FunctorType>
116 VISKORES_CONT inline std::vector<viskores::cont::internal::Buffer>
117 FunctorToArrayHandleImplicitBuffers(
const FunctorType& functor,
viskores::Id numValues)
119 return PortalToArrayHandleImplicitBuffers(
120 viskores::internal::ArrayPortalImplicit<FunctorType>(functor, numValues));
123 template <
class ArrayPortalType>
124 struct VISKORES_ALWAYS_EXPORT
125 Storage<typename ArrayPortalType::ValueType, StorageTagImplicit<ArrayPortalType>>
127 VISKORES_IS_TRIVIALLY_COPYABLE(ArrayPortalType);
132 using ReadPortalType = ArrayPortalType;
134 VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers()
136 return viskores::cont::internal::PortalToArrayHandleImplicitBuffers(ArrayPortalType{});
140 const std::vector<viskores::cont::internal::Buffer>&)
146 const std::vector<viskores::cont::internal::Buffer>& buffers)
148 return buffers[0].GetMetaData<ArrayPortalType>().GetNumberOfValues();
152 const std::vector<viskores::cont::internal::Buffer>& buffers,
156 return buffers[0].GetMetaData<ArrayPortalType>();
167 template <
typename FunctorType>
168 struct ArrayHandleImplicitTraits
170 using ValueType = decltype(FunctorType{}(
viskores::Id{}));
171 using PortalType = viskores::internal::ArrayPortalImplicit<FunctorType>;
185 template <
class FunctorType>
187 :
public detail::ArrayHandleImplicitTraits<FunctorType>
::Superclass
190 using ArrayTraits =
typename detail::ArrayHandleImplicitTraits<FunctorType>;
196 (
typename ArrayTraits::Superclass));
209 template <
typename FunctorType>
227 template <
typename Functor>
228 struct SerializableTypeString<
viskores::cont::ArrayHandleImplicit<Functor>>
237 template <
typename Functor>
238 struct SerializableTypeString<
viskores::cont::ArrayHandle<
239 typename viskores::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
240 viskores::cont::StorageTagImplicit<viskores::internal::ArrayPortalImplicit<Functor>>>>
241 : SerializableTypeString<viskores::cont::ArrayHandleImplicit<Functor>>
250 template <
typename Functor>
251 struct Serialization<
viskores::cont::ArrayHandleImplicit<Functor>>
258 static VISKORES_CONT void save(BinaryBuffer& bb,
const BaseType& obj)
260 viskoresdiy::save(bb, obj.GetNumberOfValues());
261 viskoresdiy::save(bb, obj.ReadPortal().GetFunctor());
276 template <
typename Functor>
277 struct Serialization<
viskores::cont::ArrayHandle<
278 typename viskores::cont::detail::ArrayHandleImplicitTraits<Functor>::ValueType,
279 viskores::cont::StorageTagImplicit<viskores::internal::ArrayPortalImplicit<Functor>>>>
280 : Serialization<viskores::cont::ArrayHandleImplicit<Functor>>
287 #endif //viskores_cont_ArrayHandleImplicit_h