OMNeT++ Simulation Library
6.0.3
|
#include <cdynamicexpression.h>
A stack-based expression evaluator class, for dynamically created expressions.
Classes | |
class | IResolver |
class | SymbolTable |
Public Member Functions | |
Constructors, destructor, assignment. | |
cDynamicExpression () | |
cDynamicExpression (const cDynamicExpression &other) | |
virtual | ~cDynamicExpression () |
cDynamicExpression & | operator= (const cDynamicExpression &other) |
virtual cDynamicExpression * | dup () const override |
virtual std::string | str () const override |
Setter and evaluator methods. | |
virtual void | parse (const char *text) override |
virtual void | parse (const char *text, IResolver *resolver) |
virtual void | parse (const char *text, const std::map< std::string, cValue > &symbolTable) |
virtual void | setResolver (IResolver *resolver) |
virtual IResolver * | getResolver () const |
virtual void | parseNedExpr (const char *text) |
virtual cValue | evaluate (Context *context) const override |
virtual bool | boolValue (Context *context) const override |
virtual intval_t | intValue (Context *context, const char *expectedUnit=nullptr) const override |
virtual double | doubleValue (Context *context, const char *expectedUnit=nullptr) const override |
virtual std::string | stringValue (Context *context) const override |
virtual cXMLElement * | xmlValue (Context *context) const override |
virtual cValue | evaluate (Context *context) const=0 |
virtual cValue | evaluate (cComponent *contextComponent=nullptr) const |
virtual bool | boolValue (Context *context) const=0 |
virtual bool | boolValue (cComponent *contextComponent=nullptr) const |
virtual intval_t | intValue (Context *context, const char *expectedUnit=nullptr) const=0 |
virtual intval_t | intValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const |
virtual double | doubleValue (Context *context, const char *expectedUnit=nullptr) const=0 |
virtual double | doubleValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const |
virtual std::string | stringValue (Context *context) const=0 |
virtual std::string | stringValue (cComponent *contextComponent=nullptr) const |
virtual cXMLElement * | xmlValue (Context *context) const=0 |
virtual cXMLElement * | xmlValue (cComponent *contextComponent=nullptr) const |
Public Member Functions inherited from cExpression | |
cExpression () | |
cExpression (const cExpression &other)=default | |
virtual | ~cExpression () |
cExpression & | operator= (const cExpression &other) |
virtual cValue | evaluate (cComponent *contextComponent=nullptr) const |
virtual bool | boolValue (cComponent *contextComponent=nullptr) const |
virtual intval_t | intValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const |
virtual double | doubleValue (cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const |
virtual std::string | stringValue (cComponent *contextComponent=nullptr) const |
virtual cXMLElement * | xmlValue (cComponent *contextComponent=nullptr) const |
Miscellaneous utility functions. | |
virtual int | compare (const cExpression *other) const override |
virtual bool | isAConstant () const override |
void | setSourceLocation (FileLine loc) |
virtual std::string | getSourceLocation () const override |
static double | convertUnit (double d, const char *unit, const char *targetUnit) |
|
explicit |
Constructor.
|
inline |
Copy constructor.
|
virtual |
Destructor.
cDynamicExpression& operator= | ( | const cDynamicExpression & | other | ) |
Assignment operator.
|
inlineoverridevirtual |
Creates and returns an exact copy of this object.
Implements cExpression.
Reimplemented in cOwnedDynamicExpression.
|
overridevirtual |
Converts the expression to string. See cObject for more details.
Reimplemented from cExpression.
Reimplemented in cOwnedDynamicExpression.
Referenced by cOwnedDynamicExpression::str().
|
overridevirtual |
Interprets the string as a generic expression, and stores it.
Implements cExpression.
|
inlinevirtual |
Interprets the string as a generic expression, and stores it. The resolver object allows variables, member accesses, function calls and method calls to be handled in a custom way. The expression object will take ownership of the resolver object.
References cDynamicExpression::parse().
Referenced by cDynamicExpression::parse().
|
inlinevirtual |
Interprets the string as a generic expression, and stores it. Values for variables used in the expression can be passed in the symbolTable argument. This method is simply delegates to parse(const char *text, IResolver *resolver) while using cDynamicExpression::SymbolTable as resolver.
References cDynamicExpression::parse().
Referenced by cDynamicExpression::parse().
|
virtual |
Allows changing the resolver after a parse() call.
|
inlinevirtual |
Returns the resolver.
|
virtual |
Interprets the string as a NED expression, and stores it.
Evaluate the expression, and return the results as a cValue. Evaluation errors result in exceptions.
Implements cExpression.
|
overridevirtual |
Evaluate the expression and convert the result to bool if possible; throw an error if conversion from that type is not supported.
Implements cExpression.
|
overridevirtual |
Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported, or the value of out of the range of intval_t.
Implements cExpression.
|
overridevirtual |
Evaluate the expression and convert the result to double if possible; throw an error if conversion from that type is not supported.
Implements cExpression.
|
overridevirtual |
Evaluate the expression and convert the result to string if possible; throw an error if conversion from that type is not supported.
Implements cExpression.
|
overridevirtual |
Evaluate the expression and convert the result to an XML tree if possible; throw an error if conversion from that type is not supported.
Implements cExpression.
|
overridevirtual |
Compares two expressions.
Implements cExpression.
|
overridevirtual |
Returns true if the expression is just a literal (or equivalent to one, like "2+2"). This can be used for optimization.
Reimplemented from cExpression.
|
inline |
Returns the file:line info where this expression was parsed from. Returns empty string if such info is not available.
|
inlineoverridevirtual |
Returns the file:line info where this expression was parsed from. Returns empty string if such info is not available.
Implements cExpression.
|
static |
Convert the given number into the target unit (e.g. milliwatt to watt). Throws an exception if conversion is not possible (unknown/unrelated units).
virtual cValue evaluate |
Evaluate the expression and return the result in a cValue. The context parameter cannot be nullptr.
virtual cValue evaluate |
Evaluate the expression and return the result in a cValue. This method creates a Context from contextComponent, and delegates to evaluate(Context*).
virtual bool boolValue |
Evaluate the expression and convert the result to bool if possible; throw an error if conversion from that type is not supported.
virtual bool boolValue |
Evaluate the expression and convert the result to bool if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to boolValue(Context*).
virtual intval_t intValue |
Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit.
virtual intval_t intValue |
Evaluate the expression and convert the result to intval_t if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit. This method creates a Context from contextComponent, and delegates to intValue(Context*,const char*).
virtual double doubleValue |
Evaluate the expression and convert the result to double if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit.
virtual double doubleValue |
Evaluate the expression and convert the result to double if possible; throw an error if conversion from that type is not supported. Also throws an error if the actual unit does not match the expected unit. This method creates a Context from contextComponent, and delegates to doubleValue(Context*,const char*).
virtual std::string stringValue |
Evaluate the expression and convert the result to string if possible; throw an error if conversion from that type is not supported.
virtual std::string stringValue |
Evaluate the expression and convert the result to string if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to stringValue(Context*).
virtual cXMLElement* xmlValue |
Evaluate the expression and convert the result to an XML tree if possible; throw an error if conversion from that type is not supported.
virtual cXMLElement* xmlValue |
Evaluate the expression and convert the result to an XML tree if possible; throw an error if conversion from that type is not supported. This method creates a Context from contextComponent, and delegates to xmlValue(Context*).