Dune Core Modules (2.9.0)

callable.hh
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 
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  {
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
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)
Instantiate from reference to f.
Definition: callable.hh:50
CallableFunctionWrapper(const std::shared_ptr< const F > &f)
Instantiate from std::shared_ptr to f.
Definition: callable.hh:61
Simple base class templates for functions.
CallableFunctionWrapper< F > callable(const std::shared_ptr< F > &fp)
Create a callable object from std::shared_ptr<F>
Definition: callable.hh:137
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
This file implements several utilities related to std::shared_ptr.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 8, 22:30, 2024)