VTK-m  2.0
UncertainArrayHandle.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_UncertainArrayHandle_h
11 #define vtk_m_cont_UncertainArrayHandle_h
12 
13 #include <vtkm/cont/CastAndCall.h>
15 
16 namespace vtkm
17 {
18 namespace cont
19 {
20 
38 template <typename ValueTypeList, typename StorageTypeList>
40 {
41  VTKM_IS_LIST(ValueTypeList);
42  VTKM_IS_LIST(StorageTypeList);
43 
44  VTKM_STATIC_ASSERT_MSG((!std::is_same<ValueTypeList, vtkm::ListUniversal>::value),
45  "Cannot use vtkm::ListUniversal with UncertainArrayHandle.");
46  VTKM_STATIC_ASSERT_MSG((!std::is_same<StorageTypeList, vtkm::ListUniversal>::value),
47  "Cannot use vtkm::ListUniversal with UncertainArrayHandle.");
48 
51 
52 public:
53  VTKM_CONT UncertainArrayHandle() = default;
54 
55  template <typename T, typename S>
57  : Superclass(array)
58  {
59  }
60 
62  : Superclass(src)
63  {
64  }
65 
66  template <typename OtherValues, typename OtherStorage>
68  : Superclass(src)
69  {
70  }
71 
78  VTKM_CONT Thisclass NewInstance() const { return Thisclass(this->Superclass::NewInstance()); }
79 
82  template <typename NewValueTypeList>
84  NewValueTypeList = NewValueTypeList{}) const
85  {
86  return this->ResetTypes<NewValueTypeList, StorageTypeList>();
87  }
88 
91  template <typename NewStorageTypeList>
93  NewStorageTypeList = NewStorageTypeList{}) const
94  {
95  return this->ResetTypes<ValueTypeList, NewStorageTypeList>();
96  }
97 
103  template <typename Functor, typename... Args>
104  VTKM_CONT void CastAndCall(Functor&& functor, Args&&... args) const
105  {
106  this->CastAndCallForTypes<ValueTypeList, StorageTypeList>(std::forward<Functor>(functor),
107  std::forward<Args>(args)...);
108  }
109 
118  template <typename Functor, typename... Args>
119  VTKM_CONT void CastAndCallWithFloatFallback(Functor&& functor, Args&&... args) const
120  {
121  this->template CastAndCallForTypesWithFloatFallback<ValueTypeList, StorageTypeList>(
122  std::forward<Functor>(functor), std::forward<Args>(args)...);
123  }
124 };
125 
126 // Defined here to avoid circular dependencies between UnknownArrayHandle and UncertainArrayHandle.
127 template <typename NewValueTypeList, typename NewStorageTypeList>
129  UnknownArrayHandle::ResetTypes(NewValueTypeList, NewStorageTypeList) const
130 {
132 }
133 
134 namespace internal
135 {
136 
137 template <typename ValueTypeList, typename StorageTypeList>
138 struct DynamicTransformTraits<vtkm::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
139 {
140  using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
141 };
142 
143 } // namespace internal
144 
145 }
146 } // namespace vtkm::cont
147 
148 //=============================================================================
149 // Specializations of serialization related classes
151 
152 namespace vtkm
153 {
154 namespace cont
155 {
156 
157 template <typename ValueTypeList, typename StorageTypeList>
158 struct SerializableTypeString<vtkm::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
159 {
160  static VTKM_CONT std::string Get() { return "UncertainAH"; }
161 };
162 }
163 } // namespace vtkm::cont
164 
165 namespace mangled_diy_namespace
166 {
167 
168 namespace internal
169 {
170 
171 struct UncertainArrayHandleSerializeFunctor
172 {
173  template <typename ArrayHandleType>
174  void operator()(const ArrayHandleType& ah, BinaryBuffer& bb) const
175  {
177  vtkmdiy::save(bb, ah);
178  }
179 };
180 
181 struct UncertainArrayHandleDeserializeFunctor
182 {
183  template <typename T, typename S>
184  void operator()(vtkm::List<T, S>,
185  vtkm::cont::UnknownArrayHandle& unknownArray,
186  const std::string& typeString,
187  bool& success,
188  BinaryBuffer& bb) const
189  {
190  using ArrayHandleType = vtkm::cont::ArrayHandle<T, S>;
191 
192  if (!success && (typeString == vtkm::cont::SerializableTypeString<ArrayHandleType>::Get()))
193  {
194  ArrayHandleType knownArray;
195  vtkmdiy::load(bb, knownArray);
196  unknownArray = knownArray;
197  success = true;
198  }
199  }
200 };
201 
202 } // internal
203 
204 template <typename ValueTypeList, typename StorageTypeList>
205 struct Serialization<vtkm::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
206 {
208 
209 public:
210  static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj)
211  {
212  obj.CastAndCall(internal::UncertainArrayHandleSerializeFunctor{}, bb);
213  }
214 
215  static VTKM_CONT void load(BinaryBuffer& bb, Type& obj)
216  {
217  std::string typeString;
218  vtkmdiy::load(bb, typeString);
219 
220  bool success = false;
221  vtkm::ListForEach(internal::UncertainArrayHandleDeserializeFunctor{},
222  vtkm::cont::internal::ListAllArrayTypes<ValueTypeList, StorageTypeList>{},
223  obj,
224  typeString,
225  success,
226  bb);
227 
228  if (!success)
229  {
231  "Error deserializing Unknown/UncertainArrayHandle. Message TypeString: " + typeString);
232  }
233  }
234 };
235 
236 } // namespace mangled_diy_namespace
237 
239 
240 #endif //vtk_m_cont_UncertainArrayHandle_h
vtkm::cont::ArrayHandle< T, S >
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::UncertainArrayHandle::UncertainArrayHandle
VTKM_CONT UncertainArrayHandle(const UncertainArrayHandle< OtherValues, OtherStorage > &src)
Definition: UncertainArrayHandle.h:67
vtkm::Get
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT auto Get(const vtkm::Tuple< Ts... > &tuple) -> decltype(tuple.template Get< Index >())
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:83
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
vtkm::ListForEach
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT void ListForEach(Functor &&f, vtkm::List< Ts... >, Args &&... args)
Definition: List.h:720
vtkm::cont::UncertainArrayHandle::ResetStorageTypes
VTKM_CONT UncertainArrayHandle< ValueTypeList, NewStorageTypeList > ResetStorageTypes(NewStorageTypeList=NewStorageTypeList{}) const
Like ResetTypes except it only resets the storage types.
Definition: UncertainArrayHandle.h:92
vtkm::cont::ErrorBadType
This class is thrown when VTK-m encounters data of a type that is incompatible with the current opera...
Definition: ErrorBadType.h:25
mangled_diy_namespace
Definition: Particle.h:331
vtkm::exec::arg::load
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm::cont::UncertainArrayHandle::UncertainArrayHandle
VTKM_CONT UncertainArrayHandle(const vtkm::cont::UnknownArrayHandle &src)
Definition: UncertainArrayHandle.h:61
vtkm::cont::UncertainArrayHandle::CastAndCall
VTKM_CONT void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type.
Definition: UncertainArrayHandle.h:104
UnknownArrayHandle.h
CastAndCall.h
vtkm::cont::UncertainArrayHandle::NewInstance
VTKM_CONT Thisclass NewInstance() const
Create a new array of the same type as this array.
Definition: UncertainArrayHandle.h:78
VTKM_STATIC_ASSERT_MSG
#define VTKM_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:18
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::UncertainArrayHandle::CastAndCallWithFloatFallback
VTKM_CONT void CastAndCallWithFloatFallback(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type with a float cast fallback.
Definition: UncertainArrayHandle.h:119
vtkm::cont::UncertainArrayHandle::UncertainArrayHandle
VTKM_CONT UncertainArrayHandle(const vtkm::cont::ArrayHandle< T, S > &array)
Definition: UncertainArrayHandle.h:56
vtkm::cont::UncertainArrayHandle
An ArrayHandle of an uncertain value type and storage.
Definition: UncertainArrayHandle.h:39
vtkm::cont::UnknownArrayHandle::ResetTypes
VTKM_CONT vtkm::cont::UncertainArrayHandle< NewValueTypeList, NewStorageTypeList > ResetTypes(NewValueTypeList=NewValueTypeList{}, NewStorageTypeList=NewStorageTypeList{}) const
Assigns potential value and storage types.
Definition: UncertainArrayHandle.h:129
VTKM_IS_LIST
#define VTKM_IS_LIST(type)
Checks that the argument is a proper list.
Definition: List.h:64
vtkm::List
Definition: List.h:34
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
vtkm::cont::UncertainArrayHandle::ResetValueTypes
VTKM_CONT UncertainArrayHandle< NewValueTypeList, StorageTypeList > ResetValueTypes(NewValueTypeList=NewValueTypeList{}) const
Like ResetTypes except it only resets the value types.
Definition: UncertainArrayHandle.h:83