mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Merge topic 'portal-check-3d'
5a805b6dc Properly handle Get(Id3) in ArrayPortalCheck Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Robert Maynard <robert.maynard@kitware.com> Merge-request: !1998
This commit is contained in:
commit
60a720d523
@ -101,6 +101,25 @@ public:
|
||||
return this->Superclass::Get(index);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename PT = Superclass,
|
||||
typename std::enable_if<vtkm::internal::PortalSupportsGets3D<PT>::value, int>::type = 0>
|
||||
VTKM_EXEC_CONT typename Superclass::ValueType Get(vtkm::Id3 index) const
|
||||
{
|
||||
if (!(*this->Valid))
|
||||
{
|
||||
VTKM_LOG_F(vtkm::cont::LogLevel::Fatal,
|
||||
"Attempted to read from an ArrayPortal whose data has been deleted.");
|
||||
return typename Superclass::ValueType{};
|
||||
}
|
||||
// Technically, this is not perfectly thread safe. It is possible that the check above
|
||||
// passed and then another thread has deleted the underlying array before we got here.
|
||||
// However, any case in which this portal is used where such a condition can possible
|
||||
// happen is a grevious error. In which case a different run is likely to give the
|
||||
// correct error and the problem can be fixed.
|
||||
return this->Superclass::Get(index);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename PT = Superclass,
|
||||
typename std::enable_if<vtkm::internal::PortalSupportsSets<PT>::value, int>::type = 0>
|
||||
@ -120,6 +139,25 @@ public:
|
||||
this->Superclass::Set(index, value);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename PT = Superclass,
|
||||
typename std::enable_if<vtkm::internal::PortalSupportsSets3D<PT>::value, int>::type = 0>
|
||||
VTKM_EXEC_CONT void Set(vtkm::Id3 index, typename Superclass::ValueType value) const
|
||||
{
|
||||
if (!(*this->Valid))
|
||||
{
|
||||
VTKM_LOG_F(vtkm::cont::LogLevel::Fatal,
|
||||
"Attempted to write to an ArrayPortal whose data has been deleted.");
|
||||
return;
|
||||
}
|
||||
// Technically, this is not perfectly thread safe. It is possible that the check above
|
||||
// passed and then another thread has deleted the underlying array before we got here.
|
||||
// However, any case in which this portal is used where such a condition can possible
|
||||
// happen is a grevious error. In which case a different run is likely to give the
|
||||
// correct error and the problem can be fixed.
|
||||
this->Superclass::Set(index, value);
|
||||
}
|
||||
|
||||
VTKM_CONT std::shared_ptr<bool> GetValidPointer() const { return this->Valid; }
|
||||
};
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ void TestArrayHandleUniformPointCoordinates()
|
||||
"Array computed wrong number of points.");
|
||||
|
||||
std::cout << "Getting array portal." << std::endl;
|
||||
vtkm::internal::ArrayPortalUniformPointCoordinates portal = arrayHandle.ReadPortal();
|
||||
auto portal = arrayHandle.ReadPortal();
|
||||
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == NUM_POINTS, "Portal has wrong number of points.");
|
||||
VTKM_TEST_ASSERT(portal.GetRange3() == DIMENSIONS, "Portal range is wrong.");
|
||||
|
||||
|
@ -32,6 +32,16 @@ struct PortalSupportsGetsImpl
|
||||
using type = decltype(has<PortalType>(0));
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct PortalSupportsGets3DImpl
|
||||
{
|
||||
template <typename U, typename S = decltype(std::declval<U>().Get(vtkm::Id3{}))>
|
||||
static std::true_type has(int);
|
||||
template <typename U>
|
||||
static std::false_type has(...);
|
||||
using type = decltype(has<PortalType>(0));
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct PortalSupportsSetsImpl
|
||||
{
|
||||
@ -44,6 +54,18 @@ struct PortalSupportsSetsImpl
|
||||
using type = decltype(has<PortalType>(0));
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct PortalSupportsSets3DImpl
|
||||
{
|
||||
template <typename U,
|
||||
typename S = decltype(std::declval<U>().Set(vtkm::Id3{},
|
||||
std::declval<typename U::ValueType>()))>
|
||||
static std::true_type has(int);
|
||||
template <typename U>
|
||||
static std::false_type has(...);
|
||||
using type = decltype(has<PortalType>(0));
|
||||
};
|
||||
|
||||
template <typename PortalType>
|
||||
struct PortalSupportsIteratorsImpl
|
||||
{
|
||||
@ -60,10 +82,18 @@ template <typename PortalType>
|
||||
using PortalSupportsGets =
|
||||
typename detail::PortalSupportsGetsImpl<typename std::decay<PortalType>::type>::type;
|
||||
|
||||
template <typename PortalType>
|
||||
using PortalSupportsGets3D =
|
||||
typename detail::PortalSupportsGets3DImpl<typename std::decay<PortalType>::type>::type;
|
||||
|
||||
template <typename PortalType>
|
||||
using PortalSupportsSets =
|
||||
typename detail::PortalSupportsSetsImpl<typename std::decay<PortalType>::type>::type;
|
||||
|
||||
template <typename PortalType>
|
||||
using PortalSupportsSets3D =
|
||||
typename detail::PortalSupportsSets3DImpl<typename std::decay<PortalType>::type>::type;
|
||||
|
||||
template <typename PortalType>
|
||||
using PortalSupportsIterators =
|
||||
typename detail::PortalSupportsIteratorsImpl<typename std::decay<PortalType>::type>::type;
|
||||
|
Loading…
Reference in New Issue
Block a user