VTK-m  2.0
UncertainCellSet.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_UncertainCellSet_h
11 #define vtk_m_cont_UncertainCellSet_h
12 
14 
15 namespace vtkm
16 {
17 namespace cont
18 {
19 
37 template <typename CellSetList>
39 {
40  VTKM_IS_LIST(CellSetList);
41 
42  VTKM_STATIC_ASSERT_MSG((!std::is_same<CellSetList, vtkm::ListUniversal>::value),
43  "Cannot use vtkm::ListUniversal with UncertainCellSet.");
44 
47 
48 public:
49  VTKM_CONT UncertainCellSet() = default;
50 
51  template <typename CellSetType>
52  VTKM_CONT UncertainCellSet(const CellSetType& cellSet)
53  : Superclass(cellSet)
54  {
55  }
56 
58  : Superclass(src)
59  {
60  }
61 
62  template <typename OtherCellSetList>
64  : Superclass(src)
65  {
66  }
67 
73  VTKM_CONT Thisclass NewInstance() const { return Thisclass(this->Superclass::NewInstance()); }
74 
80  template <typename Functor, typename... Args>
81  VTKM_CONT void CastAndCall(Functor&& functor, Args&&... args) const
82  {
83  this->CastAndCallForTypes<CellSetList>(std::forward<Functor>(functor),
84  std::forward<Args>(args)...);
85  }
86 };
87 
88 // Defined here to avoid circular dependencies between UnknownCellSet and UncertainCellSet.
89 template <typename NewCellSetList>
91  NewCellSetList) const
92 {
94 }
95 template <typename NewCellSetList>
97 {
99 }
100 
101 namespace internal
102 {
103 
104 template <typename CellSetList>
105 struct DynamicTransformTraits<vtkm::cont::UncertainCellSet<CellSetList>>
106 {
107  using DynamicTag = vtkm::cont::internal::DynamicTransformTagCastAndCall;
108 };
109 
110 } // namespace internal
111 
112 } // namespace vtkm::cont
113 } // namespace vtkm
114 
115 //=============================================================================
116 // Specializations of serialization related classes
118 
119 namespace vtkm
120 {
121 namespace cont
122 {
123 
124 template <typename CellSetList>
125 struct SerializableTypeString<vtkm::cont::UncertainCellSet<CellSetList>>
126 {
127  static VTKM_CONT std::string Get()
128  {
130  }
131 };
132 }
133 } // namespace vtkm::cont
134 
135 namespace mangled_diy_namespace
136 {
137 
138 namespace internal
139 {
140 
141 struct UncertainCellSetSerializeFunctor
142 {
143  template <typename CellSetType>
144  void operator()(const CellSetType& cs, BinaryBuffer& bb) const
145  {
147  vtkmdiy::save(bb, cs);
148  }
149 };
150 
151 struct UncertainCellSetDeserializeFunctor
152 {
153  template <typename CellSetType>
154  void operator()(CellSetType,
155  vtkm::cont::UnknownCellSet& unknownCellSet,
156  const std::string& typeString,
157  bool& success,
158  BinaryBuffer& bb) const
159  {
160  if (!success && (typeString == vtkm::cont::SerializableTypeString<CellSetType>::Get()))
161  {
162  CellSetType knownCellSet;
163  vtkmdiy::load(bb, knownCellSet);
164  unknownCellSet = knownCellSet;
165  success = true;
166  }
167  }
168 };
169 
170 } // internal
171 
172 template <typename CellSetList>
173 struct Serialization<vtkm::cont::UncertainCellSet<CellSetList>>
174 {
176 
177 public:
178  static VTKM_CONT void save(BinaryBuffer& bb, const Type& obj)
179  {
180  obj.CastAndCall(internal::UncertainCellSetSerializeFunctor{}, bb);
181  }
182 
183  static VTKM_CONT void load(BinaryBuffer& bb, Type& obj)
184  {
185  std::string typeString;
186  vtkmdiy::load(bb, typeString);
187 
188  bool success = false;
190  internal::UncertainCellSetDeserializeFunctor{}, CellSetList{}, obj, typeString, success, bb);
191 
192  if (!success)
193  {
195  "Error deserializing Unknown/UncertainCellSet. Message TypeString: " + typeString);
196  }
197  }
198 };
199 
200 } // namespace mangled_diy_namespace
201 
203 
204 #endif //vtk_m_cont_UncertainCellSet_h
vtkm::cont::UncertainCellSet::UncertainCellSet
VTKM_CONT UncertainCellSet(const UncertainCellSet< OtherCellSetList > &src)
Definition: UncertainCellSet.h:63
vtkm::cont::UncertainCellSet::NewInstance
VTKM_CONT Thisclass NewInstance() const
Create a new cell set of the same type as this.
Definition: UncertainCellSet.h:73
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
UnknownCellSet.h
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::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:38
vtkm::ListForEach
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC_CONT void ListForEach(Functor &&f, vtkm::List< Ts... >, Args &&... args)
Definition: List.h:720
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
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
vtkm::cont::UncertainCellSet::UncertainCellSet
VTKM_CONT UncertainCellSet(const CellSetType &cellSet)
Definition: UncertainCellSet.h:52
vtkm::cont::UncertainCellSet::UncertainCellSet
VTKM_CONT UncertainCellSet(const vtkm::cont::UnknownCellSet &src)
Definition: UncertainCellSet.h:57
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_STATIC_ASSERT_MSG
#define VTKM_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:18
vtkm::cont::UncertainCellSet::CastAndCall
VTKM_CONT void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying cell set type.
Definition: UncertainCellSet.h:81
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::UnknownCellSet::ResetCellSetList
VTKM_CONT vtkm::cont::UncertainCellSet< CellSetList > ResetCellSetList() const
VTKM_IS_LIST
#define VTKM_IS_LIST(type)
Checks that the argument is a proper list.
Definition: List.h:64
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92