PIP 5.5.3
Platform-Independent Primitives
Открытые члены | Полный список членов класса
Класс PIEvaluator

This class provide mathematical evaluations of custom expression. Подробнее...

Открытые члены

 PIEvaluator ()
 Constructs an empty evaluator.
 
void * data ()
 Returns custom data.
 
void setData (void *_data)
 Set custom data to "_data".
 
bool check (const PIString &string)
 Check mathematical expression and parse it to list of instructions.
 
bool isCorrect () const
 Returns true if expression was checked succesfully.
 
int setVariable (const PIString &name, complexd value=complexd(0.))
 Set variable value with name "name" to value "value". Add variable if it doesn`t exists.
 
void setVariable (int index, complexd value=0.)
 Set variable value with index "index" to value "value". Dont add variable if it doesnt exists.
 
complexd evaluate ()
 Evaluate last successfully checked with function check() expression and returns result.
 
void clearCustomVariables ()
 Remove all manually added variables.
 
int variableIndex (const PIString &name) const
 Returns index of variable with name "name".
 
const PIStringListunknownVariables () const
 Returns all unknown variables founded in last expression passed to check() function.
 
const PIStringListusedVariables () const
 Returns all used variables founded in last expression passed to check() function.
 
const PIStringexpression () const
 Returns processed last expression passed to check() function.
 
const PIStringerror () const
 Returns last error description occured in check() function.
 
const complexd & lastResult () const
 Returns last result of evaluate()
 
PIByteArray save () const
 Save to PIByteArray evaluator state (expression, variables, errors, compiled instructions)
 
void load (PIByteArray ba)
 Restore from PIByteArray evaluator state (expression, variables, errors, compiled instructions)
 

Подробное описание

This class provide mathematical evaluations of custom expression.

Synopsis

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().

Using

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.

Functions

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.

Example

eval.check("2*sin(pi/2)");
piCout << eval.expression() << "=" << eval.evaluate().real();
// 2*sin(pi/2) = 2
eval.check("10x");
piCout << eval.error() << eval.unknownVariables();
// Unknown variables: "x" {"x"}
eval.setVariable("x", complexd(1, 2));
eval.check("10x");
piCout << eval.error() << eval.unknownVariables();
// Correct {}
piCout << eval.expression() << "=" << eval.evaluate();
// 10*x = (10; 20)
eval.setVariable("x", complexd(-2, 0));
piCout << eval.expression() << "=" << eval.evaluate();
// 10*x = (-20; 0)
This class provide mathematical evaluations of custom expression.
Definition: pievaluator.h:222
bool check(const PIString &string)
Check mathematical expression and parse it to list of instructions.
Definition: pievaluator.cpp:1206
const PIString & error() const
Returns last error description occured in check() function.
Definition: pievaluator.h:271
int setVariable(const PIString &name, complexd value=complexd(0.))
Set variable value with name "name" to value "value". Add variable if it doesn`t exists.
Definition: pievaluator.cpp:1218
const PIStringList & unknownVariables() const
Returns all unknown variables founded in last expression passed to check() function.
Definition: pievaluator.h:262
const PIString & expression() const
Returns processed last expression passed to check() function.
Definition: pievaluator.h:268
complexd evaluate()
Evaluate last successfully checked with function check() expression and returns result.
Definition: pievaluator.cpp:1233
#define piCout
Макрос для условного (piDebug) вывода в PICout(StdOut)
Definition: picout.h:35