Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
PLMD::lepton::ExpressionProgram Class Reference

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 OperationgetOperation (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...
 
ExpressionProgramoperator= (const ExpressionProgram &program)
 
void setOperation (int index, Operation *operation)
 Change an Operation in this program. More...
 

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ExpressionProgram() [1/3]

PLMD::ExpressionProgram::ExpressionProgram ( )

◆ ExpressionProgram() [2/3]

PLMD::ExpressionProgram::ExpressionProgram ( const ExpressionProgram program)

◆ ~ExpressionProgram()

PLMD::ExpressionProgram::~ExpressionProgram ( )

◆ ExpressionProgram() [3/3]

PLMD::ExpressionProgram::ExpressionProgram ( const ParsedExpression expression)
private

Member Function Documentation

◆ buildProgram()

void PLMD::ExpressionProgram::buildProgram ( const ExpressionTreeNode node)
private

◆ evaluate() [1/2]

double PLMD::ExpressionProgram::evaluate ( ) const

Evaluate the expression.

If the expression involves any variables, this method will throw an exception.

◆ evaluate() [2/2]

double PLMD::ExpressionProgram::evaluate ( const std::map< std::string, double > &  variables) const

Evaluate the expression.

Parameters
variablesa 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.

◆ getNumOperations()

int PLMD::ExpressionProgram::getNumOperations ( ) const

Get the number of Operations that make up this program.

◆ getOperation()

const Operation & PLMD::ExpressionProgram::getOperation ( int  index) const

Get an Operation in this program.

◆ getStackSize()

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.

◆ operator=()

ExpressionProgram & PLMD::ExpressionProgram::operator= ( const ExpressionProgram program)

◆ setOperation()

void PLMD::ExpressionProgram::setOperation ( int  index,
Operation operation 
)

Change an Operation in this program.

The Operation must have been allocated on the heap with the "new" operator. The ExpressionProgram assumes ownership of it and will delete it when it is no longer needed.

Friends And Related Function Documentation

◆ ParsedExpression

friend class ParsedExpression
friend

Member Data Documentation

◆ maxArgs

int PLMD::lepton::ExpressionProgram::maxArgs
private

◆ operations

std::vector<Operation*> PLMD::lepton::ExpressionProgram::operations
private

◆ stackSize

int PLMD::lepton::ExpressionProgram::stackSize
private

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