ELAM
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Slots | Public Member Functions | Static Public Member Functions | List of all members
ELAM::Engine Class Reference

The calculation engine of . More...

#include <elamengine.h>

Inheritance diagram for ELAM::Engine:
Inheritance graph
[legend]
Collaboration diagram for ELAM::Engine:
Collaboration graph
[legend]

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

Detailed Description

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.

Member Enumeration Documentation

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.

Enumerator
IgnoreMismatch 

if the operator is new: use the given priority, otherwise leave priority as is ignoring the one given in the call, this is the default

OverridePrio 

override the priority of the existing operator, using the priority given in the call

FailIfMismatch 

returns a dummy operator making it impossible to overwrite the existing operator

Constructor & Destructor Documentation

ELAM::Engine::Engine ( QObject *  parent = 0)
explicit

instantiates an engine object

Member Function Documentation

Q_INVOKABLE QVariant ELAM::Engine::autoCast ( const QVariant &  ) const

performs automatic casting

Returns
the casted value or the original value if it is of a primary type or if there is no known cast for it
Q_INVOKABLE BinaryOperator ELAM::Engine::binaryOperator ( QString  name,
int  prio = 1,
PriorityMatch  match = IgnoreMismatch 
)

returns an existing or new binary operator object

Parameters
namethe name token of the operator, if the name is not a valid operator it cannot be called from this engine until character classes change
priothe priority that should be set for the operator; higher value means stronger binding
matchhow to behave if the operator already exists and priorities do not match, see PriorityMatch
Returns
a reference to the operator, or to a dummy operator if priority matching failed
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
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

virtual QVariant ELAM::Engine::getValue ( QString  ) const
virtualslot

returns the value of the named variable or constant (default uses getVariable/getConstant)

virtual QVariant ELAM::Engine::getVariable ( QString  ) const
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 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

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)

void ELAM::Engine::registerType ( int  typeId)
slot

registers a type as primary, this means it is not cast into another type when encountered

Parameters
typeIdthe QVariant ID of the type to register
virtual void ELAM::Engine::removeConstant ( QString  )
virtualslot

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  )
virtualslot

deletes a variable or constant (default uses removeVariable and removeConstant)

virtual void ELAM::Engine::removeVariable ( QString  )
virtualslot

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.

Parameters
targetthe target of the cast function, the target is automatically registered as primary type (see registerType)
origintype IDs that are automatically converted using this function, origins that are also primary types are ignored
castfuncthe function that converts these types
priothe 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   
)
virtualslot

sets a constant

Returns
true on success or false if:
  • the name is not valid
  • a function of that name exists

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.

Returns
true on success or false if:
  • the name is not syntactically valid
  • the function is null
  • a constant or variable of the same name exists already
int ELAM::Engine::setLiteralParser ( LiteralParser  parser,
QString  startchars,
int  prio = 50 
)
slot

sets the parser routine for a literal value

Parameters
parserpointer to the parser routine
startcharscharacters 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
prioa value between 0 and 100, parsers with higher values are preferred over those with lower values if they share a start character
Returns
>0 if the parser is registered successfully, or 0 if:
  • the parser is null
  • the start characters are empty
  • the priority is outside the allowed range (0<=prio<=100)

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.

void ELAM::Engine::setNamedOperatorsAllowed ( bool  )
slot

sets whether named operators are allowed (default is false)

void ELAM::Engine::setPipeOperator ( QString  pipe)
slot

sets the pipe operator

void ELAM::Engine::setPipePrio ( int  )
slot

sets the prio of the pipe operator

virtual bool ELAM::Engine::setVariable ( QString  ,
QVariant   
)
virtualslot

sets a variable

Returns
true on success or false if:
  • the name is not valid
  • a function or constant of that name already exists
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

Parameters
namethe 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


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