Version: 9.15.0
QtxEvalExpr Class Reference

String expression evaluator. More...

#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
 

Detailed Description

String expression evaluator.

Member Enumeration Documentation

◆ Error

Parsing error type.

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() [1/2]

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

Constructor.

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() [2/2]

QtxEvalExpr::QtxEvalExpr ( const bool  stdSets,
const QString &  expr = QString() 
)

Constructor.

Parameters
stdSetsif true, the evaluator is initalized by standard operations
exprexpression to be evaluated

References intialize().

◆ ~QtxEvalExpr()

QtxEvalExpr::~QtxEvalExpr ( )

Destructor.

References myParser.

Member Function Documentation

◆ autoDeleteOperationSets()

bool QtxEvalExpr::autoDeleteOperationSets ( ) const

Get the 'auto-delete operations' flag value.

Returns
true if all operations shoud be automatically deleted when the evaluator is destroyed
See also
setAutoDeleteOperationSets()

References QtxEvalParser::autoDeleteOperationSets(), and myParser.

◆ calculate()

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

Evaluate the expression.

Parameters
exprexpression to be evaluated
Returns
result of the evaluation

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

◆ error()

QtxEvalExpr::Error QtxEvalExpr::error ( ) const

Get the code of latest parsing error.

Returns
the code of the last error

References QtxEvalParser::error(), and myParser.

◆ expression()

QString QtxEvalExpr::expression ( ) const

Get the expression.

Returns
expression string

References myExpr.

◆ insertOperationSet()

void QtxEvalExpr::insertOperationSet ( QtxEvalSet set,
const int  idx = -1 
)

Install the operation.

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.

◆ intialize()

void QtxEvalExpr::intialize ( const bool  stdSets,
const QString &  expr 
)
private

Initialize the evaluator.

Parameters
stdSetsif true, the evaluator is initalized by standard operations
exprexpression to be evaluated

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

◆ operationSet()

QtxEvalSet * QtxEvalExpr::operationSet ( const QString &  name) const

Get the operation by name.

Parameters
nameoperation name
Returns
operation of 0 if not found
See also
operationSets(), insertOperationSet(), removeOperationSet()

References myParser, and QtxEvalParser::operationSet().

◆ operationSets()

QList< QtxEvalSet * > QtxEvalExpr::operationSets ( ) const

Get current set of operations.

Returns
operations set
See also
insertOperationSet(), removeOperationSet(), operationSet()

References myParser, and QtxEvalParser::operationSets().

◆ parser()

QtxEvalParser * QtxEvalExpr::parser ( ) const

Get the expression parser.

Returns
expression parser

References myParser.

◆ removeOperationSet()

void QtxEvalExpr::removeOperationSet ( QtxEvalSet set)

Remove the operation.

Parameters
operationto be removed
See also
operationSets(), insertOperationSet(), operationSet()

References myParser, and QtxEvalParser::removeOperationSet().

◆ setAutoDeleteOperationSets()

void QtxEvalExpr::setAutoDeleteOperationSets ( const bool  on)

Set the 'auto-delete operations' flag value.

Parameters
onif true, all operations shoud be automatically deleted when the evaluator is destroyed
See also
autoDeleteOperationSets()

References myParser, and QtxEvalParser::setAutoDeleteOperationSets().

◆ setExpression()

void QtxEvalExpr::setExpression ( const QString &  expr)

Set the expression.

Parameters
exprexpression string

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

Member Data Documentation

◆ myExpr

QString QtxEvalExpr::myExpr
private

◆ myParser

QtxEvalParser* QtxEvalExpr::myParser
private

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