Viskores  1.0
ExecutionAndControlObjectBase.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_ExecutionAndControlObjectBase_h
19 #define viskores_cont_ExecutionAndControlObjectBase_h
20 
22 
23 namespace viskores
24 {
25 namespace cont
26 {
27 
37 {
38 };
39 
40 namespace internal
41 {
42 
43 namespace detail
44 {
45 
46 struct CheckPrepareForControl
47 {
48  template <typename T>
49  static auto check(T* p) -> decltype(p->PrepareForControl(), std::true_type());
50 
51  template <typename T>
52  static auto check(...) -> std::false_type;
53 };
54 
55 } // namespace detail
56 
57 template <typename T>
58 using IsExecutionAndControlObjectBase =
59  std::is_base_of<viskores::cont::ExecutionAndControlObjectBase, typename std::decay<T>::type>;
60 
61 template <typename T>
62 struct HasPrepareForControl
63  : decltype(detail::CheckPrepareForControl::check<typename std::decay<T>::type>(nullptr))
64 {
65 };
66 
69 #define VISKORES_IS_EXECUTION_AND_CONTROL_OBJECT(execObject) \
70  static_assert( \
71  ::viskores::cont::internal::IsExecutionAndControlObjectBase<execObject>::value, \
72  "Provided type is not a subclass of viskores::cont::ExecutionAndControlObjectBase."); \
73  static_assert(::viskores::cont::internal::HasPrepareForExecution<execObject>::value, \
74  "Provided type does not have requisite PrepareForExecution method."); \
75  static_assert(::viskores::cont::internal::HasPrepareForControl<execObject>::value, \
76  "Provided type does not have requisite PrepareForControl method.")
77 
85 template <typename T>
86 VISKORES_CONT auto CallPrepareForControl(T&& execObject) -> decltype(execObject.PrepareForControl())
87 {
89 
90  return execObject.PrepareForControl();
91 }
92 
101 template <typename ExecutionAndControlObject>
102 using ControlObjectType =
103  decltype(CallPrepareForControl(std::declval<ExecutionAndControlObject>()));
104 
105 } // namespace internal
106 }
107 } // namespace viskores::cont
108 
109 #endif //viskores_cont_ExecutionAndControlObjectBase_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::ExecutionAndControlObjectBase
Base ExecutionAndControlObjectBase class.
Definition: ExecutionAndControlObjectBase.h:36
VISKORES_IS_EXECUTION_AND_CONTROL_OBJECT
#define VISKORES_IS_EXECUTION_AND_CONTROL_OBJECT(execObject)
Checks that the argument is a proper execution object.
Definition: ExecutionAndControlObjectBase.h:69
ExecutionObjectBase.h
viskores::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:39