VTK-m  2.0
ArrayHandleConstant.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_ArrayHandleConstant_h
11 #define vtk_m_cont_ArrayHandleConstant_h
12 
14 
15 namespace vtkm
16 {
17 namespace cont
18 {
19 
21 {
22 };
23 
24 namespace internal
25 {
26 
27 template <typename ValueType>
28 struct VTKM_ALWAYS_EXPORT ConstantFunctor
29 {
31  ConstantFunctor(const ValueType& value = ValueType())
32  : Value(value)
33  {
34  }
35 
37  ValueType operator()(vtkm::Id vtkmNotUsed(index)) const { return this->Value; }
38 
39 private:
40  ValueType Value;
41 };
42 
43 template <typename T>
44 using StorageTagConstantSuperclass =
46 
47 template <typename T>
48 struct Storage<T, vtkm::cont::StorageTagConstant> : Storage<T, StorageTagConstantSuperclass<T>>
49 {
50 };
51 
52 } // namespace internal
53 
62 template <typename T>
63 class ArrayHandleConstant : public vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>
64 {
65 public:
69 
70  VTKM_CONT
71  ArrayHandleConstant(T value, vtkm::Id numberOfValues = 0)
72  : Superclass(internal::FunctorToArrayHandleImplicitBuffers(internal::ConstantFunctor<T>(value),
73  numberOfValues))
74  {
75  }
76 
81  VTKM_CONT T GetValue() const { return this->ReadPortal().GetFunctor()(0); }
82 };
83 
88 template <typename T>
90 {
91  return vtkm::cont::ArrayHandleConstant<T>(value, numberOfValues);
92 }
93 }
94 } // vtkm::cont
95 
96 //=============================================================================
97 // Specializations of serialization related classes
99 namespace vtkm
100 {
101 namespace cont
102 {
103 
104 template <typename T>
105 struct SerializableTypeString<vtkm::cont::ArrayHandleConstant<T>>
106 {
107  static VTKM_CONT const std::string& Get()
108  {
109  static std::string name = "AH_Constant<" + SerializableTypeString<T>::Get() + ">";
110  return name;
111  }
112 };
113 
114 template <typename T>
115 struct SerializableTypeString<vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>>
116  : SerializableTypeString<vtkm::cont::ArrayHandleConstant<T>>
117 {
118 };
119 }
120 } // vtkm::cont
121 
122 namespace mangled_diy_namespace
123 {
124 
125 template <typename T>
126 struct Serialization<vtkm::cont::ArrayHandleConstant<T>>
127 {
128 private:
131 
132 public:
133  static VTKM_CONT void save(BinaryBuffer& bb, const BaseType& obj)
134  {
135  vtkmdiy::save(bb, obj.GetNumberOfValues());
136  vtkmdiy::save(bb, obj.ReadPortal().Get(0));
137  }
138 
139  static VTKM_CONT void load(BinaryBuffer& bb, BaseType& obj)
140  {
141  vtkm::Id count = 0;
142  vtkmdiy::load(bb, count);
143 
144  T value;
145  vtkmdiy::load(bb, value);
146 
147  obj = vtkm::cont::make_ArrayHandleConstant(value, count);
148  }
149 };
150 
151 template <typename T>
152 struct Serialization<vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagConstant>>
153  : Serialization<vtkm::cont::ArrayHandleConstant<T>>
154 {
155 };
156 
157 } // diy
159 
160 #endif //vtk_m_cont_ArrayHandleConstant_h
vtkm::cont::ArrayHandleConstant::VTKM_ARRAY_HANDLE_SUBCLASS
VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleConstant,(ArrayHandleConstant< T >),(vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagConstant >))
vtkm::cont::ArrayHandleConstant::ArrayHandleConstant
VTKM_CONT ArrayHandleConstant(T value, vtkm::Id numberOfValues=0)
Definition: ArrayHandleConstant.h:71
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
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::ArrayHandleConstant::GetValue
VTKM_CONT T GetValue() const
Returns the constant value stored in this array.
Definition: ArrayHandleConstant.h:81
vtkm::cont::make_ArrayHandleConstant
vtkm::cont::ArrayHandleConstant< T > make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
make_ArrayHandleConstant is convenience function to generate an ArrayHandleImplicit.
Definition: ArrayHandleConstant.h:89
mangled_diy_namespace
Definition: Particle.h:331
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::exec::arg::load
VTKM_SUPPRESS_EXEC_WARNINGS VTKM_EXEC T load(const U &u, vtkm::Id v)
Definition: FetchTagArrayDirectIn.h:36
vtkm::cont::StorageTagConstant
Definition: ArrayHandleConstant.h:20
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::cont::ArrayHandle< T, vtkm::cont::StorageTagConstant >::ReadPortal
VTKM_CONT ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:414
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
ArrayHandleImplicit.h
vtkm::cont::ArrayHandleImplicit
An ArrayHandle that computes values on the fly.
Definition: ArrayHandleImplicit.h:174