VTK-m  2.0
Storage.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_Storage_h
11 #define vtk_m_cont_Storage_h
12 
13 #define VTKM_STORAGE_ERROR -2
14 #define VTKM_STORAGE_UNDEFINED -1
15 #define VTKM_STORAGE_BASIC 1
16 
17 #ifndef VTKM_STORAGE
18 #define VTKM_STORAGE VTKM_STORAGE_BASIC
19 #endif
20 
21 #include <vtkm/Flags.h>
22 #include <vtkm/StaticAssert.h>
23 
25 
27 #include <vtkm/cont/Logging.h>
28 #include <vtkm/cont/Token.h>
29 
31 
32 namespace vtkm
33 {
34 namespace cont
35 {
36 
37 #ifdef VTKM_DOXYGEN_ONLY
38 struct VTKM_ALWAYS_EXPORT StorageTag___
68 {
69 };
70 #endif // VTKM_DOXYGEN_ONLY
71 
72 namespace internal
73 {
74 
75 struct UndefinedStorage
76 {
77 };
78 
79 namespace detail
80 {
81 
82 // This class should never be used. It is used as a placeholder for undefined
83 // Storage objects. If you get a compiler error involving this object, then it
84 // probably comes from trying to use an ArrayHandle with bad template
85 // arguments.
86 template <typename T>
87 struct UndefinedArrayPortal
88 {
89  VTKM_STATIC_ASSERT(sizeof(T) == static_cast<size_t>(-1));
90 };
91 
92 } // namespace detail
93 
97 template <typename T, class StorageTag>
98 class Storage
99 #ifndef VTKM_DOXYGEN_ONLY
100  : public vtkm::cont::internal::UndefinedStorage
101 {
102 public:
103  using ReadPortalType = vtkm::cont::internal::detail::UndefinedArrayPortal<T>;
104  using WritePortalType = vtkm::cont::internal::detail::UndefinedArrayPortal<T>;
105 };
106 #else //VTKM_DOXYGEN_ONLY
107 {
108 public:
111  using ValueType = T;
112 
115  using ReadPortalType = vtkm::internal::ArrayPortalBasicRead<T>;
116 
119  using WritePortalType = vtkm::internal::ArrayPortalBasicWrite<T>;
120 
127  VTKM_CONT static std::vector<vtkm::cont::internal::Buffer> CreateBuffers();
128 
133  VTKM_CONT static void ResizeBuffers(vtkm::Id numValues,
134  const std::vector<vtkm::cont::internal::Buffer>& buffers,
135  vtkm::CopyFlag preserve,
136  vtkm::cont::Token& token);
137 
139  VTKM_CONT static vtkm::Id GetNumberOfValues(
140  const std::vector<vtkm::cont::internal::Buffer>& buffers);
141 
144  VTKM_CONT static void Fill(const std::vector<vtkm::cont::internal::Buffer>& buffers,
145  const ValueType& fillValue,
146  vtkm::Id startIndex,
147  vtkm::Id endIndex,
148  vtkm::cont::Token& token);
149 
152  VTKM_CONT static ReadPortalType CreateReadPortal(
153  const std::vector<vtkm::cont::internal::Buffer>& buffers,
155  vtkm::cont::Token& token);
156 
159  VTKM_CONT static WritePortalType CreateWritePortal(
160  const std::vector<vtkm::cont::internal::Buffer>& buffers,
162  vtkm::cont::Token& token)
163 };
164 #endif // VTKM_DOXYGEN_ONLY
165 
166 namespace detail
167 {
168 
169 VTKM_CONT_EXPORT void StorageNoResizeImpl(vtkm::Id currentNumValues,
170  vtkm::Id requestedNumValues,
171  std::string storageTagName);
172 
173 } // namespace detail
174 
175 template <typename StorageType>
176 struct StorageTraits;
177 
178 template <typename T, typename S>
179 struct StorageTraits<vtkm::cont::internal::Storage<T, S>>
180 {
181  using ValueType = T;
182  using Tag = S;
183 };
184 
185 #define VTKM_STORAGE_NO_RESIZE \
186  VTKM_CONT static void ResizeBuffers(vtkm::Id numValues, \
187  const std::vector<vtkm::cont::internal::Buffer>& buffers, \
188  vtkm::CopyFlag, \
189  vtkm::cont::Token&) \
190  { \
191  vtkm::cont::internal::detail::StorageNoResizeImpl( \
192  GetNumberOfValues(buffers), \
193  numValues, \
194  vtkm::cont::TypeToString<typename vtkm::cont::internal::StorageTraits<Storage>::Tag>()); \
195  } \
196  using ResizeBuffersEatComma = void
197 
198 #define VTKM_STORAGE_NO_WRITE_PORTAL \
199  using WritePortalType = vtkm::internal::ArrayPortalDummy< \
200  typename vtkm::cont::internal::StorageTraits<Storage>::ValueType>; \
201  VTKM_CONT static void Fill( \
202  const std::vector<vtkm::cont::internal::Buffer>&, \
203  const typename vtkm::cont::internal::StorageTraits<Storage>::ValueType&, \
204  vtkm::Id, \
205  vtkm::Id, \
206  vtkm::cont::Token&) \
207  { \
208  throw vtkm::cont::ErrorBadAllocation( \
209  "Cannot write to arrays with storage type of " + \
210  vtkm::cont::TypeToString<typename vtkm::cont::internal::StorageTraits<Storage>::Tag>()); \
211  } \
212  VTKM_CONT static WritePortalType CreateWritePortal( \
213  const std::vector<vtkm::cont::internal::Buffer>&, \
214  vtkm::cont::DeviceAdapterId, \
215  vtkm::cont::Token&) \
216  { \
217  throw vtkm::cont::ErrorBadAllocation( \
218  "Cannot write to arrays with storage type of " + \
219  vtkm::cont::TypeToString<typename vtkm::cont::internal::StorageTraits<Storage>::Tag>()); \
220  } \
221  using CreateWritePortalEatComma = void
222 
223 } // namespace internal
224 }
225 } // namespace vtkm::cont
226 
227 #endif //vtk_m_cont_Storage_h
ErrorBadAllocation.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
VTKM_STATIC_ASSERT
#define VTKM_STATIC_ASSERT(condition)
Definition: StaticAssert.h:16
Buffer.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
StaticAssert.h
vtkm::CopyFlag
CopyFlag
Definition: Flags.h:16
VTKM_ALWAYS_EXPORT
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
Flags.h
Logging.h
Logging utilities.
Token.h
ArrayPortalDummy.h