Viskores  1.0
FetchTagArrayDirectOut.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_exec_arg_FetchTagArrayDirectOut_h
19 #define viskores_exec_arg_FetchTagArrayDirectOut_h
20 
23 
24 #include <type_traits>
25 
26 namespace viskores
27 {
28 namespace exec
29 {
30 namespace arg
31 {
32 
40 {
41 };
42 
43 template <typename ExecObjectType>
46  ExecObjectType>
47 {
48  using ValueType = typename ExecObjectType::ValueType;
49 
51  template <typename ThreadIndicesType>
52  VISKORES_EXEC ValueType Load(const ThreadIndicesType& indices,
53  const ExecObjectType& arrayPortal) const
54  {
55  return this->DoLoad(
56  indices, arrayPortal, typename std::is_default_constructible<ValueType>::type{});
57  }
58 
60  template <typename ThreadIndicesType, typename T>
61  VISKORES_EXEC void Store(const ThreadIndicesType& indices,
62  const ExecObjectType& arrayPortal,
63  const T& value) const
64  {
65  arrayPortal.Set(indices.GetOutputIndex(), static_cast<ValueType>(value));
66  }
67 
68 private:
70  template <typename ThreadIndicesType>
71  VISKORES_EXEC ValueType DoLoad(const ThreadIndicesType&,
72  const ExecObjectType&,
73  std::true_type) const
74  {
75  // Load is a no-op for this fetch.
76  return ValueType();
77  }
78 
80  template <typename ThreadIndicesType>
81  VISKORES_EXEC ValueType DoLoad(const ThreadIndicesType& indices,
82  const ExecObjectType& arrayPortal,
83  std::false_type) const
84  {
85  // Cannot create a ValueType object, so pull one out of the array portal. This may seem
86  // weird because an output array often has garbage in it. However, this case can happen
87  // with special arrays with Vec-like values that reference back to the array memory.
88  // For example, with ArrayHandleRecombineVec, the values are actual objects that point
89  // back to the array for on demand reading and writing. You need the buffer established
90  // by the array even if there is garbage in that array.
91  return arrayPortal.Get(indices.GetOutputIndex());
92  }
93 };
94 }
95 }
96 } // namespace viskores::exec::arg
97 
98 #endif //viskores_exec_arg_FetchTagArrayDirectOut_h
viskores::exec::arg::Fetch< viskores::exec::arg::FetchTagArrayDirectOut, viskores::exec::arg::AspectTagDefault, ExecObjectType >::ValueType
typename ExecObjectType::ValueType ValueType
Definition: FetchTagArrayDirectOut.h:48
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::exec::arg::Fetch< viskores::exec::arg::FetchTagArrayDirectOut, viskores::exec::arg::AspectTagDefault, ExecObjectType >::Load
ValueType Load(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal) const
Definition: FetchTagArrayDirectOut.h:52
viskores::exec::arg::Fetch< viskores::exec::arg::FetchTagArrayDirectOut, viskores::exec::arg::AspectTagDefault, ExecObjectType >::Store
void Store(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal, const T &value) const
Definition: FetchTagArrayDirectOut.h:61
viskores::exec::arg::Fetch::ValueType
typename ExecObjectType::ValueType ValueType
The type of value to load and store.
Definition: Fetch.h:66
viskores::exec::arg::Fetch
Class for loading and storing values in thread instance.
Definition: Fetch.h:57
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::exec::arg::Fetch< viskores::exec::arg::FetchTagArrayDirectOut, viskores::exec::arg::AspectTagDefault, ExecObjectType >::DoLoad
ValueType DoLoad(const ThreadIndicesType &, const ExecObjectType &, std::true_type) const
Definition: FetchTagArrayDirectOut.h:71
Fetch.h
AspectTagDefault.h
viskores::exec::arg::AspectTagDefault
Aspect tag to use for default load/store of data.
Definition: AspectTagDefault.h:30
viskores::exec::arg::Fetch< viskores::exec::arg::FetchTagArrayDirectOut, viskores::exec::arg::AspectTagDefault, ExecObjectType >::DoLoad
ValueType DoLoad(const ThreadIndicesType &indices, const ExecObjectType &arrayPortal, std::false_type) const
Definition: FetchTagArrayDirectOut.h:81
viskores::exec::arg::FetchTagArrayDirectOut
Fetch tag for setting array values with direct indexing.
Definition: FetchTagArrayDirectOut.h:39
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59