![]() |
PIP 5.6.1
Platform-Independent Primitives
|
Expression evaluator with reusable compiled instructions. More...
#include <pievaluator.h>
Public Member Functions | |
| PIEvaluator () | |
| Constructs an empty evaluator. | |
| ~PIEvaluator () | |
| Destroys the evaluator. | |
| void * | data () |
| Returns custom user data passed to callback functions. | |
| void | setData (void *_data) |
| Sets custom user data for callback functions. | |
| bool | check (const PIString &string) |
| Checks and compiles an expression. | |
| bool | isCorrect () const |
| Returns true if the last check() succeeded. | |
| int | setVariable (const PIString &name, complexd value=complexd(0.)) |
| Sets a named variable and creates it if needed. | |
| void | setVariable (int index, complexd value=0.) |
| Sets a variable by index. | |
| complexd | evaluate () |
| Evaluates the last successfully compiled expression. | |
| void | clearCustomVariables () |
| Removes user-added variables and keeps built-in constants. | |
| int | variableIndex (const PIString &name) const |
| Returns variable index by name, or -1. | |
| const PIStringList & | unknownVariables () const |
| Returns unknown variables found during the last check(). | |
| const PIStringList & | usedVariables () const |
| Returns variables used in the last checked expression. | |
| const PIString & | expression () const |
| Returns the normalized form of the last checked expression. | |
| const PIString & | error () const |
| Returns the last status or error text from check(). | |
| const complexd & | lastResult () const |
| Returns the last evaluation result. | |
| PIByteArray | save () const |
| Serializes evaluator state. | |
| void | load (PIByteArray ba) |
| Restores evaluator state from serialized data. | |
Expression evaluator with reusable compiled instructions.
This class provide mathematical evaluations of custom expression.
The evaluator prepares an expression with check(), keeps the processed form and instruction list, and then reevaluates it after variable updates. Built-in constants include i, pi, and e.
PIEvaluator developed for stream evaluations of once set expression. It`s create internal list of instructions on function check() and executes very fast on function evaluate(). Once given expression can be evaluated any times with different variable values. Evaluator supports many common mathematic functions described below. Also it`s automatic puts unnecessarily signs and bracets. Processed expression can be obtains with function expression(). If there is an error in expression you can get it with function error(). Last evaluated result you can get with function lastResult().
First you should set your variables with function setVariable(). Next give your expression with function check() and check for error with functions isCorrect() and error(). If expression is correct you can get processed expression with function expression() and evaluate it with function evaluate(). You can change variable values without rechecking expression.
PIEvaluator supports arithmetical operations with complex numbers, this is their list in priority order:
In addition there are compare and logical operations:
Compare and logical functions works with real operators part and returns 0 or 1.
Mathematical functions:
There are some built-in constans:
All trigonometric functions takes angle in radians.