The calculation engine of . More...
#include <elamengine.h>
Public Types | |
enum | PriorityMatch { IgnoreMismatch =0, OverridePrio =1, FailIfMismatch =2 } |
Matching mode for priority when overwriting an operator, see binaryOperator. More... | |
Public Slots | |
virtual QVariant | getValue (QString) const |
returns the value of the named variable or constant (default uses getVariable/getConstant) More... | |
virtual QVariant | getVariable (QString) const |
returns the value of the named variable (does not return constants) More... | |
virtual QVariant | getConstant (QString) const |
returns the value of the named constant (does not return variables) More... | |
virtual bool | setVariable (QString, QVariant) |
sets a variable More... | |
virtual bool | setConstant (QString, QVariant) |
sets a constant More... | |
virtual void | removeVariable (QString) |
deletes a variable (does not affect constants, does nothing if the variable does not exist) More... | |
virtual void | removeConstant (QString) |
deletes a constant (does not affect variables, does nothing if the constant does not exist) More... | |
virtual void | removeValue (QString) |
deletes a variable or constant (default uses removeVariable and removeConstant) More... | |
bool | setFunction (QString, Function) |
Sets a new function for a specific function name. More... | |
void | removeFunction (QString) |
removes a function More... | |
int | setLiteralParser (LiteralParser parser, QString startchars, int prio=50) |
sets the parser routine for a literal value More... | |
void | removeLiteralParser (int parserid) |
removes a parser function More... | |
void | setBinaryOperatorPrio (QString name, int prio) |
sets/overrides the priority of an operator, creating the operator if it does not exist yet More... | |
void | registerType (int typeId) |
registers a type as primary, this means it is not cast into another type when encountered More... | |
void | setAutoCast (int target, QList< int >origin, TypeCast castfunc, int prio=50) |
Registers an automatic cast function. More... | |
void | setPipeOperator (QString pipe) |
sets the pipe operator More... | |
void | setPipePrio (int) |
sets the prio of the pipe operator More... | |
void | setNamedOperatorsAllowed (bool) |
sets whether named operators are allowed (default is false) More... | |
Expression | expression (QString) |
simply parses an expression string into an object More... | |
Expression | expression (QList< Token >) |
simply parses an expression string into an object More... | |
QList< Token > | tokenize (QString) |
simply parses an expression string into a list of tokens More... | |
QVariant | evaluate (QString) |
parses and evaluates an expression string into a final value More... | |
QVariant | evaluate (Expression) |
evaluates a parsed expression into a final value More... | |
CharacterClassSettings | characterClasses () |
gives access to the character classes settings More... | |
Public Member Functions | |
Engine (QObject *parent=0) | |
instantiates an engine object More... | |
virtual Q_INVOKABLE bool | hasVariable (QString) const |
true if the named variable exists in this engine More... | |
virtual Q_INVOKABLE bool | hasConstant (QString) const |
true if the named constant exists in this engine More... | |
virtual Q_INVOKABLE bool | hasValue (QString) const |
true if a variable or constant of that name exists in this engine (default calls hasVariable() || hasConstant() ) More... | |
Q_INVOKABLE bool | hasFunction (QString) const |
returns true if the named function exists More... | |
Q_INVOKABLE Function | getFunction (QString) const |
returns the pointer to the function More... | |
Q_INVOKABLE bool | hasUnaryOperator (QString name) const |
returns true if there is an unaryOperator with this name More... | |
Q_INVOKABLE bool | hasBinaryOperator (QString name) const |
returns true if there is an binaryOperator with this name More... | |
Q_INVOKABLE UnaryOperator | unaryOperator (QString name) |
returns an existing or new unary operator object More... | |
Q_INVOKABLE BinaryOperator | binaryOperator (QString name, int prio=1, PriorityMatch match=IgnoreMismatch) |
returns an existing or new binary operator object More... | |
Q_INVOKABLE int | binaryOperatorPrio (QString name) |
returns the priority of the operator, or -1 if the operator does not exist More... | |
Q_INVOKABLE bool | isAssignment (QString name) const |
returns true if the name represents an assignment operator More... | |
Q_INVOKABLE bool | isPipe (QString name) const |
returns true if the name represents a pipe More... | |
Q_INVOKABLE QVariant | autoCast (const QVariant &) const |
performs automatic casting More... | |
virtual Q_INVOKABLE QStringList | variableNames () const |
returns the names of all currently existing variables More... | |
virtual Q_INVOKABLE QStringList | constantNames () const |
returns the names of all currently existing constants More... | |
Q_INVOKABLE QStringList | functionNames () const |
returns the names of all currently existing functions More... | |
Q_INVOKABLE QStringList | binaryOperatorNames () const |
returns the names of all currently existing binary operators More... | |
Q_INVOKABLE QStringList | unaryOperatorNames () const |
returns the names of all currently existing unary operators More... | |
Q_INVOKABLE QString | pipeOperator () const |
returns the name of the pipe operator or empty string if it does not exist More... | |
Q_INVOKABLE int | pipePrio () const |
returns the priority of the pipe operator - per default 0 (lowest binding) More... | |
Q_INVOKABLE bool | namedOperatorsAllowed () const |
returns whether named operators are allowed More... | |
Static Public Member Functions | |
static void | configureReflection (Engine &) |
register reflection functions More... | |
The calculation engine of .
Instances of this class can be configured to represent a specific system of functions and operators.
Methods of this class are used to evaluate expressions into final values.
Matching mode for priority when overwriting an operator, see binaryOperator.
The matching mode has no effect if the operator is new or the priorities match. In those cases binaryOperator always returns the operator object corresponding to the given name for this engine.
The matching mode changes behavior if the operator exists and its priority is different from the one given in the call.
|
explicit |
instantiates an engine object
Q_INVOKABLE QVariant ELAM::Engine::autoCast | ( | const QVariant & | ) | const |
performs automatic casting
Q_INVOKABLE BinaryOperator ELAM::Engine::binaryOperator | ( | QString | name, |
int | prio = 1 , |
||
PriorityMatch | match = IgnoreMismatch |
||
) |
returns an existing or new binary operator object
name | the name token of the operator, if the name is not a valid operator it cannot be called from this engine until character classes change |
prio | the priority that should be set for the operator; higher value means stronger binding |
match | how to behave if the operator already exists and priorities do not match, see PriorityMatch |
Q_INVOKABLE QStringList ELAM::Engine::binaryOperatorNames | ( | ) | const |
returns the names of all currently existing binary operators
Q_INVOKABLE int ELAM::Engine::binaryOperatorPrio | ( | QString | name | ) |
returns the priority of the operator, or -1 if the operator does not exist
|
slot |
gives access to the character classes settings
|
static |
register reflection functions
|
virtual |
returns the names of all currently existing constants
|
slot |
parses and evaluates an expression string into a final value
|
slot |
evaluates a parsed expression into a final value
|
slot |
simply parses an expression string into an object
|
slot |
simply parses an expression string into an object
Q_INVOKABLE QStringList ELAM::Engine::functionNames | ( | ) | const |
returns the names of all currently existing functions
|
virtualslot |
returns the value of the named constant (does not return variables)
Q_INVOKABLE Function ELAM::Engine::getFunction | ( | QString | ) | const |
returns the pointer to the function
|
virtualslot |
returns the value of the named variable or constant (default uses getVariable/getConstant)
|
virtualslot |
returns the value of the named variable (does not return constants)
Q_INVOKABLE bool ELAM::Engine::hasBinaryOperator | ( | QString | name | ) | const |
returns true if there is an binaryOperator with this name
|
virtual |
true if the named constant exists in this engine
Q_INVOKABLE bool ELAM::Engine::hasFunction | ( | QString | ) | const |
returns true if the named function exists
Q_INVOKABLE bool ELAM::Engine::hasUnaryOperator | ( | QString | name | ) | const |
returns true if there is an unaryOperator with this name
|
virtual |
true if a variable or constant of that name exists in this engine (default calls hasVariable() || hasConstant() )
|
virtual |
true if the named variable exists in this engine
Q_INVOKABLE bool ELAM::Engine::isAssignment | ( | QString | name | ) | const |
returns true if the name represents an assignment operator
Q_INVOKABLE bool ELAM::Engine::isPipe | ( | QString | name | ) | const |
returns true if the name represents a pipe
Q_INVOKABLE bool ELAM::Engine::namedOperatorsAllowed | ( | ) | const |
returns whether named operators are allowed
Q_INVOKABLE QString ELAM::Engine::pipeOperator | ( | ) | const |
returns the name of the pipe operator or empty string if it does not exist
Q_INVOKABLE int ELAM::Engine::pipePrio | ( | ) | const |
returns the priority of the pipe operator - per default 0 (lowest binding)
|
slot |
registers a type as primary, this means it is not cast into another type when encountered
typeId | the QVariant ID of the type to register |
|
virtualslot |
deletes a constant (does not affect variables, does nothing if the constant does not exist)
|
slot |
removes a function
|
slot |
removes a parser function
|
virtualslot |
deletes a variable or constant (default uses removeVariable and removeConstant)
|
virtualslot |
deletes a variable (does not affect constants, does nothing if the variable does not exist)
|
slot |
Registers an automatic cast function.
Automatic cast functions must succeed in converting, if the result is uncertain (e.g. as in converting a string to a number) use an explicit function.
target | the target of the cast function, the target is automatically registered as primary type (see registerType) |
origin | type IDs that are automatically converted using this function, origins that are also primary types are ignored |
castfunc | the function that converts these types |
prio | the priority of the cast, if a cast function for the same origin, but a higher priority exists the one with the higher priority is used; the priority must be a positive value |
|
slot |
sets/overrides the priority of an operator, creating the operator if it does not exist yet
|
virtualslot |
sets a constant
Constants overwrite variables - if a variable of the same name exists, it is transparently deleted before the constant is created.
|
slot |
Sets a new function for a specific function name.
If there already is a function of that name it is overridden.
|
slot |
sets the parser routine for a literal value
parser | pointer to the parser routine |
startchars | characters that the literal can start with, at least some of those characters must be part of the literalStart class, the ones which are not part of it will be ignored when recognizing a literal - if none are part of the class the literal cannot be used until the class changes |
prio | a value between 0 and 100, parsers with higher values are preferred over those with lower values if they share a start character |
A return value >0 can be used as an ID to remove the parser again with removeLiteralParser(int) .
If a parser function is registered a second time the new registration overwrites the old registration.
|
slot |
sets whether named operators are allowed (default is false)
|
slot |
sets the pipe operator
|
slot |
sets the prio of the pipe operator
|
virtualslot |
sets a variable
|
slot |
simply parses an expression string into a list of tokens
Q_INVOKABLE UnaryOperator ELAM::Engine::unaryOperator | ( | QString | name | ) |
returns an existing or new unary operator object
name | the name token of the operator, if the name is not a valid operator it cannot be called from this engine until character classes change |
Q_INVOKABLE QStringList ELAM::Engine::unaryOperatorNames | ( | ) | const |
returns the names of all currently existing unary operators
|
virtual |
returns the names of all currently existing variables