Viskores  1.0
UncertainArrayHandle.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_UncertainArrayHandle_h
19 #define viskores_cont_UncertainArrayHandle_h
20 
23 
24 namespace viskores
25 {
26 namespace cont
27 {
28 
46 template <typename ValueTypeList, typename StorageTypeList>
47 class VISKORES_ALWAYS_EXPORT UncertainArrayHandle : public viskores::cont::UnknownArrayHandle
48 {
49  VISKORES_IS_LIST(ValueTypeList);
50  VISKORES_IS_LIST(StorageTypeList);
51 
52  VISKORES_STATIC_ASSERT_MSG((!std::is_same<ValueTypeList, viskores::ListUniversal>::value),
53  "Cannot use viskores::ListUniversal with UncertainArrayHandle.");
54  VISKORES_STATIC_ASSERT_MSG((!std::is_same<StorageTypeList, viskores::ListUniversal>::value),
55  "Cannot use viskores::ListUniversal with UncertainArrayHandle.");
56 
59 
60 public:
62 
63  template <typename T, typename S>
65  : Superclass(array)
66  {
67  }
68 
70  : Superclass(src)
71  {
72  }
73 
74  template <typename OtherValues, typename OtherStorage>
76  : Superclass(src)
77  {
78  }
79 
86  VISKORES_CONT Thisclass NewInstance() const { return Thisclass(this->Superclass::NewInstance()); }
87 
90  template <typename NewValueTypeList>
92  NewValueTypeList = NewValueTypeList{}) const
93  {
94  return this->ResetTypes<NewValueTypeList, StorageTypeList>();
95  }
96 
99  template <typename NewStorageTypeList>
101  NewStorageTypeList = NewStorageTypeList{}) const
102  {
103  return this->ResetTypes<ValueTypeList, NewStorageTypeList>();
104  }
105 
111  template <typename Functor, typename... Args>
112  VISKORES_CONT void CastAndCall(Functor&& functor, Args&&... args) const
113  {
114  this->CastAndCallForTypes<ValueTypeList, StorageTypeList>(std::forward<Functor>(functor),
115  std::forward<Args>(args)...);
116  }
117 
126  template <typename Functor, typename... Args>
127  VISKORES_CONT void CastAndCallWithFloatFallback(Functor&& functor, Args&&... args) const
128  {
129  this->template CastAndCallForTypesWithFloatFallback<ValueTypeList, StorageTypeList>(
130  std::forward<Functor>(functor), std::forward<Args>(args)...);
131  }
132 };
133 
134 // Defined here to avoid circular dependencies between UnknownArrayHandle and UncertainArrayHandle.
135 template <typename NewValueTypeList, typename NewStorageTypeList>
137 UnknownArrayHandle::ResetTypes(NewValueTypeList, NewStorageTypeList) const
138 {
140 }
141 
142 namespace internal
143 {
144 
145 template <typename ValueTypeList, typename StorageTypeList>
146 struct DynamicTransformTraits<viskores::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
147 {
148  using DynamicTag = viskores::cont::internal::DynamicTransformTagCastAndCall;
149 };
150 
151 } // namespace internal
152 
153 }
154 } // namespace viskores::cont
155 
156 //=============================================================================
157 // Specializations of serialization related classes
159 
160 namespace viskores
161 {
162 namespace cont
163 {
164 
165 template <typename ValueTypeList, typename StorageTypeList>
166 struct SerializableTypeString<viskores::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
167 {
168  static VISKORES_CONT std::string Get() { return "UncertainAH"; }
169 };
170 }
171 } // namespace viskores::cont
172 
173 namespace mangled_diy_namespace
174 {
175 
176 namespace internal
177 {
178 
179 struct UncertainArrayHandleSerializeFunctor
180 {
181  template <typename ArrayHandleType>
182  void operator()(const ArrayHandleType& ah, BinaryBuffer& bb) const
183  {
185  viskoresdiy::save(bb, ah);
186  }
187 };
188 
189 struct UncertainArrayHandleDeserializeFunctor
190 {
191  template <typename T, typename S>
192  void operator()(viskores::List<T, S>,
194  const std::string& typeString,
195  bool& success,
196  BinaryBuffer& bb) const
197  {
198  using ArrayHandleType = viskores::cont::ArrayHandle<T, S>;
199 
200  if (!success && (typeString == viskores::cont::SerializableTypeString<ArrayHandleType>::Get()))
201  {
202  ArrayHandleType knownArray;
203  viskoresdiy::load(bb, knownArray);
204  unknownArray = knownArray;
205  success = true;
206  }
207  }
208 };
209 
210 } // internal
211 
212 template <typename ValueTypeList, typename StorageTypeList>
213 struct Serialization<viskores::cont::UncertainArrayHandle<ValueTypeList, StorageTypeList>>
214 {
216 
217 public:
218  static VISKORES_CONT void save(BinaryBuffer& bb, const Type& obj)
219  {
220  obj.CastAndCall(internal::UncertainArrayHandleSerializeFunctor{}, bb);
221  }
222 
223  static VISKORES_CONT void load(BinaryBuffer& bb, Type& obj)
224  {
225  std::string typeString;
226  viskoresdiy::load(bb, typeString);
227 
228  bool success = false;
230  internal::UncertainArrayHandleDeserializeFunctor{},
231  viskores::cont::internal::ListAllArrayTypes<ValueTypeList, StorageTypeList>{},
232  obj,
233  typeString,
234  success,
235  bb);
236 
237  if (!success)
238  {
240  "Error deserializing Unknown/UncertainArrayHandle. Message TypeString: " + typeString);
241  }
242  }
243 };
244 
245 } // namespace mangled_diy_namespace
246 
248 
249 #endif //viskores_cont_UncertainArrayHandle_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const viskores::cont::ArrayHandle< T, S > &array)
Definition: UncertainArrayHandle.h:64
viskores::cont::UncertainArrayHandle
An ArrayHandle of an uncertain value type and storage.
Definition: UncertainArrayHandle.h:47
viskores::cont::UncertainArrayHandle::NewInstance
Thisclass NewInstance() const
Create a new array of the same type as this array.
Definition: UncertainArrayHandle.h:86
viskores::cont::ErrorBadType
This class is thrown when Viskores encounters data of a type that is incompatible with the current op...
Definition: ErrorBadType.h:33
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const viskores::cont::UnknownArrayHandle &src)
Definition: UncertainArrayHandle.h:69
viskores::cont::UnknownArrayHandle::ResetTypes
viskores::cont::UncertainArrayHandle< NewValueTypeList, NewStorageTypeList > ResetTypes(NewValueTypeList=NewValueTypeList{}, NewStorageTypeList=NewStorageTypeList{}) const
Assigns potential value and storage types.
Definition: UncertainArrayHandle.h:137
viskores::cont::UncertainArrayHandle::ResetStorageTypes
UncertainArrayHandle< ValueTypeList, NewStorageTypeList > ResetStorageTypes(NewStorageTypeList=NewStorageTypeList{}) const
Like ResetTypes except it only resets the storage types.
Definition: UncertainArrayHandle.h:100
mangled_diy_namespace
Definition: Particle.h:373
viskores::List
A template used to hold a list of types.
Definition: List.h:47
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
UnknownArrayHandle.h
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
CastAndCall.h
viskores::cont::UncertainArrayHandle::UncertainArrayHandle
UncertainArrayHandle(const UncertainArrayHandle< OtherValues, OtherStorage > &src)
Definition: UncertainArrayHandle.h:75
VISKORES_STATIC_ASSERT_MSG
#define VISKORES_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:26
viskores::ListForEach
void ListForEach(Functor &&f, viskores::List< Ts... >, Args &&... args)
For each typename represented by the list, call the functor with a default instance of that type.
Definition: List.h:745
viskores::cont::UncertainArrayHandle::CastAndCall
void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying array type.
Definition: UncertainArrayHandle.h:112
viskores::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:127
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::cont::UncertainArrayHandle::ResetValueTypes
UncertainArrayHandle< NewValueTypeList, StorageTypeList > ResetValueTypes(NewValueTypeList=NewValueTypeList{}) const
Like ResetTypes except it only resets the value types.
Definition: UncertainArrayHandle.h:91
VISKORES_IS_LIST
#define VISKORES_IS_LIST(type)
Checks that the argument is a proper list.
Definition: List.h:77