VTK-m  2.0
ExecutionObjectBase.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_ExecutionObjectBase_h
11 #define vtk_m_cont_ExecutionObjectBase_h
12 
13 #include <vtkm/Types.h>
14 
15 #include <vtkm/cont/Token.h>
16 
18 
19 namespace vtkm
20 {
21 namespace cont
22 {
23 
32 {
33 };
34 
35 namespace internal
36 {
37 
38 namespace detail
39 {
40 
41 struct CheckPrepareForExecution
42 {
43  template <typename T>
44  static auto check(T* p) -> decltype(p->PrepareForExecution(vtkm::cont::DeviceAdapterTagSerial{},
45  std::declval<vtkm::cont::Token&>()),
46  std::true_type());
47 
48  template <typename T>
49  static auto check(...) -> std::false_type;
50 };
51 
52 } // namespace detail
53 
54 template <typename T>
55 using IsExecutionObjectBase =
56  typename std::is_base_of<vtkm::cont::ExecutionObjectBase, typename std::decay<T>::type>::type;
57 
58 template <typename T>
59 struct HasPrepareForExecution
60  : decltype(detail::CheckPrepareForExecution::check<typename std::decay<T>::type>(nullptr))
61 {
62 };
63 
66 #define VTKM_IS_EXECUTION_OBJECT(execObject) \
67  static_assert(::vtkm::cont::internal::IsExecutionObjectBase<execObject>::value, \
68  "Provided type is not a subclass of vtkm::cont::ExecutionObjectBase."); \
69  static_assert(::vtkm::cont::internal::HasPrepareForExecution<execObject>::value, \
70  "Provided type does not have requisite PrepareForExecution method.")
71 
80 template <typename T, typename Device>
81 VTKM_CONT auto CallPrepareForExecution(T&& execObject, Device device, vtkm::cont::Token& token)
82  -> decltype(execObject.PrepareForExecution(device, token))
83 {
86 
87  return execObject.PrepareForExecution(device, token);
88 }
89 
90 template <typename T>
91 VTKM_CONT auto CallPrepareForExecution(T&& execObject,
93  vtkm::cont::Token& token)
94  -> decltype(execObject.PrepareForExecution(device, token))
95 {
97 
98  return execObject.PrepareForExecution(device, token);
99 }
101 
109 template <typename ExecutionObject, typename Device = vtkm::cont::DeviceAdapterId>
110 using ExecutionObjectType = decltype(CallPrepareForExecution(std::declval<ExecutionObject>(),
111  std::declval<Device>(),
112  std::declval<vtkm::cont::Token&>()));
113 
114 } // namespace internal
115 }
116 } // namespace vtkm::cont
117 
118 #endif //vtk_m_cont_ExecutionObjectBase_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
DeviceAdapterTagSerial.h
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
VTKM_IS_EXECUTION_OBJECT
#define VTKM_IS_EXECUTION_OBJECT(execObject)
Checks that the argument is a proper execution object.
Definition: ExecutionObjectBase.h:66
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
Token.h
VTKM_IS_DEVICE_ADAPTER_TAG
#define VTKM_IS_DEVICE_ADAPTER_TAG(tag)
Checks that the argument is a proper device adapter tag.
Definition: DeviceAdapterTag.h:164