An ExpressionProgram is a linear sequence of Operations for evaluating an expression. More...
#include <ExpressionProgram.h>
Public Member Functions | |
ExpressionProgram () | |
ExpressionProgram (const ExpressionProgram &program) | |
~ExpressionProgram () | |
double | evaluate () const |
Evaluate the expression. More... | |
double | evaluate (const std::map< std::string, double > &variables) const |
Evaluate the expression. More... | |
int | getNumOperations () const |
Get the number of Operations that make up this program. More... | |
const Operation & | getOperation (int index) const |
Get an Operation in this program. More... | |
int | getStackSize () const |
Get the size of the stack needed to execute this program. More... | |
ExpressionProgram & | operator= (const ExpressionProgram &program) |
Private Member Functions | |
ExpressionProgram (const ParsedExpression &expression) | |
void | buildProgram (const ExpressionTreeNode &node) |
Private Attributes | |
int | maxArgs |
std::vector< Operation * > | operations |
int | stackSize |
Friends | |
class | ParsedExpression |
An ExpressionProgram is a linear sequence of Operations for evaluating an expression.
The evaluation is done with a stack. The arguments to each Operation are first taken off the stack in order, then it is evaluated and the result is pushed back onto the stack. At the end, the stack contains a single value, which is the value of the expression.
An ExpressionProgram is created by calling createProgram() on a ParsedExpression.
PLMD::ExpressionProgram::ExpressionProgram | ( | ) |
PLMD::ExpressionProgram::ExpressionProgram | ( | const ExpressionProgram & | program | ) |
PLMD::ExpressionProgram::~ExpressionProgram | ( | ) |
|
private |
|
private |
double PLMD::ExpressionProgram::evaluate | ( | ) | const |
Evaluate the expression.
If the expression involves any variables, this method will throw an exception.
double PLMD::ExpressionProgram::evaluate | ( | const std::map< std::string, double > & | variables | ) | const |
Evaluate the expression.
variables | a map specifying the values of all variables that appear in the expression. If any variable appears in the expression but is not included in this map, an exception will be thrown. |
int PLMD::ExpressionProgram::getNumOperations | ( | ) | const |
Get the number of Operations that make up this program.
const Operation & PLMD::ExpressionProgram::getOperation | ( | int | index | ) | const |
Get an Operation in this program.
int PLMD::ExpressionProgram::getStackSize | ( | ) | const |
Get the size of the stack needed to execute this program.
This is the largest number of elements present on the stack at any point during evaluation.
ExpressionProgram & PLMD::ExpressionProgram::operator= | ( | const ExpressionProgram & | program | ) |
|
friend |
|
private |
|
private |
|
private |
Hosted by GitHub | 1.8.17 |