Viskores  1.0
Storage.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_Storage_h
19 #define viskores_cont_Storage_h
20 
21 #define VISKORES_STORAGE_ERROR -2
22 #define VISKORES_STORAGE_UNDEFINED -1
23 #define VISKORES_STORAGE_BASIC 1
24 
25 #ifndef VISKORES_STORAGE
26 #define VISKORES_STORAGE VISKORES_STORAGE_BASIC
27 #endif
28 
29 #include <viskores/Flags.h>
30 #include <viskores/StaticAssert.h>
31 
33 
35 #include <viskores/cont/Logging.h>
36 #include <viskores/cont/Token.h>
37 
39 
40 namespace viskores
41 {
42 namespace cont
43 {
44 
45 #ifdef VISKORES_DOXYGEN_ONLY
46 struct VISKORES_ALWAYS_EXPORT StorageTag___
76 {
77 };
78 #endif // VISKORES_DOXYGEN_ONLY
79 
80 namespace internal
81 {
82 
83 struct UndefinedStorage
84 {
85 };
86 
87 namespace detail
88 {
89 
90 // This class should never be used. It is used as a placeholder for undefined
91 // Storage objects. If you get a compiler error involving this object, then it
92 // probably comes from trying to use an ArrayHandle with bad template
93 // arguments.
94 template <typename T>
95 struct UndefinedArrayPortal
96 {
97  VISKORES_STATIC_ASSERT(sizeof(T) == static_cast<size_t>(-1));
98 };
99 
100 } // namespace detail
101 
105 template <typename T, class StorageTag>
106 class Storage
107 #ifndef VISKORES_DOXYGEN_ONLY
108  : public viskores::cont::internal::UndefinedStorage
109 {
110 public:
111  using ReadPortalType = viskores::cont::internal::detail::UndefinedArrayPortal<T>;
112  using WritePortalType = viskores::cont::internal::detail::UndefinedArrayPortal<T>;
113 };
114 #else //VISKORES_DOXYGEN_ONLY
115 {
116 public:
119  using ValueType = T;
120 
123  using ReadPortalType = viskores::internal::ArrayPortalBasicRead<T>;
124 
127  using WritePortalType = viskores::internal::ArrayPortalBasicWrite<T>;
128 
135  VISKORES_CONT static std::vector<viskores::cont::internal::Buffer> CreateBuffers();
136 
141  VISKORES_CONT static void ResizeBuffers(
142  viskores::Id numValues,
143  const std::vector<viskores::cont::internal::Buffer>& buffers,
144  viskores::CopyFlag preserve,
145  viskores::cont::Token& token);
146 
148  VISKORES_CONT static viskores::Id GetNumberOfValues(
149  const std::vector<viskores::cont::internal::Buffer>& buffers);
150 
153  VISKORES_CONT static void Fill(const std::vector<viskores::cont::internal::Buffer>& buffers,
154  const ValueType& fillValue,
155  viskores::Id startIndex,
156  viskores::Id endIndex,
157  viskores::cont::Token& token);
158 
161  VISKORES_CONT static ReadPortalType CreateReadPortal(
162  const std::vector<viskores::cont::internal::Buffer>& buffers,
164  viskores::cont::Token& token);
165 
168  VISKORES_CONT static WritePortalType CreateWritePortal(
169  const std::vector<viskores::cont::internal::Buffer>& buffers,
171  viskores::cont::Token& token)
172 };
173 #endif // VISKORES_DOXYGEN_ONLY
174 
175 namespace detail
176 {
177 
178 VISKORES_CONT_EXPORT void StorageNoResizeImpl(viskores::Id currentNumValues,
179  viskores::Id requestedNumValues,
180  std::string storageTagName);
181 
182 } // namespace detail
183 
184 template <typename StorageType>
185 struct StorageTraits;
186 
187 template <typename T, typename S>
188 struct StorageTraits<viskores::cont::internal::Storage<T, S>>
189 {
190  using ValueType = T;
191  using Tag = S;
192 };
193 
194 #define VISKORES_STORAGE_NO_RESIZE \
195  VISKORES_CONT static void ResizeBuffers( \
196  viskores::Id numValues, \
197  const std::vector<viskores::cont::internal::Buffer>& buffers, \
198  viskores::CopyFlag, \
199  viskores::cont::Token&) \
200  { \
201  viskores::cont::internal::detail::StorageNoResizeImpl( \
202  GetNumberOfValues(buffers), \
203  numValues, \
204  viskores::cont::TypeToString< \
205  typename viskores::cont::internal::StorageTraits<Storage>::Tag>()); \
206  } \
207  using ResizeBuffersEatComma = void
208 
209 #define VISKORES_STORAGE_NO_WRITE_PORTAL \
210  using WritePortalType = viskores::internal::ArrayPortalDummy< \
211  typename viskores::cont::internal::StorageTraits<Storage>::ValueType>; \
212  VISKORES_CONT static void Fill( \
213  const std::vector<viskores::cont::internal::Buffer>&, \
214  const typename viskores::cont::internal::StorageTraits<Storage>::ValueType&, \
215  viskores::Id, \
216  viskores::Id, \
217  viskores::cont::Token&) \
218  { \
219  throw viskores::cont::ErrorBadAllocation( \
220  "Cannot write to arrays with storage type of " + \
221  viskores::cont::TypeToString< \
222  typename viskores::cont::internal::StorageTraits<Storage>::Tag>()); \
223  } \
224  VISKORES_CONT static WritePortalType CreateWritePortal( \
225  const std::vector<viskores::cont::internal::Buffer>&, \
226  viskores::cont::DeviceAdapterId, \
227  viskores::cont::Token&) \
228  { \
229  throw viskores::cont::ErrorBadAllocation( \
230  "Cannot write to arrays with storage type of " + \
231  viskores::cont::TypeToString< \
232  typename viskores::cont::internal::StorageTraits<Storage>::Tag>()); \
233  } \
234  using CreateWritePortalEatComma = void
235 
236 } // namespace internal
237 }
238 } // namespace viskores::cont
239 
240 #endif //viskores_cont_Storage_h
ErrorBadAllocation.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
Buffer.h
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
StaticAssert.h
Flags.h
Logging.h
Logging utilities.
viskores::CopyFlag
CopyFlag
Identifier used to specify whether a function should deep copy data.
Definition: Flags.h:25
Token.h
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
ArrayPortalDummy.h
VISKORES_STATIC_ASSERT
#define VISKORES_STATIC_ASSERT(condition)
Definition: StaticAssert.h:24