Type check input and output array arguments differently

Read-only arrays (usually) do not define Set methods. Thus, using one in
an Invoke argument that does output will result in compile errors. To
help avoid that, modify the type checks to differentiate input and
output arrays.
This commit is contained in:
Kenneth Moreland 2020-03-19 15:02:54 -06:00
parent 35276434bd
commit 76f870150b
12 changed files with 272 additions and 77 deletions

@ -27,7 +27,9 @@ set(headers
TransportTagWholeArrayInOut.h
TransportTagWholeArrayOut.h
TypeCheck.h
TypeCheckTagArray.h
TypeCheckTagArrayIn.h
TypeCheckTagArrayInOut.h
TypeCheckTagArrayOut.h
TypeCheckTagAtomicArray.h
TypeCheckTagBitField.h
TypeCheckTagCellSet.h

@ -1,42 +0,0 @@
//============================================================================
// 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_cont_arg_TypeCheckTagArray_h
#define vtk_m_cont_arg_TypeCheckTagArray_h
#include <vtkm/cont/arg/TypeCheck.h>
#include <vtkm/List.h>
#include <vtkm/cont/ArrayHandle.h>
namespace vtkm
{
namespace cont
{
namespace arg
{
/// The Array type check passes for any object that behaves like an \c
/// ArrayHandle class and can be passed to the ArrayIn and ArrayOut transports.
///
struct TypeCheckTagArray
{
};
template <typename ArrayType>
struct TypeCheck<TypeCheckTagArray, ArrayType>
{
static constexpr bool value = vtkm::cont::internal::ArrayHandleCheck<ArrayType>::type::value;
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TypeCheckTagArray_h

@ -0,0 +1,66 @@
//============================================================================
// 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_cont_arg_TypeCheckTagArrayIn_h
#define vtk_m_cont_arg_TypeCheckTagArrayIn_h
#include <vtkm/cont/arg/TypeCheck.h>
#include <vtkm/List.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/internal/ArrayPortalHelpers.h>
namespace vtkm
{
namespace cont
{
namespace arg
{
/// The Array type check passes for any object that behaves like an \c
/// ArrayHandle class and can be passed to the ArrayIn transport.
///
struct TypeCheckTagArrayIn
{
};
namespace detail
{
template <typename ArrayType,
bool IsArrayHandle = vtkm::cont::internal::ArrayHandleCheck<ArrayType>::type::value>
struct IsArrayHandleIn;
template <typename ArrayType>
struct IsArrayHandleIn<ArrayType, true>
{
static constexpr bool value =
vtkm::internal::PortalSupportsGets<typename ArrayType::ReadPortalType>::value;
};
template <typename ArrayType>
struct IsArrayHandleIn<ArrayType, false>
{
static constexpr bool value = false;
};
} // namespace detail
template <typename ArrayType>
struct TypeCheck<TypeCheckTagArrayIn, ArrayType>
{
static constexpr bool value = detail::IsArrayHandleIn<ArrayType>::value;
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TypeCheckTagArray_h

@ -0,0 +1,67 @@
//============================================================================
// 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_cont_arg_TypeCheckTagArrayInOut_h
#define vtk_m_cont_arg_TypeCheckTagArrayInOut_h
#include <vtkm/cont/arg/TypeCheck.h>
#include <vtkm/List.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/internal/ArrayPortalHelpers.h>
namespace vtkm
{
namespace cont
{
namespace arg
{
/// The Array type check passes for any object that behaves like an
/// `ArrayHandle` class and can be passed to the ArrayInOut transport.
///
struct TypeCheckTagArrayInOut
{
};
namespace detail
{
template <typename ArrayType,
bool IsArrayHandle = vtkm::cont::internal::ArrayHandleCheck<ArrayType>::type::value>
struct IsArrayHandleInOut;
template <typename ArrayType>
struct IsArrayHandleInOut<ArrayType, true>
{
static constexpr bool value =
(vtkm::internal::PortalSupportsGets<typename ArrayType::ReadPortalType>::value &&
vtkm::internal::PortalSupportsSets<typename ArrayType::WritePortalType>::value);
};
template <typename ArrayType>
struct IsArrayHandleInOut<ArrayType, false>
{
static constexpr bool value = false;
};
} // namespace detail
template <typename ArrayType>
struct TypeCheck<TypeCheckTagArrayInOut, ArrayType>
{
static constexpr bool value = detail::IsArrayHandleInOut<ArrayType>::value;
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TypeCheckTagArray_h

@ -0,0 +1,67 @@
//============================================================================
// 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_cont_arg_TypeCheckTagArrayOut_h
#define vtk_m_cont_arg_TypeCheckTagArrayOut_h
#include <vtkm/cont/arg/TypeCheck.h>
#include <vtkm/List.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/internal/ArrayPortalHelpers.h>
namespace vtkm
{
namespace cont
{
namespace arg
{
/// The Array type check passes for any object that behaves like an
/// `ArrayHandle` class and can be passed to the ArrayOut transport.
///
struct TypeCheckTagArrayOut
{
};
namespace detail
{
template <typename ArrayType,
bool IsArrayHandle = vtkm::cont::internal::ArrayHandleCheck<ArrayType>::type::value>
struct IsArrayHandleOut;
template <typename ArrayType>
struct IsArrayHandleOut<ArrayType, true>
{
static constexpr bool value =
(vtkm::internal::PortalSupportsGets<typename ArrayType::ReadPortalType>::value &&
vtkm::internal::PortalSupportsSets<typename ArrayType::WritePortalType>::value);
};
template <typename ArrayType>
struct IsArrayHandleOut<ArrayType, false>
{
static constexpr bool value = false;
};
} // namespace detail
template <typename ArrayType>
struct TypeCheck<TypeCheckTagArrayOut, ArrayType>
{
static constexpr bool value = detail::IsArrayHandleOut<ArrayType>::value;
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TypeCheckTagArray_h

@ -12,7 +12,7 @@
#include <vtkm/cont/arg/TypeCheck.h>
#include <vtkm/cont/CellSet.h>
#include <vtkm/cont/CellSetStructured.h>
namespace vtkm
{

@ -8,7 +8,9 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagAtomicArray.h>
#include <vtkm/cont/ArrayHandle.h>
@ -26,27 +28,50 @@ struct TryArraysOfType
void operator()(T) const
{
using vtkm::cont::arg::TypeCheck;
using vtkm::cont::arg::TypeCheckTagArray;
using vtkm::cont::arg::TypeCheckTagArrayIn;
using vtkm::cont::arg::TypeCheckTagArrayInOut;
using vtkm::cont::arg::TypeCheckTagArrayOut;
using StandardArray = vtkm::cont::ArrayHandle<T>;
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArray, StandardArray>::value),
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayIn, StandardArray>::value),
"Standard array type check failed.");
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayInOut, StandardArray>::value),
"Standard array type check failed.");
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayOut, StandardArray>::value),
"Standard array type check failed.");
using CountingArray = vtkm::cont::ArrayHandleCounting<T>;
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArray, CountingArray>::value),
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayIn, CountingArray>::value),
"Counting array type check failed.");
VTKM_TEST_ASSERT((!TypeCheck<TypeCheckTagArrayInOut, CountingArray>::value),
"Counting array type check failed.");
VTKM_TEST_ASSERT((!TypeCheck<TypeCheckTagArrayOut, CountingArray>::value),
"Counting array type check failed.");
using CompositeArray = vtkm::cont::ArrayHandleCompositeVector<StandardArray, CountingArray>;
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArray, CompositeArray>::value),
using CompositeArray = vtkm::cont::ArrayHandleCompositeVector<StandardArray, StandardArray>;
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayIn, CompositeArray>::value),
"Composite array type check failed.");
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayInOut, CountingArray>::value),
"Counting array type check failed.");
VTKM_TEST_ASSERT((TypeCheck<TypeCheckTagArrayOut, CountingArray>::value),
"Counting array type check failed.");
// Just some type that is not a valid array.
using NotAnArray = typename StandardArray::WritePortalType;
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArray, NotAnArray>::value),
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayIn, NotAnArray>::value),
"Not an array type check failed.");
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayInOut, NotAnArray>::value),
"Not an array type check failed.");
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayOut, NotAnArray>::value),
"Not an array type check failed.");
// Another type that is not a valid array.
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArray, T>::value), "Not an array type check failed.");
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayIn, T>::value),
"Not an array type check failed.");
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayInOut, T>::value),
"Not an array type check failed.");
VTKM_TEST_ASSERT(!(TypeCheck<TypeCheckTagArrayOut, T>::value),
"Not an array type check failed.");
}
};

