VTK-m  2.2
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::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const vtkm::cont::ArrayHandle< T, S > &array)
Definition: UncertainArrayHandle.h:56
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::exec::arg::load
T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Get
auto Get(const vtkm::Tuple< Ts... > &tuple)
Retrieve the object from a vtkm::Tuple at the given index.
Definition: Tuple.h:81
vtkm::cont::UncertainArrayHandle::ResetStorageTypes
UncertainArrayHandle< ValueTypeList, NewStorageTypeList > ResetStorageTypes(NewStorageTypeList=NewStorageTypeList{}) const
Like ResetTypes except it only resets the storage types.
Definition: UncertainArrayHandle.h:92
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::cont::UncertainArrayHandle::NewInstance
Thisclass NewInstance() const
Create a new array of the same type as this array.
Definition: UncertainArrayHandle.h:78
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:351
UnknownArrayHandle.h
vtkm::cont::UncertainArrayHandle::CastAndCall
void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type.
Definition: UncertainArrayHandle.h:104
CastAndCall.h
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::ListForEach
void ListForEach(Functor &&f, vtkm::List< Ts... >, Args &&... args)
For each typename represented by the list, call the functor with a default instance of that type.
Definition: List.h:725
vtkm::cont::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const vtkm::cont::UnknownArrayHandle &src)
Definition: UncertainArrayHandle.h:61
vtkm::cont::UncertainArrayHandle
An ArrayHandle of an uncertain value type and storage.
Definition: UncertainArrayHandle.h:39
VTKM_IS_LIST
#define VTKM_IS_LIST(type)
Checks that the argument is a proper list.
Definition: List.h:69
vtkm::cont::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const UncertainArrayHandle< OtherValues, OtherStorage > &src)
Definition: UncertainArrayHandle.h:67
vtkm::List
A template used to hold a list of types.
Definition: List.h:39
vtkm::cont::UnknownArrayHandle::ResetTypes
vtkm::cont::UncertainArrayHandle< NewValueTypeList, NewStorageTypeList > ResetTypes(NewValueTypeList=NewValueTypeList{}, NewStorageTypeList=NewStorageTypeList{}) const
Assigns potential value and storage types.
Definition: UncertainArrayHandle.h:129
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
vtkm::cont::UncertainArrayHandle::ResetValueTypes
UncertainArrayHandle< NewValueTypeList, StorageTypeList > ResetValueTypes(NewValueTypeList=NewValueTypeList{}) const
Like ResetTypes except it only resets the value types.
Definition: UncertainArrayHandle.h:83
vtkm::cont::UncertainArrayHandle::CastAndCallWithFloatFallback
void CastAndCallWithFloatFallback(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type with a float cast fallback.
Definition: UncertainArrayHandle.h:119