OMNeT++ API 6.1
Discrete Event Simulation Library
cmsgpar.h
1 //==========================================================================
2 // CMSGPAR.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_CMSGPAR_H
17 #define __OMNETPP_CMSGPAR_H
18 
19 #include "cownedobject.h"
20 #include "cnedmathfunction.h"
21 
22 namespace omnetpp {
23 
24 class cStatistic;
25 class cXMLElement;
26 
27 
52 class SIM_API cMsgPar : public cOwnedObject
53 {
54  public:
58  typedef void (*VoidDelFunc)(void *);
59 
63  typedef void *(*VoidDupFunc)(void *);
64 
65  private:
66  enum { SHORTSTR_MAXLEN = 27 };
67 
68  char typeChar = 'L'; // S/B/L/D/F/T/P/O
69  bool changedFlag = false;
70  bool takeOwnership = false;
71 
72  union {
73  struct { bool sht; char *str; } ls; // S:long string
74  struct { bool sht; char str[SHORTSTR_MAXLEN+1]; } ss; // S:short str
75  struct { long val; } lng; // L:long,B:bool
76  struct { double val; } dbl; // D:double
77  struct { MathFunc f; int argc;
78  double p1,p2,p3,p4; } func; // F:math function
79  struct { cStatistic *res; } dtr; // T:distribution
80  struct { void *ptr;
81  VoidDelFunc delfunc;
82  VoidDupFunc dupfunc;
83  size_t itemsize; } ptr; // P:void* pointer
84  struct { cOwnedObject *obj; } obj; // O:object pointer
85  struct { cXMLElement *node; } xmlp; // M:XML element pointer
86  };
87 
88  private:
89  void copy(const cMsgPar& other);
90 
91  // helper func: destruct old value
92  void deleteOld();
93 
94  // helper func: rand.num with given distr.(T)
95  double getFromstat();
96 
97  // setFromText() helper func.
98  bool setfunction(char *w);
99 
100  protected:
103 
109  virtual void beforeChange();
110 
116  virtual void afterChange();
118 
119  public:
122 
126  cMsgPar(const cMsgPar& other);
127 
132  explicit cMsgPar(const char *name=nullptr);
133 
138  explicit cMsgPar(const char *name, cMsgPar& other);
139 
143  virtual ~cMsgPar();
144 
156  cMsgPar& operator=(const cMsgPar& otherpar);
158 
161 
166  virtual cMsgPar *dup() const override {return new cMsgPar(*this);}
167 
172  virtual std::string str() const override;
173 
178  virtual void forEachChild(cVisitor *v) override;
179 
185  virtual void parsimPack(cCommBuffer *buffer) const override;
186 
192  virtual void parsimUnpack(cCommBuffer *buffer) override;
194 
197 
201  cMsgPar& setBoolValue(bool b);
202 
206  cMsgPar& setLongValue(long l);
207 
213  cMsgPar& setStringValue(const char *s);
214 
218  cMsgPar& setDoubleValue(double d);
219 
225  cMsgPar& setDoubleValue(cStatistic *res);
226 
231  cMsgPar& setDoubleValue(MathFuncNoArg f);
232 
238  cMsgPar& setDoubleValue(MathFunc1Arg f, double p1);
239 
245  cMsgPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
246 
252  cMsgPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
253 
259  cMsgPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
260 
267  cMsgPar& setPointerValue(void *ptr);
268 
273  cMsgPar& setObjectValue(cOwnedObject *obj);
274 
278  cMsgPar& setXMLValue(cXMLElement *node);
279 
299  void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
300 
306  void setTakeOwnership(bool tk) {takeOwnership=tk;}
307 
311  bool getTakeOwnership() const {return takeOwnership;}
313 
316 
320  bool boolValue();
321 
326  long longValue();
327 
331  const char *stringValue();
332 
337  double doubleValue();
338 
342  void *pointerValue();
343 
347  cOwnedObject *getObjectValue();
348 
352  cXMLElement *xmlValue();
354 
357 
361  char getType() const;
362 
366  bool isNumeric() const;
367 
373  bool isConstant() const;
374 
380  bool hasChanged();
382 
389  void convertToConst();
390 
395  bool equalsTo(cMsgPar *par);
397 
407  virtual bool parse(const char *text, char type='?');
409 
412 
416  cMsgPar& operator=(bool b) {return setBoolValue(b);}
417 
421  cMsgPar& operator=(const char *s) {return setStringValue(s);}
422 
426  cMsgPar& operator=(char c) {return setLongValue((long)c);}
427 
431  cMsgPar& operator=(unsigned char c) {return setLongValue((long)c);}
432 
436  cMsgPar& operator=(int i) {return setLongValue((long)i);}
437 
441  cMsgPar& operator=(unsigned int i) {return setLongValue((long)i);}
442 
446  cMsgPar& operator=(short i) {return setLongValue((long)i);}
447 
451  cMsgPar& operator=(unsigned short i) {return setLongValue((long)i);}
452 
456  cMsgPar& operator=(long l) {return setLongValue(l);}
457 
461  cMsgPar& operator=(unsigned long l) {return setLongValue((long)l);}
462 
466  cMsgPar& operator=(double d) {return setDoubleValue(d);}
467 
471  cMsgPar& operator=(long double d) {return setDoubleValue((double)d);}
472 
476  cMsgPar& operator=(void *ptr) {return setPointerValue(ptr);}
477 
481  cMsgPar& operator=(cOwnedObject *obj) {return setObjectValue(obj);}
482 
486  cMsgPar& operator=(cXMLElement *node) {return setXMLValue(node);}
487 
491  operator bool() {return boolValue();}
492 
496  operator const char *() {return stringValue();}
497 
501  operator char() {return (char)longValue();}
502 
506  operator unsigned char() {return (unsigned char)longValue();}
507 
511  operator int() {return (int)longValue();}
512 
516  operator unsigned int() {return (unsigned int)longValue();}
517 
521  operator short() {return (short)longValue();}
522 
526  operator unsigned short() {return (unsigned short)longValue();}
527 
531  operator long() {return longValue();}
532 
536  operator unsigned long() {return longValue();}
537 
541  operator double() {return doubleValue();}
542 
546  operator long double() {return doubleValue();}
547 
551  operator void *() {return pointerValue();}
552 
556  operator cOwnedObject *() {return getObjectValue();}
557 
561  operator cXMLElement *() {return xmlValue();}
563 };
564 
565 } // namespace omnetpp
566 
567 
568 #endif
569 
570 
omnetpp::cMsgPar::operator=
cMsgPar & operator=(void *ptr)
Definition: cmsgpar.h:476
omnetpp::cMsgPar::operator=
cMsgPar & operator=(cXMLElement *node)
Definition: cmsgpar.h:486
omnetpp::cMsgPar::operator=
cMsgPar & operator=(int i)
Definition: cmsgpar.h:436
omnetpp::cMsgPar::operator=
cMsgPar & operator=(unsigned int i)
Definition: cmsgpar.h:441
omnetpp::cMsgPar::getTakeOwnership
bool getTakeOwnership() const
Definition: cmsgpar.h:311
omnetpp::MathFunc2Args
double(* MathFunc2Args)(double, double)
Prototype for mathematical functions taking two arguments.
Definition: cnedmathfunction.h:57
omnetpp::cMsgPar::setTakeOwnership
void setTakeOwnership(bool tk)
Definition: cmsgpar.h:306
omnetpp::MathFunc3Args
double(* MathFunc3Args)(double, double, double)
Prototype for mathematical functions taking three arguments.
Definition: cnedmathfunction.h:65
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::cMsgPar::operator=
cMsgPar & operator=(cOwnedObject *obj)
Definition: cmsgpar.h:481
omnetpp::cMsgPar::operator=
cMsgPar & operator=(char c)
Definition: cmsgpar.h:426
omnetpp::MathFunc
double(* MathFunc)(...)
Prototype for mathematical functions.
Definition: cnedmathfunction.h:33
omnetpp::cMsgPar::operator=
cMsgPar & operator=(long double d)
Definition: cmsgpar.h:471
omnetpp::cMsgPar::operator=
cMsgPar & operator=(const char *s)
Definition: cmsgpar.h:421
omnetpp::cMsgPar::operator=
cMsgPar & operator=(short i)
Definition: cmsgpar.h:446
omnetpp::cMsgPar::operator=
cMsgPar & operator=(long l)
Definition: cmsgpar.h:456
omnetpp::MathFunc4Args
double(* MathFunc4Args)(double, double, double, double)
Prototype for mathematical functions taking four arguments.
Definition: cnedmathfunction.h:73
omnetpp::cXMLElement
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:75
omnetpp::cMsgPar::dup
virtual cMsgPar * dup() const override
Definition: cmsgpar.h:166
omnetpp::cMsgPar::operator=
cMsgPar & operator=(unsigned char c)
Definition: cmsgpar.h:431
omnetpp::MathFunc1Arg
double(* MathFunc1Arg)(double)
Prototype for mathematical functions taking one argument.
Definition: cnedmathfunction.h:49
omnetpp::cMsgPar::operator=
cMsgPar & operator=(unsigned short i)
Definition: cmsgpar.h:451
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::MathFuncNoArg
double(* MathFuncNoArg)()
Prototype for mathematical functions taking no arguments.
Definition: cnedmathfunction.h:41
omnetpp::cMsgPar::operator=
cMsgPar & operator=(double d)
Definition: cmsgpar.h:466
omnetpp::cMsgPar::operator=
cMsgPar & operator=(unsigned long l)
Definition: cmsgpar.h:461
omnetpp::cMsgPar::operator=
cMsgPar & operator=(bool b)
Definition: cmsgpar.h:416
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cMsgPar
Allows a value (string, bool, double, etc) to be attached to a cMessage object.
Definition: cmsgpar.h:52
omnetpp::cOwnedObject
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:105