@ -16,7 +16,9 @@
#include <vtkm/cont/arg/TransportTagArrayIn.h>
#include <vtkm/cont/arg/TransportTagArrayInOut.h>
#include <vtkm/cont/arg/TransportTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/exec/arg/FetchTagArrayDirectIn.h>
#include <vtkm/exec/arg/FetchTagArrayDirectInOut.h>
@ -47,7 +49,7 @@ public:
///
struct FieldIn : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagArrayIn;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -58,7 +60,7 @@ public:
///
struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut;
};
@ -69,7 +71,7 @@ public:
///
struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayInOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut;
};

@ -19,7 +19,9 @@
#include <vtkm/cont/arg/TransportTagArrayOut.h>
#include <vtkm/cont/arg/TransportTagCellSetIn.h>
#include <vtkm/cont/arg/TransportTagTopologyFieldIn.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagCellSet.h>
#include <vtkm/exec/arg/CellShape.h>
@ -75,7 +77,7 @@ public:
///
struct FieldInVisit : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagTopologyFieldIn<VisitTopologyType>;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -85,7 +87,7 @@ public:
///
struct FieldInIncident : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagTopologyFieldIn<IncidentTopologyType>;
using FetchTag = vtkm::exec::arg::FetchTagArrayTopologyMapIn;
};
@ -97,7 +99,7 @@ public:
///
struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut;
};
@ -107,7 +109,7 @@ public:
///
struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayInOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut;
};

