Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QtxEvalExpr Class Reference

String expression evaluator.

#include <QtxEvalExpr.h>

Public Types

enum  Error {
  OK, OperandsNotMatch, InvalidResult, InvalidOperation,
  OperationsNull, InvalidToken, CloseExpected, ExcessClose,
  BracketsNotMatch, StackUnderflow, ExcessData
}
 Parsing error type. More...
 

Public Member Functions

 QtxEvalExpr (const QString &=QString())
 Constructor. More...
 
 QtxEvalExpr (const bool, const QString &=QString())
 Constructor. More...
 
 ~QtxEvalExpr ()
 Destructor. More...
 
QVariant calculate (const QString &=QString())
 Evaluate the expression. More...
 
QString expression () const
 Get the expression. More...
 
void setExpression (const QString &)
 Set the expression. More...
 
Error error () const
 Get the code of latest parsing error. More...
 
QtxEvalParserparser () const
 Get the expression parser. More...
 
bool autoDeleteOperationSets () const
 Get the 'auto-delete operations' flag value. More...
 
void setAutoDeleteOperationSets (const bool)
 Set the 'auto-delete operations' flag value. More...
 
QList< QtxEvalSet * > operationSets () const
 Get current set of operations. More...
 
QtxEvalSetoperationSet (const QString &) const
 Get the operation by name. More...
 
void removeOperationSet (QtxEvalSet *)
 Remove the operation. More...
 
void insertOperationSet (QtxEvalSet *, const int=-1)
 Install the operation. More...
 

Private Member Functions

void intialize (const bool, const QString &)
 Initialize the evaluator. More...
 

Private Attributes

QString myExpr
 
QtxEvalParsermyParser
 

Member Enumeration Documentation

Enumerator
OK 

No errors found.

OperandsNotMatch 

Types of arguments are invalid for this operation.

InvalidResult 

Operation cannot find result (for example, division by zero)

InvalidOperation 

Unknown operation.

OperationsNull 

Internal operations pointer of parser is null.

InvalidToken 

Invalid token (neither operation, nor parameter of value)

CloseExpected 

Closing bracket is expected.

ExcessClose 

Extra closing bracket is found.

BracketsNotMatch 

Opening and closing brackets are of different type, e.g. [)

StackUnderflow 

There are no arguments in the stack for the operation.

ExcessData 

The parsing is finished, but there are more then one value in the stack.

Constructor & Destructor Documentation

QtxEvalExpr::QtxEvalExpr ( const QString &  expr = QString())

The evaluator is initalized by standard operations. Use another constructor with parameter stdSets = false to avoid initialization of evaluator with standard operations.

Parameters
exprexpression to be evaluated

References intialize().

QtxEvalExpr::QtxEvalExpr ( const bool  stdSets,
const QString &  expr = QString() 
)
Parameters
stdSetsif true, the evaluator is initalized by standard operations
exprexpression to be evaluated

References intialize().

QtxEvalExpr::~QtxEvalExpr ( )

References myParser.

Member Function Documentation

bool QtxEvalExpr::autoDeleteOperationSets ( ) const
Returns
true if all operations shoud be automatically deleted when the evaluator is destroyed
See Also
setAutoDeleteOperationSets()

References QtxEvalParser::autoDeleteOperationSets(), and myParser.

QVariant QtxEvalExpr::calculate ( const QString &  expr = QString())
Parameters
exprexpression to be evaluated
Returns
result of the evaluation

References QtxEvalParser::calculate(), myParser, and setExpression().

QtxEvalExpr::Error QtxEvalExpr::error ( ) const
Returns
the code of the last error

References QtxEvalParser::error(), and myParser.

QString QtxEvalExpr::expression ( ) const
Returns
expression string

References myExpr.

void QtxEvalExpr::insertOperationSet ( QtxEvalSet set,
const int  idx = -1 
)
Parameters
operationto be added
idxindex in the list at which the operation shoud be inserted
See Also
operationSets(), removeOperationSet(), operationSet()

References QtxEvalParser::insertOperationSet(), and myParser.

void QtxEvalExpr::intialize ( const bool  stdSets,
const QString &  expr 
)
private
Parameters
stdSetsif true, the evaluator is initalized by standard operations
exprexpression to be evaluated

References QtxEvalParser::insertOperationSet(), myParser, QtxEvalParser::setAutoDeleteOperationSets(), and setExpression().

QtxEvalSet * QtxEvalExpr::operationSet ( const QString &  name) const
Parameters
nameoperation name
Returns
operation of 0 if not found
See Also
operationSets(), insertOperationSet(), removeOperationSet()

References myParser, and QtxEvalParser::operationSet().

QList< QtxEvalSet * > QtxEvalExpr::operationSets ( ) const
QtxEvalParser * QtxEvalExpr::parser ( ) const
Returns
expression parser

References myParser.

void QtxEvalExpr::removeOperationSet ( QtxEvalSet set)
Parameters
operationto be removed
See Also
operationSets(), insertOperationSet(), operationSet()

References myParser, and QtxEvalParser::removeOperationSet().

void QtxEvalExpr::setAutoDeleteOperationSets ( const bool  on)
Parameters
onif true, all operations shoud be automatically deleted when the evaluator is destroyed
See Also
autoDeleteOperationSets()

References myParser, and QtxEvalParser::setAutoDeleteOperationSets().

void QtxEvalExpr::setExpression ( const QString &  expr)
Parameters
exprexpression string

References expression(), myExpr, myParser, and QtxEvalParser::setExpression().

Member Data Documentation

QString QtxEvalExpr::myExpr
private
QtxEvalParser* QtxEvalExpr::myParser
private

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