OMNeT++ Simulation Library  6.0.3
cparimpl.h
1 //==========================================================================
2 // CPARIMPL.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_CPARIMPL_H
17 #define __OMNETPP_CPARIMPL_H
18 
19 #include "cpar.h"
20 #include "cexpression.h"
21 #include "cexception.h"
22 #include "fileline.h"
23 #include "opp_pooledstring.h"
24 
25 namespace omnetpp {
26 
27 class cExpression;
28 class cXMLElement;
29 class cProperties;
30 class cComponent;
31 
32 namespace internal {
33 
46 class SIM_API cParImpl : public cNamedObject
47 {
48  protected:
49  // various flags, stored in cNamedObject::flags
50  enum {
51  FL_ISVOLATILE = 4, // whether it was declared as "volatile" in NED
52  FL_ISEXPR = 8, // whether it stores a constant or an expression
53  FL_ISSHARED = 16, // used by cPar only: whether this object is shared among multiple cPars
54  FL_CONTAINSVALUE = 32, // whether it has a value
55  FL_ISSET = 64, // whether the contained value is just a default value (false) or the set value (true)
56  FL_ISMUTABLE = 128 // whether it was declared as "mutable" in NED
57  };
58 
59  private:
60  // unit (s, mW, GHz, baud, etc); optional
61  opp_staticpooledstring unit = nullptr;
62 
63  // base directory for interpreting relative path names in the expression (e.g. xmldoc())
64  opp_staticpooledstring baseDirectory = nullptr;
65 
66  // global variables for statistics
67  static long totalParimplObjs;
68  static long liveParimplObjs;
69 
70  private:
71  void copy(const cParImpl& other);
72 
73  public:
74  typedef cPar::Type Type;
75 
76  protected:
77  cValue evaluate(cExpression *expr, cComponent *context) const;
78 
79  public:
82 
86  explicit cParImpl();
87 
91  cParImpl(const cParImpl& other) : cNamedObject(other) {copy(other);}
92 
96  virtual ~cParImpl();
97 
101  cParImpl& operator=(const cParImpl& otherpar);
103 
109  virtual cParImpl *dup() const override;
110 
114  virtual void parsimPack(cCommBuffer *buffer) const override;
115 
119  virtual void parsimUnpack(cCommBuffer *buffer) override;
121 
127  virtual Type getType() const = 0;
128 
132  virtual bool isNumeric() const = 0;
133 
137  virtual bool isVolatile() const {return flags & FL_ISVOLATILE;}
138 
142  virtual bool isMutable() const {return flags & FL_ISMUTABLE;}
143 
149  virtual bool isExpression() const {return flags & FL_ISEXPR;}
150 
154  virtual bool isShared() const {return flags & FL_ISSHARED;}
155 
160  virtual bool containsValue() const {return flags & FL_CONTAINSVALUE;}
161 
167  virtual bool isSet() const {return flags & FL_ISSET;}
168 
173  virtual void setIsVolatile(bool f) {setFlag(FL_ISVOLATILE,f);}
174 
178  virtual void setIsMutable(bool f) {setFlag(FL_ISMUTABLE,f);}
179 
183  virtual void setIsShared(bool f) {setFlag(FL_ISSHARED,f);}
184 
188  virtual void setIsSet(bool f) {setFlag(FL_ISSET,f);}
189 
195  virtual const char *getUnit() const {return unit.c_str();}
196 
200  virtual void setUnit(const char *s) {unit = s;}
201 
206  virtual const char *getBaseDirectory() const {return baseDirectory.c_str();}
207 
212  virtual void setBaseDirectory(const char *s) {baseDirectory = s;}
214 
217 
221  virtual void setBoolValue(bool b) = 0;
222 
226  virtual void setIntValue(intval_t l) = 0;
227 
231  virtual void setDoubleValue(double d) = 0;
232 
238  virtual void setStringValue(const char *s) = 0;
239 
243  virtual void setStringValue(const std::string& s) {setStringValue(s.c_str());}
244 
248  virtual void setObjectValue(cObject *object) = 0;
249 
253  virtual void setXMLValue(cXMLElement *node) = 0;
254 
263  virtual void setExpression(cExpression *e) = 0;
265 
268 
272  virtual bool boolValue(cComponent *context) const = 0;
273 
278  virtual intval_t intValue(cComponent *context) const = 0;
279 
284  virtual double doubleValue(cComponent *context) const = 0;
285 
294  virtual const char *stringValue(cComponent *context) const = 0;
295 
299  virtual std::string stdstringValue(cComponent *context) const = 0;
300 
304  virtual cObject *objectValue(cComponent *context) const = 0;
305 
309  virtual cXMLElement *xmlValue(cComponent *context) const = 0;
310 
314  virtual cExpression *getExpression() const = 0;
316 
319 
324  virtual void convertToConst(cComponent *context) = 0;
325 
331  virtual void parse(const char *text, FileLine loc) = 0;
332 
336  static cParImpl *createWithType(Type type);
337 
342  virtual int compare(const cParImpl *other) const;
343 
347  virtual void forEachChild(cVisitor *v, cComponent *context) {}
348 
349  using cObject::forEachChild;
351 
361  static long getTotalParImplObjectCount() {return totalParimplObjs;}
362 
369  static long getLiveParImplObjectCount() {return liveParimplObjs;}
370 
375  static void resetParImplObjectCounters() {totalParimplObjs=liveParimplObjs=0L;}
377 };
378 
379 } // namespace internal
380 } // namespace omnetpp
381 
382 
383 #endif
384 
385 
omnetpp::internal::cParImpl::getTotalParImplObjectCount
static long getTotalParImplObjectCount()
Definition: cparimpl.h:361
omnetpp::internal::cParImpl::forEachChild
virtual void forEachChild(cVisitor *v, cComponent *context)
Definition: cparimpl.h:347
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cValue
A variant-like value class used during evaluating NED expressions.
Definition: cvalue.h:47
omnetpp::internal::cParImpl::setIsMutable
virtual void setIsMutable(bool f)
Definition: cparimpl.h:178
omnetpp::cExpression
Abstract base class for expression evaluators.
Definition: cexpression.h:33
omnetpp::internal::cParImpl::getUnit
virtual const char * getUnit() const
Definition: cparimpl.h:195
omnetpp::cObject::forEachChild
virtual void forEachChild(cVisitor *v)
omnetpp::internal::cParImpl::setIsSet
virtual void setIsSet(bool f)
Definition: cparimpl.h:188
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::internal::cParImpl::cParImpl
cParImpl(const cParImpl &other)
Definition: cparimpl.h:91
omnetpp::FileLine
Definition: fileline.h:27
omnetpp::internal::cParImpl::setBaseDirectory
virtual void setBaseDirectory(const char *s)
Definition: cparimpl.h:212
omnetpp::internal::cParImpl::setIsVolatile
virtual void setIsVolatile(bool f)
Definition: cparimpl.h:173
omnetpp::internal::cParImpl::containsValue
virtual bool containsValue() const
Definition: cparimpl.h:160
omnetpp::internal::cParImpl::isSet
virtual bool isSet() const
Definition: cparimpl.h:167
omnetpp::internal::cParImpl::resetParImplObjectCounters
static void resetParImplObjectCounters()
Definition: cparimpl.h:375
omnetpp::internal::cParImpl::getBaseDirectory
virtual const char * getBaseDirectory() const
Definition: cparimpl.h:206
omnetpp::opp_staticpooledstring
Definition: opp_pooledstring.h:29
omnetpp::internal::cParImpl::setStringValue
virtual void setStringValue(const std::string &s)
Definition: cparimpl.h:243
omnetpp::internal::cParImpl::getLiveParImplObjectCount
static long getLiveParImplObjectCount()
Definition: cparimpl.h:369
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::internal::cParImpl::isMutable
virtual bool isMutable() const
Definition: cparimpl.h:142
omnetpp::internal::cParImpl
Internal class that stores values for cPar objects.
Definition: cparimpl.h:46
omnetpp::cNamedObject
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:34
omnetpp::cXMLElement
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:75
omnetpp::cComponent
Common base for module and channel classes.
Definition: ccomponent.h:49
omnetpp::internal::cParImpl::setUnit
virtual void setUnit(const char *s)
Definition: cparimpl.h:200
omnetpp::internal::cParImpl::isShared
virtual bool isShared() const
Definition: cparimpl.h:154
omnetpp::internal::cParImpl::isVolatile
virtual bool isVolatile() const
Definition: cparimpl.h:137
omnetpp::internal::cParImpl::setIsShared
virtual void setIsShared(bool f)
Definition: cparimpl.h:183
omnetpp::internal::cParImpl::isExpression
virtual bool isExpression() const
Definition: cparimpl.h:149
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41