gridripper::math::expr::Expr Class Reference

Evaluates mathematical expressions or functions. More...

#include <Expr.h>

Inheritance diagram for gridripper::math::expr::Expr:

gridripper::math::expr::StkFunc gridripper::math::expr::StkOp

List of all members.

Public Member Functions

 Expr (const string &s) throw (Error&)
 Construct a mathematical expression containing numbers only.
 Expr (const string &s, const tvector< StkOp * > &funcs, StkOpRepository *funcRep=NULL) throw (Error&)
 Construct a function from the specified string and variables.
const string & getString () const
 Gets the expression as a string.
string getProgramListString () const
 Gets the "program" as a printable string.
GReal_t eval ()
 Evaluate the expression.
bool isConstant () const
 Returns true if the expression is determined to be a constant.
bool dependsOn (const StkOp &f) const
 Returns true if the expression contains the specified function.
bool dependsOnVariables () const
 Returns true if the expression uses external variables.
void replaceVar (const string &name, StkVar &var)
 Replaces all occurances of a variable with another one in the program.
void evalStack (GReal_t *&stack) const
 Evaluates the stack.
StkOp ** getInternalProgram () const
 Gets the "program".
virtual string getClassName () const
 Gets the class name.

Static Public Member Functions

static string::size_type findExprEnd (const string &str, string::size_type i)
 Finds end of "x?y:z" after the colon.

Classes

class  Error
 Exception thrown by the Expr constructor in case of syntax error. More...


Detailed Description

Evaluates mathematical expressions or functions.

Example:

f(x) = x^0.5*atan(1)/sqrt(pi)

    StkVar vX("x");           // define variable
    StkConst xPi("pi", M_PI); // define a constant
    tvector<StkOp*> funcs;
    funcs.push_back(&vX);
    funcs.push_back(&xPi);
    try {
        Expr expr("x^0.5*atan(1)/sqrt(pi)", funcs); // create Expr
        vX.value = 5; // set value of variable
        cout << "f(5) = " << expr.eval() << endl;  // calculate f(5)
    } catch(Expr::Error& ex) {
        cerr << ex.what() << endl;
    }
 

Version:
GridRipper 0.5, 11/16/2008
Since:
GROMIT 0.2 (2001)
Author:
Peter Csizmadia

Constructor & Destructor Documentation

gridripper::math::expr::Expr::Expr ( const string &  s  )  throw (Error&)

Construct a mathematical expression containing numbers only.

Parameters:
s the expression

gridripper::math::expr::Expr::Expr ( const string &  s,
const tvector< StkOp * > &  funcs,
StkOpRepository funcRep = NULL 
) throw (Error&)

Construct a function from the specified string and variables.

Parameters:
s the expression
funcs extra functions and variables
funcRep function repository


Member Function Documentation

const string& gridripper::math::expr::Expr::getString (  )  const [inline]

Gets the expression as a string.

Returns:
the expression

string gridripper::math::expr::Expr::getProgramListString (  )  const

Gets the "program" as a printable string.

Useful for debugging.

Returns:
the program list

GReal_t gridripper::math::expr::Expr::eval (  ) 

Evaluate the expression.

bool gridripper::math::expr::Expr::dependsOn ( const StkOp f  )  const [virtual]

Returns true if the expression contains the specified function.

Subexpressions are also checked, recursively.

Reimplemented from gridripper::math::expr::StkFunc.

bool gridripper::math::expr::Expr::dependsOnVariables (  )  const

Returns true if the expression uses external variables.

void gridripper::math::expr::Expr::replaceVar ( const string &  name,
StkVar var 
)

Replaces all occurances of a variable with another one in the program.

Parameters:
name the variable name
var the new variable

void gridripper::math::expr::Expr::evalStack ( GReal_t *&  stack  )  const [virtual]

Evaluates the stack.

Parameters:
stack the stack pointer

Implements gridripper::math::expr::StkFunc.

StkOp** gridripper::math::expr::Expr::getInternalProgram (  )  const [inline]

Gets the "program".

Returns:
the array of stack operations

virtual string gridripper::math::expr::Expr::getClassName (  )  const [inline, virtual]

Gets the class name.

Returns:
the class name

Reimplemented from gridripper::math::expr::StkFunc.


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

Generated on Wed Jun 17 18:46:55 2009 for GridRipper by  doxygen 1.5.6