OMNeT++ API 6.1
Discrete Event Simulation Library
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  // the file/line location where the value was assigned from
67  FileLine sourceLoc;
68 
69  // global variables for statistics
70  static long totalParimplObjs;
71  static long liveParimplObjs;
72 
73  private:
74  void copy(const cParImpl& other);
75 
76  public:
77  typedef cPar::Type Type;
78 
79  protected:
80  cValue evaluate(cExpression *expr, cComponent *context) const;
81  void deleteOld(cExpression *expr);
82 
83  public:
86 
90  explicit cParImpl();
91 
95  cParImpl(const cParImpl& other) : cNamedObject(other) {copy(other);}
96 
100  virtual ~cParImpl();
101 
105  cParImpl& operator=(const cParImpl& otherpar);
107 
113  virtual cParImpl *dup() const override;
114 
118  virtual void parsimPack(cCommBuffer *buffer) const override;
119 
123  virtual void parsimUnpack(cCommBuffer *buffer) override;
125 
131  virtual Type getType() const = 0;
132 
136  virtual bool isNumeric() const = 0;
137 
141  virtual bool isVolatile() const {return flags & FL_ISVOLATILE;}
142 
146  virtual bool isMutable() const {return flags & FL_ISMUTABLE;}
147 
153  virtual bool isExpression() const {return flags & FL_ISEXPR;}
154 
158  virtual bool isShared() const {return flags & FL_ISSHARED;}
159 
164  virtual bool containsValue() const {return flags & FL_CONTAINSVALUE;}
165 
171  virtual bool isSet() const {return flags & FL_ISSET;}
172 
177  virtual void setIsVolatile(bool f) {setFlag(FL_ISVOLATILE,f);}
178 
182  virtual void setIsMutable(bool f) {setFlag(FL_ISMUTABLE,f);}
183 
187  virtual void setIsShared(bool f) {setFlag(FL_ISSHARED,f);}
188 
192  virtual void setIsSet(bool f) {setFlag(FL_ISSET,f);}
193 
199  virtual const char *getUnit() const {return unit.c_str();}
200 
204  virtual void setUnit(const char *s) {unit = s;}
205 
210  virtual const char *getBaseDirectory() const {return baseDirectory.c_str();}
211 
216  virtual void setBaseDirectory(const char *s) {baseDirectory = s;}
217 
221  virtual void setSourceLocation(const FileLine &loc);
222 
226  virtual void clearSourceLocation();
227 
232  virtual const FileLine& getSourceLocation() const {return sourceLoc;}
234 
237 
241  virtual void setBoolValue(bool b) = 0;
242 
246  virtual void setIntValue(intval_t l) = 0;
247 
251  virtual void setDoubleValue(double d) = 0;
252 
258  virtual void setStringValue(const char *s) = 0;
259 
263  virtual void setStringValue(const std::string& s) {setStringValue(s.c_str());}
264 
268  virtual void setObjectValue(cObject *object) = 0;
269 
273  virtual void setXMLValue(cXMLElement *node) = 0;
274 
283  virtual void setExpression(cExpression *e) = 0;
285 
288 
292  virtual bool boolValue(cComponent *context) const = 0;
293 
298  virtual intval_t intValue(cComponent *context) const = 0;
299 
304  virtual double doubleValue(cComponent *context) const = 0;
305 
314  virtual const char *stringValue(cComponent *context) const = 0;
315 
319  virtual std::string stdstringValue(cComponent *context) const = 0;
320 
324  virtual cObject *objectValue(cComponent *context) const = 0;
325 
329  virtual cXMLElement *xmlValue(cComponent *context) const = 0;
330 
334  virtual cExpression *getExpression() const = 0;
336 
339 
345  virtual void convertToConst(cComponent *context) = 0;
346 
352  virtual void parse(const char *text, FileLine loc) = 0;
353 
357  static cParImpl *createWithType(Type type);
358 
363  virtual int compare(const cParImpl *other) const;
364 
368  virtual void forEachChild(cVisitor *v, cComponent *context) {}
369 
370  using cObject::forEachChild;
372 
382  static long getTotalParImplObjectCount() {return totalParimplObjs;}
383 
390  static long getLiveParImplObjectCount() {return liveParimplObjs;}
391 
396  static void resetParImplObjectCounters() {totalParimplObjs=liveParimplObjs=0L;}
398 };
399 
400 } // namespace internal
401 } // namespace omnetpp
402 
403 
404 #endif
405 
406 
omnetpp::internal::cParImpl::getTotalParImplObjectCount
static long getTotalParImplObjectCount()
Definition: cparimpl.h:382
omnetpp::internal::cParImpl::forEachChild
virtual void forEachChild(cVisitor *v, cComponent *context)
Definition: cparimpl.h:368
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:182
omnetpp::internal::cParImpl::getSourceLocation
virtual const FileLine & getSourceLocation() const
Definition: cparimpl.h:232
omnetpp::cExpression
Abstract base class for expression evaluators.
Definition: cexpression.h:33
omnetpp::internal::cParImpl::getUnit
virtual const char * getUnit() const
Definition: cparimpl.h:199
omnetpp::cObject::forEachChild
virtual void forEachChild(cVisitor *v)
omnetpp::internal::cParImpl::setIsSet
virtual void setIsSet(bool f)
Definition: cparimpl.h:192
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:95
omnetpp::FileLine
Definition: fileline.h:27
omnetpp::internal::cParImpl::setBaseDirectory
virtual void setBaseDirectory(const char *s)
Definition: cparimpl.h:216
omnetpp::internal::cParImpl::setIsVolatile
virtual void setIsVolatile(bool f)
Definition: cparimpl.h:177
omnetpp::internal::cParImpl::containsValue
virtual bool containsValue() const
Definition: cparimpl.h:164
omnetpp::internal::cParImpl::isSet
virtual bool isSet() const
Definition: cparimpl.h:171
omnetpp::internal::cParImpl::resetParImplObjectCounters
static void resetParImplObjectCounters()
Definition: cparimpl.h:396
omnetpp::internal::cParImpl::getBaseDirectory
virtual const char * getBaseDirectory() const
Definition: cparimpl.h:210
omnetpp::opp_staticpooledstring
Definition: opp_pooledstring.h:29
omnetpp::internal::cParImpl::setStringValue
virtual void setStringValue(const std::string &s)
Definition: cparimpl.h:263
omnetpp::internal::cParImpl::getLiveParImplObjectCount
static long getLiveParImplObjectCount()
Definition: cparimpl.h:390
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:146
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:204
omnetpp::internal::cParImpl::isShared
virtual bool isShared() const
Definition: cparimpl.h:158
omnetpp::internal::cParImpl::isVolatile
virtual bool isVolatile() const
Definition: cparimpl.h:141
omnetpp::internal::cParImpl::setIsShared
virtual void setIsShared(bool f)
Definition: cparimpl.h:187
omnetpp::internal::cParImpl::isExpression
virtual bool isExpression() const
Definition: cparimpl.h:153
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41