Base Framework
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
ExpressionEvaluator Class Reference

Expression evaluator. More...

#include <base/math/ExpressionParser.h>

Inherits Object.

Classes

class  BinaryOperator
 
class  Function
 
struct  Node
 
class  Operation
 
class  UnaryOperator
 

Public Types

enum  NodeType {
  VALUE, VARIABLE, CONSTANT, BUILTIN,
  FUNCTION, UNKNOWN
}
 
enum  Glue { LEFT, RIGHT }
 
enum  Builtin {
  PLUS = 0, MINUS = 1, ADD = 2, SUBTRACT = 3,
  MULTIPLY = 4, DIVIDE = 5, POWER = 6, PARENTHESIS = 7
}
 

Public Member Functions

virtual double onConstant (unsigned int constant) const
 
virtual double onFunction (unsigned int function, const double *value) const
 
 ExpressionEvaluator () noexcept
 
const List< Node > & getExpression () const noexcept
 
void setExpression (const List< Node > &nodes) noexcept
 
const List< String > & getVariables () const noexcept
 
void setVariables (const List< String > &variables) noexcept
 
double evaluate () const
 
double evaluate (const double *variables) const
 
void evaluate (const double *variables, double *results, unsigned int count) const
 

Static Public Member Functions

static Node makeValueNode (double value) noexcept
 
static Node makeConstantNode (unsigned int id) noexcept
 
static Node makeVariableNode (unsigned int id) noexcept
 
static Node makeFunctionNode (unsigned int id, unsigned int arguments) noexcept
 
static Node makeUnknownNode (unsigned int id) noexcept
 
static Node makeNodeFromOperation (Operation operation) noexcept
 

Detailed Description

Expression evaluator.

Arithmetic expression evaluator.

See also
ExpressionParser
Version
1.0
Examples
testsuite/eval.cpp.

Member Enumeration Documentation

◆ Builtin

Built-in operators.

Enumerator
PLUS 

Plus.

MINUS 

Minus.

ADD 

Add.

SUBTRACT 

Subtract.

MULTIPLY 

Multiply.

DIVIDE 

Divide.

POWER 

Power.

PARENTHESIS 

Parenthesis.

◆ Glue

Enumerator
LEFT 

Bind to the left.

RIGHT 

Bind to the right.

◆ NodeType

The valid types of a node in an expression.

Enumerator
VALUE 

A value.

VARIABLE 

A variable.

CONSTANT 

A constant.

BUILTIN 

Built-in.

FUNCTION 

A function.

UNKNOWN 

Unknown.

Constructor & Destructor Documentation

◆ ExpressionEvaluator()

ExpressionEvaluator::ExpressionEvaluator ( )
noexcept

Initializes expression evaluator.

Member Function Documentation

◆ evaluate() [1/3]

double ExpressionEvaluator::evaluate ( ) const

Evaluates the constant expression once.

Returns
The result of the evaluation.

◆ evaluate() [2/3]

double ExpressionEvaluator::evaluate ( const double *  variables) const

Evaluates the formula once.

Parameters
variablesThe array containing the values of the variables (e.g. x0, y0, z0).
Returns
The result of the evaluation.

◆ evaluate() [3/3]

void ExpressionEvaluator::evaluate ( const double *  variables,
double *  results,
unsigned int  count 
) const

Evaluates the formula several times.

Parameters
variableThe values of the variables (e.g. x0, y0, z0, x1, y1, z1, x2, ...).
resultsThe array to store the results in. (e.g. res0, res1, res3, ...).
countThe desired number of evaluations.

◆ getExpression()

const List<Node>& ExpressionEvaluator::getExpression ( ) const
inlinenoexcept

Returns the expression.

◆ getVariables()

const List<String>& ExpressionEvaluator::getVariables ( ) const
inlinenoexcept

Returns the names of variables of the formula in the order expected by the evaluate methods.

◆ setExpression()

void ExpressionEvaluator::setExpression ( const List< Node > &  nodes)
inlinenoexcept

Sets the expression.

◆ setVariables()

void ExpressionEvaluator::setVariables ( const List< String > &  variables)
inlinenoexcept

Sets the variables.