Feellgood
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ExpressionParser Class Reference

#include <expression_parser.h>

Public Member Functions

 ExpressionParser (const ExpressionParser &)=delete
 
ExpressionParseroperator= (const ExpressionParser &)=delete
 
void set_function (const std::string &js_function) const
 
void set_expressions (const std::string &parameters, 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
 

Detailed Description

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).

Member Function Documentation

◆ compute_vector()

Eigen::Vector3d ExpressionParser::compute_vector ( int  argument_count) const
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.

◆ die_if_error()

void ExpressionParser::die_if_error ( duk_int_t  err) const
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.

◆ get_scalar()

double ExpressionParser::get_scalar ( double  arg) const

Compute a scalar from the given scalar argument.

◆ get_vector() [1/2]

Eigen::Vector3d ExpressionParser::get_vector ( const Eigen::Ref< Eigen::Vector3d >  arg) const

Compute a vector from the given vector argument.

◆ get_vector() [2/2]

Eigen::Vector3d ExpressionParser::get_vector ( double  arg) const

Compute a vector from the given scalar argument.

◆ get_vector_component()

double ExpressionParser::get_vector_component ( int  idx) const
private

Get the given component from the array at the top of the stack. Preserve the stack state.

◆ set_expressions()

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".

◆ set_function()

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.

Member Data Documentation

◆ ctx

duk_context* ExpressionParser::ctx
private

Ducktape context holding the internal state of the interpreter.


The documentation for this class was generated from the following files: