24#ifndef VULPES_UTILS_EXPRESSION_PARSER_HPP_
25#define VULPES_UTILS_EXPRESSION_PARSER_HPP_
27#include <mathpresso/mathpresso.h>
57 template <
typename... Args>
59 init(expression, args...);
70 template <
typename... Args>
72 init(expression.c_str(), args...);
82 return m_expr.evaluate(
const_cast<double*
>(data));
93 template <
typename... Args>
94 void init(
const char* expression, Args&&... args) {
96 sizeof...(Args) == N,
"Incorrect number of variable names provided");
98 std::array<std::string_view, N> variable_names{std::forward<Args>(args)...};
99 for (
size_t i = 0; i < N; ++i) {
100 m_context.addVariable(variable_names[i].data(), i *
sizeof(
double));
103 const auto options = mathpresso::kNoOptions;
105 if (err != mathpresso::kErrorOk) {
106 throw std::runtime_error(
107 "Failed to compile expression: '" + std::string(expression) +
108 "'. Error: " + std::to_string(err));
double evaluate(const double *data) const
Evaluate the compiled expression against a data buffer.
Definition expression_parser.hpp:81
ExpressionParser(const char *expression, Args &&... args)
Compile an expression given as a C string.
Definition expression_parser.hpp:58
mathpresso::Expression m_expr
Definition expression_parser.hpp:113
void init(const char *expression, Args &&... args)
Register variables and compile the expression.
Definition expression_parser.hpp:94
ExpressionParser(const std::string &expression, Args &&... args)
Compile an expression given as a std::string.
Definition expression_parser.hpp:71
mathpresso::Context m_context
Definition expression_parser.hpp:112
Definition cell_manager.hpp:38