vtk-m/vtkm/cont/ExecutionAndControlObjectBase.h
Kenneth Moreland 2b05487398 Add ExecutionAndControlObjectBase
This is a subclass of ExecutionObject and a superset of its
functionality. In addition to having a PrepareForExecution method, it
also has a PrepareForControl method that gets an object appropriate for
the control environment. This is helpful for situations where you need
code to work in both environments, such as the functor in an
ArrayHandleTransform.

Also added several runtime checks for execution objects and execution
and cotnrol objects.
2018-09-08 11:54:28 -06:00

83 lines
3.0 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.
//
// Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2018 UT-Battelle, LLC.
// Copyright 2018 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_ExecutionAndControlObjectBase_h
#define vtk_m_cont_ExecutionAndControlObjectBase_h
#include <vtkm/cont/ExecutionObjectBase.h>
namespace vtkm
{
namespace cont
{
/// Base \c ExecutionAndControlObjectBase class. These are objects that behave
/// as execution objects but can also be use din the control environment.
/// Any subclass of \c ExecutionAndControlObjectBase must implement a
/// \c PrepareForExecution method that takes a device adapter tag and returns
/// an object for that device as well as a \c PrepareForControl that simply
/// returns an object that works in the control environment.
///
struct ExecutionAndControlObjectBase : vtkm::cont::ExecutionObjectBase
{
};
namespace internal
{
namespace detail
{
struct CheckPrepareForControl
{
template <typename T>
static auto check(T* p) -> decltype(p->PrepareForControl(), std::true_type());
template <typename T>
static auto check(...) -> std::false_type;
};
} // namespace detail
template <typename T>
using IsExecutionAndControlObjectBase =
std::is_base_of<vtkm::cont::ExecutionAndControlObjectBase, typename std::decay<T>::type>;
template <typename T>
struct HasPrepareForControl
: decltype(detail::CheckPrepareForControl::check<typename std::decay<T>::type>(nullptr))
{
};
} // namespace internal
}
} // namespace vtkm::cont
/// Checks that the argument is a proper execution object.
///
#define VTKM_IS_EXECUTION_AND_CONTROL_OBJECT(execObject) \
static_assert(::vtkm::cont::internal::IsExecutionAndControlObjectBase<execObject>::value, \
"Provided type is not a subclass of vtkm::cont::ExecutionAndControlObjectBase."); \
static_assert(::vtkm::cont::internal::HasPrepareForExecution<execObject>::value, \
"Provided type does not have requisite PrepareForExecution method."); \
static_assert(::vtkm::cont::internal::HasPrepareForControl<execObject>::value, \
"Provided type does not have requisite PrepareForControl method.")
#endif //vtk_m_cont_ExecutionAndControlObjectBase_h