#include <Formula.h>
Public Types | |
| typedef std::stack< double > | ResultStack |
| Result stack. | |
| typedef double(* | UnaryFunctionPtr )(double) |
| pointer to a unary function | |
| typedef std::vector< BytecodeToken * > | Bytecode |
| The Bytecode is a vector of tokens. | |
|
typedef std::map< std::string, const double * > | VariableMap |
| The VariableMap is a map of string to pointers to double. | |
|
typedef std::map< std::string, UnaryFunctionPtr > | FunctionMap |
| The FunctionMap is a map of string to pointers to function. | |
Public Member Functions | |
| Formula (const std::string &formula, bool useStandardFunctions=true) | |
| Constructor, take a text in input. | |
| virtual | ~Formula () |
| Destructor, free tokens. | |
| void | setVariable (const std::string &name, const double &value) |
| Set a variable from the formula to an external value. | |
| void | addUnaryFunction (const std::string &name, UnaryFunctionPtr funcPtr) |
| Add an unary function. | |
| ParseResult | parse (void) |
| Parse, return a ParseResult struct indicating if the parsing was successfull, and if not, the error. All formula variables must be bound to C++ ones by calls to setVariable before this calling this method. | |
| double | eval (void) |
| Evaluate the formula. | |
Static Protected Member Functions | |
| static double | sqr (double v) |
| f(x) = x*x | |
| static double | sgn (double v) |
| f(x) = 1 if x > 0; -1 if x < 0; 0 otherwise | |
Protected Attributes | |
| std::string | formulaText |
| text of formula | |
| VariableMap | variableMap |
| map of variable name to variable values | |
| FunctionMap | functionMap |
| map of function name to functions | |
| Bytecode | bytecode |
| bytecode of the formula | |
| bool | parsed |
| has the formula been parsed? | |
Classes | |
| struct | BytecodeToken |
| An token from the bytecode, can be a variable or an operation. More... | |
| struct | ParseResult |
| Result returned by Formula::parse, including error description. More... | |
1.4.2