faunus
functionparser.h
1 #pragma once
2 
3 #include <string>
4 #include <nlohmann/json.hpp>
5 
6 namespace exprtk { // exprtk.hpp
7 template <typename T> class parser;
8 template <typename T> class expression;
9 template <typename T> class symbol_table;
10 } // namespace exprtk
11 
17 template <std::floating_point T = double> class ExprFunction
18 {
19  std::shared_ptr<exprtk::parser<T>> parser;
20  std::shared_ptr<exprtk::expression<T>> expression;
21  std::shared_ptr<exprtk::symbol_table<T>> symbols;
22  typedef std::vector<std::pair<std::string, T*>> Tvarvec;
23  typedef std::vector<std::pair<std::string, T>> Tconstvec;
24 
25  public:
26  void set(const std::string& exprstr, const Tvarvec& vars = {}, const Tconstvec& consts = {});
27  void set(const nlohmann::json&, const Tvarvec& vars = {});
28  T operator()() const;
29  T derivative(T& variable) const;
30 };
31 
32 extern template class ExprFunction<double>;
Definition: functionparser.h:9
Definition: functionparser.h:7
Since parser<T> is non-copyable we instantiate it with a shared pointer, allowing ExprFunction to be ...
Definition: externalpotential.h:9
Definition: functionparser.h:6
Definition: functionparser.h:8