VTK-m  2.0
Placeholders.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_worklet_internal_Placeholders_h
11 #define vtk_m_worklet_internal_Placeholders_h
12 
13 #include <vtkmstd/integer_sequence.h>
14 
15 #include <type_traits>
16 
17 #include <vtkm/exec/arg/BasicArg.h>
18 
19 namespace vtkm
20 {
21 namespace placeholders
22 {
23 
24 //============================================================================
25 template <int ControlSignatureIndex>
26 struct Arg : vtkm::exec::arg::BasicArg<ControlSignatureIndex>
27 {
28 };
29 
30 //============================================================================
34 template <typename>
35 struct FunctionSigArity;
36 template <typename R, typename... ArgTypes>
37 struct FunctionSigArity<R(ArgTypes...)>
38 {
39  static constexpr std::size_t value = sizeof...(ArgTypes);
40 };
41 
42 //============================================================================
43 template <int... Args>
44 auto DefaultSigGenerator(vtkmstd::integer_sequence<int, 0, Args...>) -> void (*)(Arg<Args>...);
45 
55 template <int Length>
56 struct DefaultExecSig
57 {
58  using seq = vtkmstd::make_integer_sequence<int, Length + 1>;
59  using type = typename std::remove_pointer<decltype(DefaultSigGenerator(seq{}))>::type;
60 };
61 template <>
62 struct DefaultExecSig<1>
63 {
64  using type = void(Arg<1>);
65 };
66 template <>
67 struct DefaultExecSig<2>
68 {
69  using type = void(Arg<1>, Arg<2>);
70 };
71 template <>
72 struct DefaultExecSig<3>
73 {
74  using type = void(Arg<1>, Arg<2>, Arg<3>);
75 };
76 template <>
77 struct DefaultExecSig<4>
78 {
79  using type = void(Arg<1>, Arg<2>, Arg<3>, Arg<4>);
80 };
81 
82 template <bool HasExecSig_, typename Sig_>
83 struct ExecSigQuery
84 {
85  static constexpr bool HasExecSig = HasExecSig_;
86  using Sig = Sig_;
87 };
88 
89 template <typename U, typename S = decltype(std::declval<typename U::ExecutionSignature>())>
90 static ExecSigQuery<true, typename U::ExecutionSignature> get_exec_sig(int);
91 
92 template <typename U>
93 static ExecSigQuery<false, void> get_exec_sig(...);
94 
95 //============================================================================
110 template <typename WorkletType>
111 struct GetExecSig
112 {
113  using cont_sig = typename WorkletType::ControlSignature;
114  using cont_sig_info = vtkm::placeholders::FunctionSigArity<cont_sig>;
115 
116  using result = decltype(get_exec_sig<WorkletType>(0));
117  static constexpr bool has_explicit_exec_sig = result::HasExecSig;
118 
119  using ExecutionSignature = typename std::conditional<
120  has_explicit_exec_sig,
121  typename result::Sig,
122  typename vtkm::placeholders::DefaultExecSig<cont_sig_info::value>::type>::type;
123 };
124 }
125 }
126 
127 #endif
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::exec::arg::BasicArg
The underlying tag for basic ExecutionSignature arguments.
Definition: BasicArg.h:32
BasicArg.h