OGS 6.2.1-76-gbb689931b
NamedFunctionCaller.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <map>
13 #include <vector>
14 #include "NamedFunction.h"
15 
16 namespace NumLib
17 {
18 class SpecificFunctionCaller;
19 
22 {
23 public:
25  explicit NamedFunctionCaller(
26  std::initializer_list<std::string> unbound_argument_names);
27 
29  void addNamedFunction(NamedFunction&& fct);
30 
32  std::vector<NamedFunction> const& getNamedFunctions() const
33  {
34  return _named_functions;
35  }
36 
42  void plug(std::string const& sink_fct, std::string const& sink_arg,
43  std::string const& source_fct);
44 
48  void applyPlugs();
49 
53  std::string const& function_name);
54 
59  std::string getCallExpression(std::string const& function_name) const;
60 
62  std::size_t getNumberOfUnboundArguments() const;
63 
64 private:
67  double call(std::size_t function_idx,
68  std::vector<double> const& unbound_arguments) const;
69 
72  std::map<std::string, int> _map_name_idx;
73 
75  std::vector<NamedFunction> _named_functions;
76 
81  std::vector<std::vector<int>> _map_sink_source;
82 
85  const int _uninitialized;
86 
87  struct SinkSource
88  {
89  std::string const sink_fct;
90  std::string const sink_arg;
91  std::string const source;
92  };
93 
95  std::vector<SinkSource> _deferred_plugs;
96 
97  friend class SpecificFunctionCaller;
98 };
99 
105 {
106 public:
108  SpecificFunctionCaller(std::size_t const function_idx,
109  NamedFunctionCaller const& caller);
110 
112  double call(std::vector<double> const& unbound_arguments) const;
113 
115  std::size_t getNumberOfUnboundArguments() const;
116 
117 private:
119  std::size_t const _function_idx;
120 
123 };
124 
125 } // namespace NumLib
double call(std::size_t function_idx, std::vector< double > const &unbound_arguments) const
NamedFunctionCaller const & _caller
The named function caller used for the evaluation.
void plug(std::string const &sink_fct, std::string const &sink_arg, std::string const &source_fct)
std::map< std::string, int > _map_name_idx
std::vector< SinkSource > _deferred_plugs
Saves plugs declared by plug().
Builds expression trees of named functions dynamically at runtime.
NamedFunctionCaller(std::initializer_list< std::string > unbound_argument_names)
Constructs an instance whose unbound arguments have the given names.
std::size_t const _function_idx
Index of the referenced function.
void addNamedFunction(NamedFunction &&fct)
Adds the given named function.
std::size_t getNumberOfUnboundArguments() const
Returns the number of unbound arguments.
std::vector< NamedFunction > _named_functions
Contains all named functions.
std::vector< NamedFunction > const & getNamedFunctions() const
Returns all named functions associated with the caller instance.
std::vector< std::vector< int > > _map_sink_source
std::string getCallExpression(std::string const &function_name) const
SpecificFunctionCaller getSpecificFunctionCaller(std::string const &function_name)