Feellgood
|
#include <expression_parser.h>
Public Member Functions | |
ExpressionParser (const ExpressionParser &)=delete | |
ExpressionParser & | operator= (const ExpressionParser &)=delete |
void | set_function (const std::string &js_function) const |
void | set_expressions (const std::string ¶meters, const std::string &expr_x, const std::string &expr_y, const std::string &expr_z) |
double | get_scalar (double arg) const |
Eigen::Vector3d | get_vector (double arg) const |
Eigen::Vector3d | get_vector (const Eigen::Ref< Eigen::Vector3d > arg) const |
Private Member Functions | |
void | die_if_error (duk_int_t err) const |
double | get_vector_component (int idx) const |
Eigen::Vector3d | compute_vector (int argument_count) const |
Private Attributes | |
duk_context * | ctx |
This class handles a JavaScript function that computes either a scalar or a 3D vector, which depends on either a single parameter t or on (x, y, z).
|
private |
Compute a vector. This must be called after duk_dup(ctx, -1) and one or more calls to duk_push_number(). argument_count
should match the number of arguments pushed.
|
private |
Abort with an suitable error message if err
is an actual error, in which case the top of the stack is assumed to hold the corresponding Error object.
double ExpressionParser::get_scalar | ( | double | arg | ) | const |
Compute a scalar from the given scalar argument.
Eigen::Vector3d ExpressionParser::get_vector | ( | const Eigen::Ref< Eigen::Vector3d > | arg | ) | const |
Compute a vector from the given vector argument.
Eigen::Vector3d ExpressionParser::get_vector | ( | double | arg | ) | const |
Compute a vector from the given scalar argument.
|
private |
Get the given component from the array at the top of the stack. Preserve the stack state.
void ExpressionParser::set_expressions | ( | const std::string & | parameters, |
const std::string & | expr_x, | ||
const std::string & | expr_y, | ||
const std::string & | expr_z | ||
) |
Use the provided expressions for the x, y and z components for subsequent computations of vectors. parameters
should be a comma-separated list of parameter names, typically "t" or "x,y,z".
void ExpressionParser::set_function | ( | const std::string & | js_function | ) | const |
Use the provided JavaScript function expression for subsequent computations. The provided function should take either one or three numeric parameters, and return either a number or an array of three numbers.
|
private |
Ducktape context holding the internal state of the interpreter.