Dune::Copasi
Loading...
Searching...
No Matches
context.hh
Go to the documentation of this file.
1#ifndef DUNE_COPASI_PARSER_CONTEXT_HH
2#define DUNE_COPASI_PARSER_CONTEXT_HH
3
5
6#include <dune/common/fvector.hh>
7#include <dune/common/parametertree.hh>
8
9#include <unordered_map>
10#include <vector>
11
12namespace Dune::Copasi {
13
15{
16
17public:
18 explicit ParserContext(const ParameterTree& config = {});
19
21
22 typename Parser::Function0D make_function(ParserType, const std::array<std::string,0>&, std::string_view) const;
23 typename Parser::Function1D make_function(ParserType, const std::array<std::string,1>&, std::string_view) const;
24 typename Parser::Function2D make_function(ParserType, const std::array<std::string,2>&, std::string_view) const;
25 typename Parser::Function3D make_function(ParserType, const std::array<std::string,3>&, std::string_view) const;
26 typename Parser::Function4D make_function(ParserType, const std::array<std::string,4>&, std::string_view) const;
27
28 // parse functions of the form `arg0, arg1, ...: expr`. Returns a vector of arguments and a string
29 // containing the expression
30 static std::tuple<std::vector<std::string_view>, std::string_view>
32
33private:
34
35 void add_independent_context(Parser& parser) const;
36
37 ParserType _default_context_parser;
38 std::unordered_map<std::string, double> _constants;
39 std::unordered_map<std::string, std::function<typename Parser::Function1D()>> _func_maker_1;
40 std::unordered_map<std::string, std::function<typename Parser::Function2D()>> _func_maker_2;
41 std::unordered_map<std::string, std::function<typename Parser::Function3D()>> _func_maker_3;
42 std::unordered_map<std::string, std::function<typename Parser::Function4D()>> _func_maker_4;
43 std::unordered_map<std::string, ParameterTree> _functions_expr;
44 std::unordered_map<std::string, std::function<double(std::size_t)>> _cell_data;
45};
46
47} // namespace Dune::Copasi
48
49#endif // DUNE_COPASI_PARSER_CONTEXT_HH
Definition context.hh:15
static std::tuple< std::vector< std::string_view >, std::string_view > parse_function_expression(std::string_view fnc_expr)
ParserContext(const ParameterTree &config={})
Parser::Function0D make_function(ParserType, const std::array< std::string, 0 > &, std::string_view) const
Parser::Function4D make_function(ParserType, const std::array< std::string, 4 > &, std::string_view) const
Parser::Function2D make_function(ParserType, const std::array< std::string, 2 > &, std::string_view) const
Parser::Function1D make_function(ParserType, const std::array< std::string, 1 > &, std::string_view) const
Parser::Function3D make_function(ParserType, const std::array< std::string, 3 > &, std::string_view) const
void add_context(Parser &parser) const
Definition parser.hh:16
fu2::unique_function< RangeField(RangeField, RangeField, RangeField) const > Function3D
Definition parser.hh:34
fu2::unique_function< RangeField() const > Function0D
Definition parser.hh:31
fu2::unique_function< RangeField(RangeField, RangeField, RangeField, RangeField) const > Function4D
Definition parser.hh:35
fu2::unique_function< RangeField(RangeField, RangeField) const > Function2D
Definition parser.hh:33
fu2::unique_function< RangeField(RangeField) const > Function1D
Definition parser.hh:32
Definition axis_names.hh:7
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24
ParserType
Definition factory.hh:12