#include <Expr.h>
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... |
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; }
gridripper::math::expr::Expr::Expr | ( | const string & | s | ) | throw (Error&) |
Construct a mathematical expression containing numbers only.
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.
s | the expression | |
funcs | extra functions and variables | |
funcRep | function repository |
const string& gridripper::math::expr::Expr::getString | ( | ) | const [inline] |
Gets the expression as a string.
string gridripper::math::expr::Expr::getProgramListString | ( | ) | const |
Gets the "program" as a printable string.
Useful for debugging.
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.
name | the variable name | |
var | the new variable |
void gridripper::math::expr::Expr::evalStack | ( | GReal_t *& | stack | ) | const [virtual] |
Evaluates the stack.
stack | the stack pointer |
Implements gridripper::math::expr::StkFunc.
StkOp** gridripper::math::expr::Expr::getInternalProgram | ( | ) | const [inline] |
Gets the "program".
virtual string gridripper::math::expr::Expr::getClassName | ( | ) | const [inline, virtual] |