dune-functions  2.8.0
callable.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTIONS_COMMON_CALLABLE_HH
4 #define DUNE_FUNCTIONS_COMMON_CALLABLE_HH
5 
6 #include <memory>
7 #include <functional>
8 
9 #include <dune/common/function.hh>
10 #include <dune/common/shared_ptr.hh>
11 
12 
13 namespace Dune {
14 namespace Functions {
15 
16 
17 
18 
36 template<class F>
38 {
39  using Range = typename F::RangeType;
40  using Domain = typename F::DomainType;
41 
42  public:
43 
51  {
52  f_ = Dune::stackobject_to_shared_ptr(f);
53  }
54 
61  CallableFunctionWrapper(const std::shared_ptr<const F>& f) :
62  f_(f)
63  {}
64 
70  Range operator()(const Domain& x) const
71  {
72  Range y;
73  f_->evaluate(x, y);
74  return y;
75  }
76 
77  private:
78  std::shared_ptr<const F> f_;
79 };
80 
81 
82 
104 template<class F>
106 {
107  return CallableFunctionWrapper<F>(f);
108 }
109 
110 
136 template<class F>
137 CallableFunctionWrapper<F> callable(const std::shared_ptr<F>& fp)
138 {
139  return CallableFunctionWrapper<F>(fp);
140 }
141 
142 
143 
144 } // namespace Functions
145 } // namespace Dune
146 
147 #endif //DUNE_FUNCTIONS_COMMON_CALLABLE_HH
CallableFunctionWrapper< F > callable(const F &f)
Create a callable object from some Dune::VirtualFunction.
Definition: callable.hh:105
Definition: polynomial.hh:10
Wrap a Dune::VirtualFunction into a callable object.
Definition: callable.hh:38
Range operator()(const Domain &x) const
Forward operator() to F::evaluate()
Definition: callable.hh:70
CallableFunctionWrapper(const F &f)
Instanciate from reference to f.
Definition: callable.hh:50
CallableFunctionWrapper(const std::shared_ptr< const F > &f)
Instanciate from std::shared_ptr to f.
Definition: callable.hh:61