14 #define exprtk_disable_string_capabilities // Workaround a bug in Ubuntu precise's GCC+libstdc++ 15 #include <mrpt/otherlibs/exprtk.hpp> 31 const std::map<std::string, double> &variables,
37 exprtk::symbol_table<double> symbol_table;
38 for (
const auto &
v : variables) {
39 double & var =
const_cast<double&
>(
v.second);
40 symbol_table.add_variable(
v.first, var);
42 symbol_table.add_constant(
"M_PI",
M_PI);
43 symbol_table.add_constants();
45 PIMPL_GET_REF(exprtk::expression<double>, m_compiled_formula).register_symbol_table(symbol_table);
47 exprtk::parser<double> parser;
48 if (!parser.compile(expression,
PIMPL_GET_REF(exprtk::expression<double>, m_compiled_formula)))
49 THROW_EXCEPTION_FMT(
"Error compiling expression (name=`%s`): `%s`. Error: `%s`", expr_name_for_error_reporting.c_str(), expression.c_str(), parser.error().c_str());
54 ASSERT_(m_compiled_formula.ptr.get() !=
nullptr);
59 const std::map<std::string, double *> &variables
62 exprtk::symbol_table<double> symbol_table;
63 for (
const auto &
v : variables) {
64 double * var =
const_cast<double*
>(
v.second);
65 symbol_table.add_variable(
v.first, *var);
67 PIMPL_GET_REF(exprtk::expression<double>, m_compiled_formula).register_symbol_table(symbol_table);
71 ASSERT_(m_compiled_formula.ptr.get() !=
nullptr);
72 return PIMPL_GET_REF(exprtk::expression<double>, m_compiled_formula);
75 ASSERT_(m_compiled_formula.ptr.get() !=
nullptr);
81 return m_compiled_formula.ptr.get() !=
nullptr;
CRuntimeCompiledExpression()
Default ctor.
exprtk::expression< double > & get_raw_exprtk_expr()
Access raw exprtk expression object.
PIMPL_IMPLEMENT(exprtk::expression< double >)
#define THROW_EXCEPTION_FMT(_FORMAT_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 base provides a set of functions for maths stuff.
double eval() const
Evaluates the current value of the precompiled formula.
#define PIMPL_GET_CONSTREF(_TYPE, _VAR_NAME)
GLsizei const GLchar ** string
#define PIMPL_GET_REF(_TYPE, _VAR_NAME)
bool is_compiled() const
Returns true if compile() was called and ended without errors.
#define PIMPL_CONSTRUCT(_TYPE, _VAR_NAME)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
const std::string & get_original_expression() const
Returns the original formula passed to compile(), or an empty string if still not compiled...
std::string m_original_expr_str
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...