OMNeT++ Simulation Library  5.6.1
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 "cstringpool.h"
22 #include "cexception.h"
23 
24 namespace omnetpp {
25 
26 class cExpression;
27 class cXMLElement;
28 class cProperties;
29 class cComponent;
30 
31 
44 class SIM_API cParImpl : public cNamedObject
45 {
46  protected:
47  // various flags, stored in cNamedObject::flags
48  enum {
49  FL_ISVOLATILE = 4, // whether it was declared as "volatile" in NED
50  FL_ISEXPR = 8, // whether it stores a constant or an expression
51  FL_ISSHARED = 16, // used by cPar only: whether this object is shared among multiple cPars
52  FL_CONTAINSVALUE = 32, // whether it has a value
53  FL_ISSET = 64 // whether the contained value is just a default value (false) or the set value (true)
54  };
55 
56  private:
57  // unit (s, mW, GHz, baud, etc); optional
58  const char *unitp; // stringpooled
59 
60  // global variables for statistics
61  static long totalParimplObjs;
62  static long liveParimplObjs;
63  static cStringPool unitStringPool;
64 
65  private:
66  void copy(const cParImpl& other);
67 
68  public:
69  typedef cPar::Type Type;
70 
71  protected:
72  cNedValue evaluate(cExpression *expr, cComponent *context) const;
73 
74  public:
77 
81  explicit cParImpl();
82 
86  cParImpl(const cParImpl& other) : cNamedObject(other) {unitp = nullptr; copy(other);}
87 
91  virtual ~cParImpl();
92 
96  cParImpl& operator=(const cParImpl& otherpar);
98 
104  virtual cParImpl *dup() const override;
105 
109  virtual void parsimPack(cCommBuffer *buffer) const override;
110 
114  virtual void parsimUnpack(cCommBuffer *buffer) override;
116 
122  virtual Type getType() const = 0;
123 
127  virtual bool isNumeric() const = 0;
128 
132  virtual bool isVolatile() const {return flags & FL_ISVOLATILE;}
133 
139  virtual bool isExpression() const {return flags & FL_ISEXPR;}
140 
144  virtual bool isShared() const {return flags & FL_ISSHARED;}
145 
150  virtual bool containsValue() const {return flags & FL_CONTAINSVALUE;}
151 
157  virtual bool isSet() const {return flags & FL_ISSET;}
158 
163  virtual void setIsVolatile(bool f) {setFlag(FL_ISVOLATILE,f);}
164 
168  virtual void setIsShared(bool f) {setFlag(FL_ISSHARED,f);}
169 
173  virtual void setIsSet(bool f) {setFlag(FL_ISSET,f);}
174 
180  virtual const char *getUnit() const;
181 
185  virtual void setUnit(const char *s);
187 
190 
194  virtual void setBoolValue(bool b) = 0;
195 
199  virtual void setIntValue(intpar_t l) = 0;
200 
204  virtual void setDoubleValue(double d) = 0;
205 
211  virtual void setStringValue(const char *s) = 0;
212 
216  virtual void setStringValue(const std::string& s) {setStringValue(s.c_str());}
217 
221  virtual void setXMLValue(cXMLElement *node) = 0;
222 
231  virtual void setExpression(cExpression *e) = 0;
233 
236 
240  virtual bool boolValue(cComponent *context) const = 0;
241 
246  virtual intpar_t intValue(cComponent *context) const = 0;
247 
252  virtual double doubleValue(cComponent *context) const = 0;
253 
262  virtual const char *stringValue(cComponent *context) const = 0;
263 
267  virtual std::string stdstringValue(cComponent *context) const = 0;
268 
272  virtual cXMLElement *xmlValue(cComponent *context) const = 0;
273 
277  virtual cExpression *getExpression() const = 0;
279 
282 
287  virtual void convertToConst(cComponent *context) = 0;
288 
292  virtual bool containsConstSubexpressions() const;
293 
298  virtual void evaluateConstSubexpressions(cComponent *context);
299 
305  virtual void parse(const char *text) = 0;
306 
310  static cParImpl *createWithType(Type type);
311 
316  virtual int compare(const cParImpl *other) const;
317 
321  virtual void forEachChild(cVisitor *v, cComponent *context) {}
322 
323  using cObject::forEachChild;
325 
335  static long getTotalParImplObjectCount() {return totalParimplObjs;}
336 
343  static long getLiveParImplObjectCount() {return liveParimplObjs;}
344 
349  static void resetParImplObjectCounters() {totalParimplObjs=liveParimplObjs=0L;}
351 };
352 
353 } // namespace omnetpp
354 
355 
356 #endif
357 
358 
Common base for module and channel classes.
Definition: ccomponent.h:48
virtual bool isShared() const
Definition: cparimpl.h:144
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
virtual bool containsValue() const
Definition: cparimpl.h:150
Extends cObject with a name string. Also includes a "flags" member, with bits open for use by subclas...
Definition: cnamedobject.h:36
virtual bool isSet() const
Definition: cparimpl.h:157
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
virtual bool isExpression() const
Definition: cparimpl.h:139
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
virtual bool isVolatile() const
Definition: cparimpl.h:132
static void resetParImplObjectCounters()
Definition: cparimpl.h:349
virtual void forEachChild(cVisitor *v)
virtual void setIsSet(bool f)
Definition: cparimpl.h:173
virtual void forEachChild(cVisitor *v, cComponent *context)
Definition: cparimpl.h:321
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
static long getTotalParImplObjectCount()
Definition: cparimpl.h:335
Definition: cabstracthistogram.h:21
cParImpl(const cParImpl &other)
Definition: cparimpl.h:86
virtual void setIsShared(bool f)
Definition: cparimpl.h:168
virtual void setStringValue(const std::string &s)
Definition: cparimpl.h:216
Abstract base class for expression evaluators.
Definition: cexpression.h:33
Internal class that stores values for cPar objects.
Definition: cparimpl.h:44
virtual void setIsVolatile(bool f)
Definition: cparimpl.h:163
static long getLiveParImplObjectCount()
Definition: cparimpl.h:343
Reference-counted storage for strings.
Definition: cstringpool.h:36