VTK-m  2.2
FunctionInterface.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_internal_FunctionInterface_h
11 #define vtk_m_internal_FunctionInterface_h
12 
13 #include <vtkm/Deprecated.h>
14 #include <vtkm/Types.h>
15 
17 #include <vtkm/internal/IndexTag.h>
18 
19 #include <utility>
20 
21 namespace vtkm
22 {
23 namespace internal
24 {
25 
26 namespace detail
27 {
28 
29 template <typename OriginalSignature, typename Transform>
30 struct FunctionInterfaceStaticTransformType;
31 
32 
33 } // namespace detail
34 
97 template <typename FunctionSignature>
98 class FunctionInterface
99 {
100  template <typename OtherSignature>
101  friend class FunctionInterface;
102 
103 public:
104  using Signature = FunctionSignature;
105 
107  FunctionInterface()
108  : Parameters()
109  {
110  }
111 
113  explicit FunctionInterface(const detail::ParameterContainer<FunctionSignature>& p)
114  : Parameters(p)
115  {
116  }
117 
118  // the number of parameters as an integral constant
119  using SigInfo = detail::FunctionSigInfo<FunctionSignature>;
120  using ComponentSig = typename SigInfo::Components;
121  using ParameterSig = typename SigInfo::Parameters;
122 
123  template <vtkm::IdComponent ParameterIndex>
124  struct ParameterType
125  {
126  using type = typename detail::AtType<ParameterIndex, FunctionSignature>::type;
127  };
128 
131  static constexpr vtkm::IdComponent ARITY = SigInfo::Arity;
132 
137  vtkm::IdComponent GetArity() const { return ARITY; }
138 
139  template <typename Transform>
140  struct StaticTransformType
141  {
142  using type = FunctionInterface<
143  typename detail::FunctionInterfaceStaticTransformType<FunctionSignature, Transform>::type>;
144  };
145 
191  template <typename Transform>
192  VTKM_CONT typename StaticTransformType<Transform>::type StaticTransformCont(
193  const Transform& transform)
194  {
195  using FuncIface = typename StaticTransformType<Transform>::type;
196  using PC = detail::ParameterContainer<typename FuncIface::Signature>;
197  return FuncIface{ detail::DoStaticTransformCont<PC>(transform, this->Parameters) };
198  }
199 
200  detail::ParameterContainer<FunctionSignature> Parameters;
201 };
202 
215 template <vtkm::IdComponent ParameterIndex, typename FunctionSignature>
216 VTKM_EXEC_CONT auto ParameterGet(const FunctionInterface<FunctionSignature>& fInterface)
217  -> decltype(detail::ParameterGet(fInterface.Parameters,
218  vtkm::internal::IndexTag<ParameterIndex>{}))
219 {
220  return detail::ParameterGet(fInterface.Parameters, vtkm::internal::IndexTag<ParameterIndex>{});
221 }
222 
223 
224 //============================================================================
237 
238 template <typename R, typename... Args>
239 FunctionInterface<R(Args...)> make_FunctionInterface(const Args&... args)
240 {
241 // MSVC will issue deprecation warnings if this templated method is instantiated with
242 // a deprecated class here even if the method is called from a section of code where
243 // deprecation warnings are suppressed. This is annoying behavior since this templated
244 // method has no control over what class it is used from. To get around it, we have to
245 // suppress all deprecation warnings here.
246 #ifdef VTKM_MSVC
248 #endif
249  detail::ParameterContainer<R(Args...)> container = { args... };
250  return FunctionInterface<R(Args...)>{ container };
251 #ifdef VTKM_MSVC
253 #endif
254 }
255 }
256 } // namespace vtkm::internal
257 
259 
260 #endif //vtk_m_internal_FunctionInterface_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::Transform
auto Transform(const TupleType &&tuple, Function &&f) -> decltype(Apply(tuple, detail::TupleTransformFunctor(), std::forward< Function >(f)))
Construct a new vtkm::Tuple by applying a function to each value.
Definition: Tuple.h:213
VTKM_DEPRECATED_SUPPRESS_END
#define VTKM_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:123
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
VTKM_DEPRECATED_SUPPRESS_BEGIN
#define VTKM_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:122
Deprecated.h
VTKM_SUPPRESS_EXEC_WARNINGS
#define VTKM_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:53
IndexTag.h
FunctionInterfaceDetailPost.h
FunctionInterfaceDetailPre.h