Viskores  1.0
FunctionInterface.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_internal_FunctionInterface_h
19 #define viskores_internal_FunctionInterface_h
20 
21 #include <viskores/Deprecated.h>
22 #include <viskores/Types.h>
23 
26 
27 #include <utility>
28 
29 namespace viskores
30 {
31 namespace internal
32 {
33 
34 namespace detail
35 {
36 
37 template <typename OriginalSignature, typename Transform>
38 struct FunctionInterfaceStaticTransformType;
39 
40 
41 } // namespace detail
42 
105 template <typename FunctionSignature>
106 class FunctionInterface
107 {
108  template <typename OtherSignature>
109  friend class FunctionInterface;
110 
111 public:
112  using Signature = FunctionSignature;
113 
115  FunctionInterface()
116  : Parameters()
117  {
118  }
119 
121  explicit FunctionInterface(const detail::ParameterContainer<FunctionSignature>& p)
122  : Parameters(p)
123  {
124  }
125 
126  // the number of parameters as an integral constant
127  using SigInfo = detail::FunctionSigInfo<FunctionSignature>;
128  using ComponentSig = typename SigInfo::Components;
129  using ParameterSig = typename SigInfo::Parameters;
130 
131  template <viskores::IdComponent ParameterIndex>
132  struct ParameterType
133  {
134  using type = typename detail::AtType<ParameterIndex, FunctionSignature>::type;
135  };
136 
139  static constexpr viskores::IdComponent ARITY = SigInfo::Arity;
140 
145  viskores::IdComponent GetArity() const { return ARITY; }
146 
147  template <typename Transform>
148  struct StaticTransformType
149  {
150  using type = FunctionInterface<
151  typename detail::FunctionInterfaceStaticTransformType<FunctionSignature, Transform>::type>;
152  };
153 
199  template <typename Transform>
200  VISKORES_CONT typename StaticTransformType<Transform>::type StaticTransformCont(
201  const Transform& transform)
202  {
203  using FuncIface = typename StaticTransformType<Transform>::type;
204  using PC = detail::ParameterContainer<typename FuncIface::Signature>;
205  return FuncIface{ detail::DoStaticTransformCont<PC>(transform, this->Parameters) };
206  }
207 
208  detail::ParameterContainer<FunctionSignature> Parameters;
209 };
210 
223 template <viskores::IdComponent ParameterIndex, typename FunctionSignature>
224 VISKORES_EXEC_CONT auto ParameterGet(const FunctionInterface<FunctionSignature>& fInterface)
225  -> decltype(detail::ParameterGet(fInterface.Parameters,
226  viskores::internal::IndexTag<ParameterIndex>{}))
227 {
228  return detail::ParameterGet(fInterface.Parameters,
229  viskores::internal::IndexTag<ParameterIndex>{});
230 }
231 
232 
233 //============================================================================
246 
247 template <typename R, typename... Args>
248 FunctionInterface<R(Args...)> make_FunctionInterface(const Args&... args)
249 {
250 // MSVC will issue deprecation warnings if this templated method is instantiated with
251 // a deprecated class here even if the method is called from a section of code where
252 // deprecation warnings are suppressed. This is annoying behavior since this templated
253 // method has no control over what class it is used from. To get around it, we have to
254 // suppress all deprecation warnings here.
255 #ifdef VISKORES_MSVC
257 #endif
258  detail::ParameterContainer<R(Args...)> container = { args... };
259  return FunctionInterface<R(Args...)>{ container };
260 #ifdef VISKORES_MSVC
262 #endif
263 }
264 }
265 } // namespace viskores::internal
266 
268 
269 #endif //viskores_internal_FunctionInterface_h
Types.h
viskores::Transform
auto Transform(const TupleType &&tuple, Function &&f) -> decltype(Apply(tuple, detail::TupleTransformFunctor(), std::forward< Function >(f)))
Construct a new viskores::Tuple by applying a function to each value.
Definition: Tuple.h:221
VISKORES_SUPPRESS_EXEC_WARNINGS
#define VISKORES_SUPPRESS_EXEC_WARNINGS
Definition: ExportMacros.h:61
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
VISKORES_DEPRECATED_SUPPRESS_END
#define VISKORES_DEPRECATED_SUPPRESS_END
Definition: Deprecated.h:132
Deprecated.h
IndexTag.h
FunctionInterfaceDetailPost.h
FunctionInterfaceDetailPre.h
VISKORES_DEPRECATED_SUPPRESS_BEGIN
#define VISKORES_DEPRECATED_SUPPRESS_BEGIN
Definition: Deprecated.h:131