16 #define exprtk_disable_string_capabilities // Workaround a bug in Ubuntu 20 #define exprtk_disable_enhanced_features 21 #define exprtk_disable_superscalar_unroll 22 #define exprtk_disable_rtl_vecops 23 #define exprtk_disable_rtl_io_file 24 #include <mrpt/otherlibs/exprtk.hpp> 53 const std::map<std::string, double>& variables,
58 m_impl->m_original_expr_str = expression;
60 exprtk::symbol_table<double> symbol_table;
61 for (
const auto&
v : variables)
63 double& var =
const_cast<double&
>(
v.second);
64 symbol_table.add_variable(
v.first, var);
66 symbol_table.add_constant(
"M_PI",
M_PI);
67 symbol_table.add_constants();
69 m_impl->m_compiled_formula.register_symbol_table(symbol_table);
72 exprtk::parser<double> parser;
75 m_impl->m_compiled_formula))
77 "Error compiling expression (name=`%s`): `%s`. Error: `%s`",
78 expr_name_for_error_reporting.c_str(), expression.c_str(),
79 parser.error().c_str());
85 return m_impl->m_compiled_formula.value();
92 const std::map<std::string, double*>& variables)
94 exprtk::symbol_table<double> symbol_table;
95 for (
const auto&
v : variables)
97 double* var =
const_cast<double*
>(
v.second);
98 symbol_table.add_variable(
v.first, *var);
100 m_impl->m_compiled_formula.register_symbol_table(symbol_table);
106 return m_impl->m_compiled_formula;
112 return m_impl->m_compiled_formula;
118 return m_impl->m_compiled_formula;
122 return m_impl->m_original_expr_str;
const std::string & get_original_expression() const
Returns the original formula passed to compile(), or an empty string if still not compiled...
exprtk::expression< double > & get_raw_exprtk_expr()
Access raw exprtk expression object.
exprtk::expression< double > m_compiled_formula
std::string m_original_expr_str
A wrapper of exprtk runtime expression compiler: it takes a string representing an expression (from a...
#define ASSERT_(f)
Defines an assertion mechanism.
bool is_compiled() const
Returns true if compile() was called and ended without errors.
CRuntimeCompiledExpression()
Default ctor.
void register_symbol_table(const std::map< std::string, double *> &variables)
Can be used before calling compile() to register additional variables by means of pointers instead of...
GLsizei const GLchar ** string
void compile(const std::string &expression, const std::map< std::string, double > &variables=std::map< std::string, double >(), const std::string &expr_name_for_error_reporting=std::string())
Initializes the object by compiling an expression.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double eval() const
Evaluates the current value of the precompiled formula.
pimpl< T > make_impl(Args &&... args)
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
~CRuntimeCompiledExpression()
mrpt::pimpl< Impl > m_impl