Viskores  1.0
ArrayHandleDiscard.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_ArrayHandleDiscard_h
19 #define viskores_cont_ArrayHandleDiscard_h
20 
21 #include <viskores/TypeTraits.h>
24 
25 #include <type_traits>
26 
27 namespace viskores
28 {
29 namespace exec
30 {
31 namespace internal
32 {
33 
36 template <typename ValueType_>
37 class ArrayPortalDiscard
38 {
39 public:
40  using ValueType = ValueType_;
41 
44  ArrayPortalDiscard()
45  : NumberOfValues(0)
46  {
47  } // needs to be host and device so that cuda can create lvalue of these
48 
50  explicit ArrayPortalDiscard(viskores::Id numValues)
51  : NumberOfValues(numValues)
52  {
53  }
54 
59  template <class OtherV>
60  VISKORES_CONT ArrayPortalDiscard(const ArrayPortalDiscard<OtherV>& src)
61  : NumberOfValues(src.NumberOfValues)
62  {
63  }
64 
66  viskores::Id GetNumberOfValues() const { return this->NumberOfValues; }
67 
68  ValueType Get(viskores::Id) const
69  {
70  VISKORES_UNREACHABLE("Cannot read from ArrayHandleDiscard.");
72  }
73 
75  void Set(viskores::Id index, const ValueType&) const
76  {
77  VISKORES_ASSERT(index < this->GetNumberOfValues());
78  (void)index;
79  // no-op
80  }
81 
82 private:
83  viskores::Id NumberOfValues;
84 };
85 
86 } // end namespace internal
87 } // end namespace exec
88 
89 namespace cont
90 {
91 
92 namespace internal
93 {
94 
95 struct VISKORES_ALWAYS_EXPORT StorageTagDiscard
96 {
97 };
98 
99 struct VISKORES_ALWAYS_EXPORT DiscardMetaData
100 {
101  viskores::Id NumberOfValues = 0;
102 };
103 
104 template <typename ValueType>
105 class Storage<ValueType, StorageTagDiscard>
106 {
107 public:
108  using WritePortalType = viskores::exec::internal::ArrayPortalDiscard<ValueType>;
109 
110  // Note that this portal is write-only, so you will probably run into problems if
111  // you actually try to use this read portal.
112  using ReadPortalType = viskores::exec::internal::ArrayPortalDiscard<ValueType>;
113 
114  VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers()
115  {
116  DiscardMetaData metaData;
117  metaData.NumberOfValues = 0;
118  return viskores::cont::internal::CreateBuffers(metaData);
119  }
120 
121  VISKORES_CONT static void ResizeBuffers(
122  viskores::Id numValues,
123  const std::vector<viskores::cont::internal::Buffer>& buffers,
126  {
127  VISKORES_ASSERT(numValues >= 0);
128  buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues = numValues;
129  }
130 
131  VISKORES_CONT static viskores::IdComponent GetNumberOfComponentsFlat(
132  const std::vector<viskores::cont::internal::Buffer>&)
133  {
135  }
136 
137  VISKORES_CONT static viskores::Id GetNumberOfValues(
138  const std::vector<viskores::cont::internal::Buffer>& buffers)
139  {
140  return buffers[0].GetMetaData<DiscardMetaData>().NumberOfValues;
141  }
142 
143  VISKORES_CONT static void Fill(const std::vector<viskores::cont::internal::Buffer>&,
144  const ValueType&,
145  viskores::Id,
146  viskores::Id,
148  {
149  // Fill is a NO-OP.
150  }
151 
152  VISKORES_CONT static ReadPortalType CreateReadPortal(
153  const std::vector<viskores::cont::internal::Buffer>&,
156  {
157  throw viskores::cont::ErrorBadValue("Cannot read from ArrayHandleDiscard.");
158  }
159 
160  VISKORES_CONT static WritePortalType CreateWritePortal(
161  const std::vector<viskores::cont::internal::Buffer>& buffers,
164  {
165  return WritePortalType(GetNumberOfValues(buffers));
166  }
167 };
168 
169 template <typename ValueType_>
170 struct ArrayHandleDiscardTraits
171 {
172  using ValueType = ValueType_;
173  using StorageTag = StorageTagDiscard;
175 };
176 
177 } // end namespace internal
178 
182 template <typename ValueType_>
183 class ArrayHandleDiscard : public internal::ArrayHandleDiscardTraits<ValueType_>::Superclass
184 {
185 public:
190 };
191 
193 template <typename T>
194 struct IsArrayHandleDiscard : std::false_type
195 {
196 };
197 
198 template <typename T>
199 struct IsArrayHandleDiscard<ArrayHandle<T, internal::StorageTagDiscard>> : std::true_type
200 {
201 };
202 
203 } // end namespace cont
204 } // end namespace viskores
205 
206 #endif // viskores_cont_ArrayHandleDiscard_h
viskores::cont::ArrayHandleDiscard
ArrayHandleDiscard is a write-only array that discards all data written to it.
Definition: ArrayHandleDiscard.h:183
viskores::VecFlat
Treat a Vec or Vec-like object as a flat Vec.
Definition: VecFlat.h:240
ArrayHandle.h
viskores::cont::IsArrayHandleDiscard
Helper to determine if an ArrayHandle type is an ArrayHandleDiscard.
Definition: ArrayHandleDiscard.h:194
viskores::TypeTraits::ZeroInitialization
static T ZeroInitialization()
A static function that returns 0 (or the closest equivalent to it) for the given type.
Definition: TypeTraits.h:85
viskores::cont::ArrayHandleDiscard::Superclass
typename viskores::cont::detail::GetTypeInParentheses< void(typename internal::ArrayHandleDiscardTraits< ValueType_ >::Superclass) >::type Superclass
Definition: ArrayHandleDiscard.h:189
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
VISKORES_UNREACHABLE
#define VISKORES_UNREACHABLE(msg)
VISKORES_UNREACHABLE is similar to VTK_ASSUME, with the significant difference that it is not conditi...
Definition: Unreachable.h:39
TypeTraits.h
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_ASSERT
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::ErrorBadValue
This class is thrown when a Viskores function or method encounters an invalid value that inhibits pro...
Definition: ErrorBadValue.h:33
VISKORES_ARRAY_HANDLE_SUBCLASS
#define VISKORES_ARRAY_HANDLE_SUBCLASS(classname, fullclasstype, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:256
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::CopyFlag
CopyFlag
Identifier used to specify whether a function should deep copy data.
Definition: Flags.h:25
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
Unreachable.h