OMNeT++ Simulation Library  5.6.1
cexpression.h
1 //==========================================================================
2 // CEXPRESSION.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CEXPRESSION_H
17 #define __OMNETPP_CEXPRESSION_H
18 
19 #include "cobject.h"
20 #include "cexception.h"
21 #include "cnedvalue.h"
22 
23 namespace omnetpp {
24 
25 class cXMLElement;
26 
33 class SIM_API cExpression : public cObject
34 {
35  public:
39  class SIM_API Context : public cObject
40  {
41  public:
42  explicit Context(cComponent *component) : component(component) {}
43  cComponent *component = nullptr;
44  };
45 
46  public:
49 
53  explicit cExpression() {}
54 
58  cExpression(const cExpression& other) : cObject(other) {}
59 
63  virtual ~cExpression() {}
64 
68  cExpression& operator=(const cExpression& other) {return *this;}
70 
76  virtual cExpression *dup() const override {copyNotSupported(); return nullptr;}
77 
81  virtual std::string str() const override {return "";}
82 
86  virtual void parsimPack(cCommBuffer *buffer) const override {throw cRuntimeError(this, E_CANTPACK);}
87 
91  virtual void parsimUnpack(cCommBuffer *buffer) override {throw cRuntimeError(this, E_CANTPACK);}
93 
100  virtual cNedValue evaluate(Context *context) const = 0;
101 
106  virtual bool boolValue(Context *context) const = 0;
107 
113  virtual intpar_t intValue(Context *context, const char *expectedUnit=nullptr) const = 0;
114 
120  virtual double doubleValue(Context *context, const char *expectedUnit=nullptr) const = 0;
121 
126  virtual std::string stringValue(Context *context) const = 0;
127 
132  virtual cXMLElement *xmlValue(Context *context) const = 0;
133 
139  virtual cNedValue evaluate(cComponent *contextComponent=nullptr) const;
140 
147  virtual bool boolValue(cComponent *contextComponent=nullptr) const;
148 
156  virtual intpar_t intValue(cComponent *contextComponent=nullptr, const char *expectedUnit=nullptr) const;
157 
165  virtual double doubleValue(cComponent* contextComponent=nullptr, const char *expectedUnit=nullptr) const;
166 
173  virtual std::string stringValue(cComponent *contextComponent=nullptr) const;
174 
181  virtual cXMLElement *xmlValue(cComponent *contextComponent=nullptr) const;
183 
193  virtual void parse(const char *text) = 0;
194 
199  virtual int compare(const cExpression *other) const = 0;
200 
204  virtual bool containsConstSubexpressions() const = 0;
205 
210  virtual void evaluateConstSubexpressions(Context *context) = 0;
212 };
213 
214 } // namespace omnetpp
215 
216 
217 #endif
218 
219 
Thrown when the simulation kernel or other components detect a runtime error.
Definition: cexception.h:283
Common base for module and channel classes.
Definition: ccomponent.h:48
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual void parsimUnpack(cCommBuffer *buffer) override
Definition: cexpression.h:91
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
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
Value used during evaluating NED expressions.
Definition: cnedvalue.h:50
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
virtual ~cExpression()
Definition: cexpression.h:63
Definition: cabstracthistogram.h:21
virtual cExpression * dup() const override
Definition: cexpression.h:76
virtual std::string str() const override
Definition: cexpression.h:81
cExpression & operator=(const cExpression &other)
Definition: cexpression.h:68
cExpression()
Definition: cexpression.h:53
Contextual information for evaluating the expression.
Definition: cexpression.h:39
Abstract base class for expression evaluators.
Definition: cexpression.h:33
cExpression(const cExpression &other)
Definition: cexpression.h:58
virtual void parsimPack(cCommBuffer *buffer) const override
Definition: cexpression.h:86