Viskores  1.0
UncertainCellSet.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_UncertainCellSet_h
19 #define viskores_cont_UncertainCellSet_h
20 
22 
23 namespace viskores
24 {
25 namespace cont
26 {
27 
45 template <typename CellSetList>
46 class VISKORES_ALWAYS_EXPORT UncertainCellSet : public viskores::cont::UnknownCellSet
47 {
48  VISKORES_IS_LIST(CellSetList);
49 
50  VISKORES_STATIC_ASSERT_MSG((!std::is_same<CellSetList, viskores::ListUniversal>::value),
51  "Cannot use viskores::ListUniversal with UncertainCellSet.");
52 
55 
56 public:
57  VISKORES_CONT UncertainCellSet() = default;
58 
59  template <typename CellSetType>
60  VISKORES_CONT UncertainCellSet(const CellSetType& cellSet)
61  : Superclass(cellSet)
62  {
63  }
64 
66  : Superclass(src)
67  {
68  }
69 
70  template <typename OtherCellSetList>
72  : Superclass(src)
73  {
74  }
75 
81  VISKORES_CONT Thisclass NewInstance() const { return Thisclass(this->Superclass::NewInstance()); }
82 
88  template <typename Functor, typename... Args>
89  VISKORES_CONT void CastAndCall(Functor&& functor, Args&&... args) const
90  {
91  this->CastAndCallForTypes<CellSetList>(std::forward<Functor>(functor),
92  std::forward<Args>(args)...);
93  }
94 };
95 
96 // Defined here to avoid circular dependencies between UnknownCellSet and UncertainCellSet.
97 template <typename NewCellSetList>
99  NewCellSetList) const
100 {
102 }
103 template <typename NewCellSetList>
105  const
106 {
108 }
109 
110 namespace internal
111 {
112 
113 template <typename CellSetList>
114 struct DynamicTransformTraits<viskores::cont::UncertainCellSet<CellSetList>>
115 {
116  using DynamicTag = viskores::cont::internal::DynamicTransformTagCastAndCall;
117 };
118 
119 } // namespace internal
120 
121 } // namespace viskores::cont
122 } // namespace viskores
123 
124 //=============================================================================
125 // Specializations of serialization related classes
127 
128 namespace viskores
129 {
130 namespace cont
131 {
132 
133 template <typename CellSetList>
134 struct SerializableTypeString<viskores::cont::UncertainCellSet<CellSetList>>
135 {
136  static VISKORES_CONT std::string Get()
137  {
139  }
140 };
141 }
142 } // namespace viskores::cont
143 
144 namespace mangled_diy_namespace
145 {
146 
147 namespace internal
148 {
149 
150 struct UncertainCellSetSerializeFunctor
151 {
152  template <typename CellSetType>
153  void operator()(const CellSetType& cs, BinaryBuffer& bb) const
154  {
156  viskoresdiy::save(bb, cs);
157  }
158 };
159 
160 struct UncertainCellSetDeserializeFunctor
161 {
162  template <typename CellSetType>
163  void operator()(CellSetType,
164  viskores::cont::UnknownCellSet& unknownCellSet,
165  const std::string& typeString,
166  bool& success,
167  BinaryBuffer& bb) const
168  {
169  if (!success && (typeString == viskores::cont::SerializableTypeString<CellSetType>::Get()))
170  {
171  CellSetType knownCellSet;
172  viskoresdiy::load(bb, knownCellSet);
173  unknownCellSet = knownCellSet;
174  success = true;
175  }
176  }
177 };
178 
179 } // internal
180 
181 template <typename CellSetList>
182 struct Serialization<viskores::cont::UncertainCellSet<CellSetList>>
183 {
185 
186 public:
187  static VISKORES_CONT void save(BinaryBuffer& bb, const Type& obj)
188  {
189  obj.CastAndCall(internal::UncertainCellSetSerializeFunctor{}, bb);
190  }
191 
192  static VISKORES_CONT void load(BinaryBuffer& bb, Type& obj)
193  {
194  std::string typeString;
195  viskoresdiy::load(bb, typeString);
196 
197  bool success = false;
199  internal::UncertainCellSetDeserializeFunctor{}, CellSetList{}, obj, typeString, success, bb);
200 
201  if (!success)
202  {
204  "Error deserializing Unknown/UncertainCellSet. Message TypeString: " + typeString);
205  }
206  }
207 };
208 
209 } // namespace mangled_diy_namespace
210 
212 
213 #endif //viskores_cont_UncertainCellSet_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::UncertainCellSet::CastAndCall
void CastAndCall(Functor &&functor, Args &&... args) const
Call a functor using the underlying cell set type.
Definition: UncertainCellSet.h:89
UnknownCellSet.h
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::UncertainCellSet::UncertainCellSet
UncertainCellSet(const UncertainCellSet< OtherCellSetList > &src)
Definition: UncertainCellSet.h:71
viskores::cont::UncertainCellSet::NewInstance
Thisclass NewInstance() const
Create a new cell set of the same type as this.
Definition: UncertainCellSet.h:81
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::UncertainCellSet::UncertainCellSet
UncertainCellSet(const CellSetType &cellSet)
Definition: UncertainCellSet.h:60
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_STATIC_ASSERT_MSG
#define VISKORES_STATIC_ASSERT_MSG(condition, message)
Definition: StaticAssert.h:26
viskores::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:56
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::UncertainCellSet
A CellSet of an uncertain type.
Definition: UncertainCellSet.h:46
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::UnknownCellSet::ResetCellSetList
viskores::cont::UncertainCellSet< CellSetList > ResetCellSetList() const
viskores::cont::UncertainCellSet::UncertainCellSet
UncertainCellSet(const viskores::cont::UnknownCellSet &src)
Definition: UncertainCellSet.h:65
VISKORES_IS_LIST
#define VISKORES_IS_LIST(type)
Checks that the argument is a proper list.
Definition: List.h:77