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) | |
virtual QVariant | getVariable (QString) const |
returns the value of the named variable (does not return constants) | |
virtual QVariant | getConstant (QString) const |
returns the value of the named constant (does not return variables) | |
virtual bool | setVariable (QString, QVariant) |
sets a variable | |
virtual bool | setConstant (QString, QVariant) |
sets a constant | |
virtual void | removeVariable (QString) |
deletes a variable (does not affect constants, does nothing if the variable does not exist) | |
virtual void | removeConstant (QString) |
deletes a constant (does not affect variables, does nothing if the constant does not exist) | |
virtual void | removeValue (QString) |
deletes a variable or constant (default uses removeVariable and removeConstant) | |
bool | setFunction (QString, Function) |
Sets a new function for a specific function name. | |
void | removeFunction (QString) |
removes a function | |
int | setLiteralParser (LiteralParser parser, QString startchars, int prio=50) |
sets the parser routine for a literal value | |
void | removeLiteralParser (int parserid) |
removes a parser function | |
void | setBinaryOperatorPrio (QString name, int prio) |
sets/overrides the priority of an operator, creating the operator if it does not exist yet | |
void | registerType (int typeId) |
registers a type as primary, this means it is not cast into another type when encountered | |
void | setAutoCast (int target, QList< int >origin, TypeCast castfunc, int prio=50) |
Registers an automatic cast function. | |
Expression | expression (QString) |
simply parses an expression string into an object | |
Expression | expression (QList< Token >) |
simply parses an expression string into an object | |
QList< Token > | tokenize (QString) |
simply parses an expression string into a list of tokens | |
QVariant | evaluate (QString) |
parses and evaluates an expression string into a final value | |
QVariant | evaluate (Expression) |
evaluates a parsed expression into a final value | |
CharacterClassSettings | characterClasses () |
gives access to the character classes settings | |
Public Member Functions | |
Engine (QObject *parent=0) | |
instantiates an engine object | |
virtual Q_INVOKABLE bool | hasVariable (QString) const |
true if the named variable exists in this engine | |
virtual Q_INVOKABLE bool | hasConstant (QString) const |
true if the named constant exists in this engine | |
virtual Q_INVOKABLE bool | hasValue (QString) const |
true if a variable or constant of that name exists in this engine (default calls hasVariable() || hasConstant() ) | |
Q_INVOKABLE bool | hasFunction (QString) const |
returns true if the named function exists | |
Q_INVOKABLE Function | getFunction (QString) const |
returns the pointer to the function | |
Q_INVOKABLE bool | hasUnaryOperator (QString name) const |
returns true if there is an unaryOperator with this name | |
Q_INVOKABLE bool | hasBinaryOperator (QString name) const |
returns true if there is an binaryOperator with this name | |
Q_INVOKABLE UnaryOperator | unaryOperator (QString name) |
returns an existing or new unary operator object | |
Q_INVOKABLE BinaryOperator | binaryOperator (QString name, int prio=1, PriorityMatch match=IgnoreMismatch) |
returns an existing or new binary operator object | |
Q_INVOKABLE int | binaryOperatorPrio (QString name) |
returns the priority of the operator, or -1 if the operator does not exist | |
Q_INVOKABLE bool | isAssignment (QString name) const |
returns true if the name represents an assignment operator | |
Q_INVOKABLE QVariant | autoCast (const QVariant &) const |
performs automatic casting | |
virtual Q_INVOKABLE QStringList | variableNames () const |
returns the names of all currently existing variables | |
virtual Q_INVOKABLE QStringList | constantNames () const |
returns the names of all currently existing constants | |
Q_INVOKABLE QStringList | functionNames () const |
returns the names of all currently existing functions | |
Q_INVOKABLE QStringList | binaryOperatorNames () const |
returns the names of all currently existing binary operators | |
Q_INVOKABLE QStringList | unaryOperatorNames () const |
returns the names of all currently existing unary operators | |
Static Public Member Functions | |
static void | configureReflection (Engine &) |
register reflection functions |
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.
ELAM::Engine::Engine | ( | QObject * | parent = 0 |
) | [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 | |
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
CharacterClassSettings ELAM::Engine::characterClasses | ( | ) | [slot] |
gives access to the character classes settings
static void ELAM::Engine::configureReflection | ( | Engine & | ) | [static] |
register reflection functions
virtual Q_INVOKABLE QStringList ELAM::Engine::constantNames | ( | ) | const [virtual] |
returns the names of all currently existing constants
QVariant ELAM::Engine::evaluate | ( | QString | ) | [slot] |
parses and evaluates an expression string into a final value
QVariant ELAM::Engine::evaluate | ( | Expression | ) | [slot] |
evaluates a parsed expression into a final value
Expression ELAM::Engine::expression | ( | QString | ) | [slot] |
simply parses an expression string into an object
Expression ELAM::Engine::expression | ( | QList< Token > | ) | [slot] |
simply parses an expression string into an object
Q_INVOKABLE QStringList ELAM::Engine::functionNames | ( | ) | const |
returns the names of all currently existing functions
virtual QVariant ELAM::Engine::getConstant | ( | QString | ) | const [virtual, slot] |
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
virtual QVariant ELAM::Engine::getValue | ( | QString | ) | const [virtual, slot] |
returns the value of the named variable or constant (default uses getVariable/getConstant)
virtual QVariant ELAM::Engine::getVariable | ( | QString | ) | const [virtual, slot] |
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 Q_INVOKABLE bool ELAM::Engine::hasConstant | ( | QString | ) | const [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 Q_INVOKABLE bool ELAM::Engine::hasValue | ( | QString | ) | const [virtual] |
true if a variable or constant of that name exists in this engine (default calls hasVariable() || hasConstant() )
virtual Q_INVOKABLE bool ELAM::Engine::hasVariable | ( | QString | ) | const [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
void ELAM::Engine::registerType | ( | int | typeId | ) | [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 |
virtual void ELAM::Engine::removeConstant | ( | QString | ) | [virtual, slot] |
deletes a constant (does not affect variables, does nothing if the constant does not exist)
void ELAM::Engine::removeFunction | ( | QString | ) | [slot] |
removes a function
void ELAM::Engine::removeLiteralParser | ( | int | parserid | ) | [slot] |
removes a parser function
virtual void ELAM::Engine::removeValue | ( | QString | ) | [virtual, slot] |
deletes a variable or constant (default uses removeVariable and removeConstant)
virtual void ELAM::Engine::removeVariable | ( | QString | ) | [virtual, slot] |
deletes a variable (does not affect constants, does nothing if the variable does not exist)
void ELAM::Engine::setAutoCast | ( | int | target, | |
QList< int > | origin, | |||
TypeCast | castfunc, | |||
int | prio = 50 | |||
) | [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 |
void ELAM::Engine::setBinaryOperatorPrio | ( | QString | name, | |
int | prio | |||
) | [slot] |
sets/overrides the priority of an operator, creating the operator if it does not exist yet
virtual bool ELAM::Engine::setConstant | ( | QString | , | |
QVariant | ||||
) | [virtual, slot] |
sets a constant
Constants overwrite variables - if a variable of the same name exists, it is transparently deleted before the constant is created.
bool ELAM::Engine::setFunction | ( | QString | , | |
Function | ||||
) | [slot] |
Sets a new function for a specific function name.
If there already is a function of that name it is overridden.
int ELAM::Engine::setLiteralParser | ( | LiteralParser | parser, | |
QString | startchars, | |||
int | prio = 50 | |||
) | [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.
virtual bool ELAM::Engine::setVariable | ( | QString | , | |
QVariant | ||||
) | [virtual, slot] |
sets a variable
QList<Token> ELAM::Engine::tokenize | ( | QString | ) | [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 Q_INVOKABLE QStringList ELAM::Engine::variableNames | ( | ) | const [virtual] |
returns the names of all currently existing variables