17 #ifndef vtkmlib_Storage_h
18 #define vtkmlib_Storage_h
23 #include <vtkm/cont/Storage.h>
29 template <
typename ValueType_>
30 class VTKM_ALWAYS_EXPORT Storage<ValueType_,
tovtkm::vtkAOSArrayContainerTag>
45 DeallocateOnRelease(false),
46 UserProvidedMemory(false)
53 NumberOfValues(array->GetNumberOfTuples()),
54 AllocatedSize(array->GetNumberOfTuples() * NUM_COMPONENTS),
55 DeallocateOnRelease(false),
56 UserProvidedMemory(true)
62 this->ReleaseResources();
66 operator=(
const Storage<ValueType, tovtkm::vtkAOSArrayContainerTag>& src)
68 if (src.DeallocateOnRelease)
70 throw vtkm::cont::ErrorBadValue(
71 "Attempted to copy a storage array that needs deallocation. "
72 "This is disallowed to prevent complications with deallocation.");
75 this->ReleaseResources();
76 this->Array = src.Array;
77 this->NumberOfValues = src.NumberOfValues;
78 this->AllocatedSize = src.AllocatedSize;
79 this->DeallocateOnRelease = src.DeallocateOnRelease;
80 this->UserProvidedMemory = src.UserProvidedMemory;
85 void ReleaseResources();
87 void Allocate(vtkm::Id numberOfValues);
91 return this->NumberOfValues;
96 if (numberOfValues > this->GetNumberOfValues())
98 throw vtkm::cont::ErrorBadValue(
99 "Shrink method cannot be used to grow array.");
102 this->NumberOfValues = numberOfValues;
105 PortalType GetPortal();
107 PortalConstType GetPortalConst()
const;
116 vtkm::Id NumberOfValues;
117 vtkm::Id AllocatedSize;
118 bool DeallocateOnRelease;
119 bool UserProvidedMemory;
122 template <
typename ValueType_>
123 class VTKM_ALWAYS_EXPORT Storage<ValueType_,
tovtkm::vtkSOAArrayContainerTag>
139 DeallocateOnRelease(false),
140 UserProvidedMemory(false)
146 NumberOfValues(array->GetNumberOfTuples()),
147 AllocatedSize(array->GetNumberOfTuples() * NUM_COMPONENTS),
148 DeallocateOnRelease(false),
149 UserProvidedMemory(true)
155 this->ReleaseResources();
161 if (src.DeallocateOnRelease)
163 throw vtkm::cont::ErrorBadValue(
164 "Attempted to copy a storage array that needs deallocation. "
165 "This is disallowed to prevent complications with deallocation.");
168 this->ReleaseResources();
169 this->Array = src.Array;
170 this->NumberOfValues = src.NumberOfValues;
171 this->AllocatedSize = src.AllocatedSize;
172 this->DeallocateOnRelease = src.DeallocateOnRelease;
173 this->UserProvidedMemory = src.UserProvidedMemory;
178 void ReleaseResources();
180 void Allocate(vtkm::Id numberOfValues);
184 return this->NumberOfValues;
189 if (numberOfValues > this->GetNumberOfValues())
191 throw vtkm::cont::ErrorBadValue(
192 "Shrink method cannot be used to grow array.");
195 this->NumberOfValues = numberOfValues;
198 PortalType GetPortal();
200 PortalConstType GetPortalConst()
const;
209 vtkm::Id NumberOfValues;
210 vtkm::Id AllocatedSize;
211 bool DeallocateOnRelease;
212 bool UserProvidedMemory;
215 template <
typename ValueType_>
216 class VTKM_ALWAYS_EXPORT Storage<ValueType_,
tovtkm::vtkCellArrayContainerTag>
229 DeallocateOnRelease(false),
230 UserProvidedMemory(false)
236 NumberOfValues(array->GetNumberOfConnectivityEntries()),
237 AllocatedSize(array->GetSize()),
238 DeallocateOnRelease(false),
239 UserProvidedMemory(true)
245 this->ReleaseResources();
251 if (src.DeallocateOnRelease)
253 throw vtkm::cont::ErrorBadValue(
254 "Attempted to copy a storage array that needs deallocation. "
255 "This is disallowed to prevent complications with deallocation.");
258 this->ReleaseResources();
259 this->Array = src.Array;
260 this->NumberOfValues = src.NumberOfValues;
261 this->AllocatedSize = src.AllocatedSize;
262 this->DeallocateOnRelease = src.DeallocateOnRelease;
263 this->UserProvidedMemory = src.UserProvidedMemory;
268 void ReleaseResources();
270 void Allocate(vtkm::Id numberOfValues);
274 return this->NumberOfValues;
279 if (numberOfValues > this->GetNumberOfValues())
281 throw vtkm::cont::ErrorBadValue(
282 "Shrink method cannot be used to grow array.");
285 this->NumberOfValues = numberOfValues;
288 PortalType GetPortal();
290 PortalConstType GetPortalConst()
const;
299 vtkm::Id NumberOfValues;
300 vtkm::Id AllocatedSize;
301 bool DeallocateOnRelease;
302 bool UserProvidedMemory;
308 #define VTKM_TEMPLATE_EXPORT_Storage(T, S) \
309 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<const T, S>; \
310 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<T, S>; \
311 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT \
312 Storage<const vtkm::Vec<T, 2>, S>; \
313 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT \
314 Storage<vtkm::Vec<T, 2>, S>; \
315 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT \
316 Storage<const vtkm::Vec<T, 3>, S>; \
317 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT \
318 Storage<vtkm::Vec<T, 3>, S>; \
319 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT \
320 Storage<const vtkm::Vec<T, 4>, S>; \
321 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<vtkm::Vec<T, 4>, S>;
323 #define VTKM_TEMPLATE_IMPORT_Storage(T, S) \
324 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<const T, S>; \
325 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<T, S>; \
326 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<const vtkm::Vec<T, 2>, S>; \
327 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<vtkm::Vec<T, 2>, S>; \
328 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<const vtkm::Vec<T, 3>, S>; \
329 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<vtkm::Vec<T, 3>, S>; \
330 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<const vtkm::Vec<T, 4>, S>; \
331 template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT Storage<vtkm::Vec<T, 4>, S>;
333 #ifndef vtkmlib_Storage_cxx
362 #if VTKM_SIZE_LONG_LONG == 8
370 extern template class VTKACCELERATORSVTKM_TEMPLATE_EXPORT
371 Storage<vtkIdType, tovtkm::vtkCellArrayContainerTag>;
376 #endif // defined vtkmlib_Storage_cxx
378 #include "Storage.hxx"
380 #endif // vtkmlib_Storage_h