mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 09:59:12 +00:00
7811cc4b1e
Many of the fancy `ArrayHandle`s are read-only and therefore connot really create write portals. Likewise, many `ArrayHandle`s (both read- only and read/write) have no way to resize themselves. In this case, implementing the `CreateWritePortal` and `ResizeBuffers` methods in the `Storage` class was troublesome. Mostly they just threw an exception, but they also sometimes had to deal with cases where the behavior was allowed. To simplify code for developers, this introduces a pair of macros: `VTKM_STORAGE_NO_RESIZE` and `VTKM_STORAGE_NO_WRITE_PORTAL`. These can be declared in a `Storage` implementation when the storage has no viable way to resize itself and create a write portal, respectively. Having boilerplate code for these methods also helps work around expected behavior for `ResizeBuffers`. `ResizeBuffers` should silently work when resizing to the same size. Also `ResizeBuffers` should behave well when resizing to 0 as that is what `ReleaseResources` does.
42 lines
1.2 KiB
C++
42 lines
1.2 KiB
C++
//============================================================================
|
|
// Copyright (c) Kitware, Inc.
|
|
// All rights reserved.
|
|
// See LICENSE.txt for details.
|
|
//
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
//============================================================================
|
|
#ifndef vtk_m_internal_ArrayPortalDummy
|
|
#define vtk_m_internal_ArrayPortalDummy
|
|
|
|
#include <vtkm/Assert.h>
|
|
#include <vtkm/Types.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace internal
|
|
{
|
|
|
|
/// A class that can be used in place of an `ArrayPortal` when the `ArrayPortal` is
|
|
/// not actually supported. It allows templates to be compiled, but will cause undefined
|
|
/// behavior if actually used.
|
|
template <typename T>
|
|
struct ArrayPortalDummy
|
|
{
|
|
using ValueType = T;
|
|
|
|
VTKM_EXEC_CONT vtkm::Id GetNumberOfValues() const { return 0; }
|
|
|
|
VTKM_EXEC_CONT ValueType Get(vtkm::Id) const
|
|
{
|
|
VTKM_ASSERT(false && "Tried to use a dummy portal.");
|
|
return ValueType{};
|
|
}
|
|
};
|
|
|
|
}
|
|
} // namespace vtkm::internal
|
|
|
|
#endif //vtk_m_internal_ArrayPortalDummy
|