16 #ifndef __OMNETPP_CDYNAMICEXPRESSION_H 17 #define __OMNETPP_CDYNAMICEXPRESSION_H 19 #include "cnedvalue.h" 20 #include "cexpression.h" 21 #include "cstringpool.h" 27 class cNedMathFunction;
50 ADD, SUB, MUL, DIV, MOD, POW, NEG,
51 EQ, NE, GT, GE, LT, LE, IIF, AND, OR, XOR, NOT,
52 BIN_AND, BIN_OR, BIN_XOR, BIN_NOT, LSHIFT, RSHIFT
76 enum Type {UNDEF, BOOL, INT, DBL, STR, XML, MATHFUNC, NEDFUNC, FUNCTOR, OP, CONSTSUBEXPR};
82 struct {
intpar_t i;
const char *unit;} i;
83 struct {
double d;
const char *unit;} d;
94 void copy(
const Elem& other);
99 Elem(
const Elem& other) {type=UNDEF; copy(other);}
105 void operator=(
const Elem& other);
111 void operator=(
bool b);
123 void operator=(
double d);
129 void setUnit(
const char *s);
135 void operator=(
const char *s);
164 void operator=(
OpType op);
190 const char *
getUnit()
const {
return (type==INT) ? i.unit : (type==DBL) ? d.unit :
nullptr;}
219 int compare(
const Elem& other)
const;
224 static const char *getOpName(
OpType op);
229 std::string str()
const;
240 virtual const char *getArgTypes()
const = 0;
241 virtual int getNumArgs()
const {
return strlen(getArgTypes());}
242 virtual char getReturnType()
const = 0;
244 virtual std::string str(std::string args[],
int numargs) = 0;
257 static void ensureNoLogarithmicUnit(
const cNedValue& v);
296 virtual std::string str()
const override;
308 virtual void setExpression(
Elem e[],
int size);
321 virtual bool boolValue(
Context *context)
const override;
328 virtual intpar_t intValue(
Context *context,
const char *expectedUnit=
nullptr)
const override;
334 virtual double doubleValue(
Context *context,
const char *expectedUnit=
nullptr)
const override;
340 virtual std::string stringValue(
Context *context)
const override;
361 virtual void parse(
const char *text)
override;
366 virtual int compare(
const cExpression *other)
const override;
372 virtual bool isAConstant()
const;
377 virtual bool containsConstSubexpressions()
const override;
383 virtual void evaluateConstSubexpressions(
Context *context)
override;
389 static double convertUnit(
double d,
const char *unit,
const char *targetUnit);
const char * getStringConstant() const
Definition: cdynamicexpression.h:193
Type getType() const
Definition: cdynamicexpression.h:172
Registration class for extending NED with arbitrary new functions.
Definition: cnedfunction.h:48
bool isNumericConstant() const
Definition: cdynamicexpression.h:175
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual cXMLElement * xmlValue(Context *context) const =0
Functor * getFunctor() const
Definition: cdynamicexpression.h:208
double getDoubleConstant() const
Definition: cdynamicexpression.h:187
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
intpar_t getIntConstant() const
Definition: cdynamicexpression.h:184
Function object base class. We use function objects to handle NED parameter references, "index" and "sizeof" operators, and references to NED "for" loop variables.
Definition: cdynamicexpression.h:237
int64_t intpar_t
Type for NED parameter values that store integers. It is guaranteed to be signed and at least as wide...
Definition: simkerneldefs.h:86
OpType
Definition: cdynamicexpression.h:49
bool getBoolConstant() const
Definition: cdynamicexpression.h:181
Value used during evaluating NED expressions.
Definition: cnedvalue.h:50
int getNedFunctionNumArgs() const
Definition: cdynamicexpression.h:205
cDynamicExpression(const cDynamicExpression &other)
Definition: cdynamicexpression.h:271
One element in a (reverse Polish) expression.
Definition: cdynamicexpression.h:60
cNedFunction * getNedFunction() const
Definition: cdynamicexpression.h:202
A stack-based expression evaluator class, for dynamically created expressions.
Definition: cdynamicexpression.h:36
virtual bool boolValue(Context *context) const =0
virtual std::string str() const
virtual double doubleValue(Context *context, const char *expectedUnit=nullptr) const =0
Definition: cabstracthistogram.h:21
virtual cNedValue evaluate(Context *context) const =0
cExpression * getConstSubexpression() const
Definition: cdynamicexpression.h:214
cNedMathFunction * getMathFunction() const
Definition: cdynamicexpression.h:199
cXMLElement * getXMLElement() const
Definition: cdynamicexpression.h:196
virtual cDynamicExpression * dup() const override
Definition: cdynamicexpression.h:290
OpType getOperation() const
Definition: cdynamicexpression.h:211
virtual std::string stringValue(Context *context) const =0
Contextual information for evaluating the expression.
Definition: cexpression.h:39
Registration class for extending NED with new mathematical functions.
Definition: cnedmathfunction.h:85
const char * getUnit() const
Definition: cdynamicexpression.h:190
Abstract base class for expression evaluators.
Definition: cexpression.h:33
virtual intpar_t intValue(Context *context, const char *expectedUnit=nullptr) const =0
Reference-counted storage for strings.
Definition: cstringpool.h:36