@ -25,7 +25,9 @@
#include <vtkm/cont/arg/TransportTagArrayInOut.h>
#include <vtkm/cont/arg/TransportTagArrayOut.h>
#include <vtkm/cont/arg/TransportTagCellSetIn.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagCellSetStructured.h>
#include <vtkm/exec/arg/Boundary.h>
@ -110,7 +112,7 @@ public:
///
struct FieldIn : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagArrayIn;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -122,7 +124,7 @@ public:
///
struct FieldOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut;
};
@ -134,7 +136,7 @@ public:
///
struct FieldInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayInOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut;
};
@ -166,7 +168,7 @@ public:
///
struct FieldInNeighborhood : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagArrayIn;
using FetchTag = vtkm::exec::arg::FetchTagArrayNeighborhoodIn;
};

@ -19,7 +19,9 @@
#include <vtkm/cont/arg/TransportTagKeyedValuesInOut.h>
#include <vtkm/cont/arg/TransportTagKeyedValuesOut.h>
#include <vtkm/cont/arg/TransportTagKeysIn.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagKeys.h>
#include <vtkm/exec/internal/ReduceByKeyLookup.h>
@ -69,7 +71,7 @@ public:
///
struct ValuesIn : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesIn;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -85,7 +87,7 @@ public:
///
struct ValuesInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesInOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -101,7 +103,7 @@ public:
///
struct ValuesOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagKeyedValuesOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -118,7 +120,7 @@ public:
///
struct ReducedValuesIn : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagArrayIn;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectIn;
};
@ -135,7 +137,7 @@ public:
///
struct ReducedValuesInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayInOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectInOut;
};
@ -149,7 +151,7 @@ public:
///
struct ReducedValuesOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagArrayOut;
using FetchTag = vtkm::exec::arg::FetchTagArrayDirectOut;
};

@ -32,7 +32,9 @@
#include <vtkm/cont/arg/TransportTagWholeArrayIn.h>
#include <vtkm/cont/arg/TransportTagWholeArrayInOut.h>
#include <vtkm/cont/arg/TransportTagWholeArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagArrayIn.h>
#include <vtkm/cont/arg/TypeCheckTagArrayInOut.h>
#include <vtkm/cont/arg/TypeCheckTagArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagAtomicArray.h>
#include <vtkm/cont/arg/TypeCheckTagBitField.h>
#include <vtkm/cont/arg/TypeCheckTagCellSet.h>
@ -140,7 +142,7 @@ public:
///
struct WholeArrayIn : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayIn;
using TransportTag = vtkm::cont::arg::TransportTagWholeArrayIn;
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
};
@ -158,7 +160,7 @@ public:
///
struct WholeArrayOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayOut;
using TransportTag = vtkm::cont::arg::TransportTagWholeArrayOut;
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
};
@ -177,7 +179,7 @@ public:
///
struct WholeArrayInOut : vtkm::cont::arg::ControlSignatureTagBase
{
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArray;
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagArrayInOut;
using TransportTag = vtkm::cont::arg::TransportTagWholeArrayInOut;
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
};