Viskores  1.0
ExecutionObjectBase.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_ExecutionObjectBase_h
19 #define viskores_cont_ExecutionObjectBase_h
20 
21 #include <viskores/Types.h>
22 
23 #include <viskores/cont/Token.h>
24 
26 
27 namespace viskores
28 {
29 namespace cont
30 {
31 
40 {
41 };
42 
43 namespace internal
44 {
45 
46 namespace detail
47 {
48 
49 struct CheckPrepareForExecution
50 {
51  template <typename T>
52  static auto check(T* p)
53  -> decltype(p->PrepareForExecution(viskores::cont::DeviceAdapterTagSerial{},
54  std::declval<viskores::cont::Token&>()),
55  std::true_type());
56 
57  template <typename T>
58  static auto check(...) -> std::false_type;
59 };
60 
61 } // namespace detail
62 
63 template <typename T>
64 using IsExecutionObjectBase =
65  typename std::is_base_of<viskores::cont::ExecutionObjectBase, typename std::decay<T>::type>::type;
66 
67 template <typename T>
68 struct HasPrepareForExecution
69  : decltype(detail::CheckPrepareForExecution::check<typename std::decay<T>::type>(nullptr))
70 {
71 };
72 
75 #define VISKORES_IS_EXECUTION_OBJECT(execObject) \
76  static_assert(::viskores::cont::internal::IsExecutionObjectBase<execObject>::value, \
77  "Provided type is not a subclass of viskores::cont::ExecutionObjectBase."); \
78  static_assert(::viskores::cont::internal::HasPrepareForExecution<execObject>::value, \
79  "Provided type does not have requisite PrepareForExecution method.")
80 
89 template <typename T, typename Device>
90 VISKORES_CONT auto CallPrepareForExecution(T&& execObject,
91  Device device,
92  viskores::cont::Token& token)
93  -> decltype(execObject.PrepareForExecution(device, token))
94 {
97 
98  return execObject.PrepareForExecution(device, token);
99 }
100 
101 template <typename T>
102 VISKORES_CONT auto CallPrepareForExecution(T&& execObject,
104  viskores::cont::Token& token)
105  -> decltype(execObject.PrepareForExecution(device, token))
106 {
108 
109  return execObject.PrepareForExecution(device, token);
110 }
112 
120 template <typename ExecutionObject, typename Device = viskores::cont::DeviceAdapterId>
121 using ExecutionObjectType =
122  decltype(CallPrepareForExecution(std::declval<ExecutionObject>(),
123  std::declval<Device>(),
124  std::declval<viskores::cont::Token&>()));
125 
126 } // namespace internal
127 }
128 } // namespace viskores::cont
129 
130 #endif //viskores_cont_ExecutionObjectBase_h
Types.h
VISKORES_IS_EXECUTION_OBJECT
#define VISKORES_IS_EXECUTION_OBJECT(execObject)
Checks that the argument is a proper execution object.
Definition: ExecutionObjectBase.h:75
DeviceAdapterTagSerial.h
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::DeviceAdapterTagSerial
Tag for a device adapter that performs all computation on the same single thread as the control envir...
Definition: DeviceAdapterTagSerial.h:30
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
VISKORES_IS_DEVICE_ADAPTER_TAG
#define VISKORES_IS_DEVICE_ADAPTER_TAG(tag)
Checks that the argument is a proper device adapter tag.
Definition: DeviceAdapterTag.h:208
Token.h
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
viskores::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:39