OMNeT++ Simulation Library  5.6.1
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  protected:
66  static const char *possibleTypes;
67 
68  private:
69  enum { SHORTSTR_MAXLEN = 27 };
70 
71  char typeChar; // S/B/L/D/F/T/P/O
72  bool changedFlag;
73  bool takeOwnership;
74 
75  union {
76  struct { bool sht; char *str; } ls; // S:long string
77  struct { bool sht; char str[SHORTSTR_MAXLEN+1]; } ss; // S:short str
78  struct { long val; } lng; // L:long,B:bool
79  struct { double val; } dbl; // D:double
80  struct { MathFunc f; int argc;
81  double p1,p2,p3,p4; } func; // F:math function
82  struct { cStatistic *res; } dtr; // T:distribution
83  struct { void *ptr;
84  VoidDelFunc delfunc;
85  VoidDupFunc dupfunc;
86  size_t itemsize; } ptr; // P:void* pointer
87  struct { cOwnedObject *obj; } obj; // O:object pointer
88  struct { cXMLElement *node; } xmlp; // M:XML element pointer
89  };
90 
91  private:
92  void copy(const cMsgPar& other);
93 
94  // helper func: destruct old value
95  void deleteOld();
96 
97  // helper func: rand.num with given distr.(T)
98  double getFromstat();
99 
100  // setFromText() helper func.
101  bool setfunction(char *w);
102 
103  protected:
106 
112  virtual void beforeChange();
113 
119  virtual void afterChange();
121 
122  public:
125 
129  cMsgPar(const cMsgPar& other);
130 
135  explicit cMsgPar(const char *name=nullptr);
136 
141  explicit cMsgPar(const char *name, cMsgPar& other);
142 
146  virtual ~cMsgPar();
147 
159  cMsgPar& operator=(const cMsgPar& otherpar);
161 
164 
169  virtual cMsgPar *dup() const override {return new cMsgPar(*this);}
170 
175  virtual std::string str() const override;
176 
181  virtual void forEachChild(cVisitor *v) override;
182 
188  virtual void parsimPack(cCommBuffer *buffer) const override;
189 
195  virtual void parsimUnpack(cCommBuffer *buffer) override;
197 
200 
204  cMsgPar& setBoolValue(bool b);
205 
209  cMsgPar& setLongValue(long l);
210 
216  cMsgPar& setStringValue(const char *s);
217 
221  cMsgPar& setDoubleValue(double d);
222 
228  cMsgPar& setDoubleValue(cStatistic *res);
229 
234  cMsgPar& setDoubleValue(MathFuncNoArg f);
235 
241  cMsgPar& setDoubleValue(MathFunc1Arg f, double p1);
242 
248  cMsgPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
249 
255  cMsgPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
256 
262  cMsgPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
263 
270  cMsgPar& setPointerValue(void *ptr);
271 
276  cMsgPar& setObjectValue(cOwnedObject *obj);
277 
281  cMsgPar& setXMLValue(cXMLElement *node);
282 
302  void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
303 
309  void setTakeOwnership(bool tk) {takeOwnership=tk;}
310 
314  bool getTakeOwnership() const {return takeOwnership;}
316 
319 
323  bool boolValue();
324 
329  long longValue();
330 
334  const char *stringValue();
335 
340  double doubleValue();
341 
345  void *pointerValue();
346 
350  cOwnedObject *getObjectValue();
351 
355  cXMLElement *xmlValue();
357 
360 
364  char getType() const;
365 
369  bool isNumeric() const;
370 
376  bool isConstant() const;
377 
383  bool hasChanged();
385 
392  void convertToConst();
393 
398  bool equalsTo(cMsgPar *par);
400 
410  virtual bool parse(const char *text, char type='?');
412 
415 
419  cMsgPar& operator=(bool b) {return setBoolValue(b);}
420 
424  cMsgPar& operator=(const char *s) {return setStringValue(s);}
425 
429  cMsgPar& operator=(char c) {return setLongValue((long)c);}
430 
434  cMsgPar& operator=(unsigned char c) {return setLongValue((long)c);}
435 
439  cMsgPar& operator=(int i) {return setLongValue((long)i);}
440 
444  cMsgPar& operator=(unsigned int i) {return setLongValue((long)i);}
445 
449  cMsgPar& operator=(short i) {return setLongValue((long)i);}
450 
454  cMsgPar& operator=(unsigned short i) {return setLongValue((long)i);}
455 
459  cMsgPar& operator=(long l) {return setLongValue(l);}
460 
464  cMsgPar& operator=(unsigned long l) {return setLongValue((long)l);}
465 
469  cMsgPar& operator=(double d) {return setDoubleValue(d);}
470 
474  cMsgPar& operator=(long double d) {return setDoubleValue((double)d);}
475 
479  cMsgPar& operator=(void *ptr) {return setPointerValue(ptr);}
480 
484  cMsgPar& operator=(cOwnedObject *obj) {return setObjectValue(obj);}
485 
489  cMsgPar& operator=(cXMLElement *node) {return setXMLValue(node);}
490 
494  operator bool() {return boolValue();}
495 
499  operator const char *() {return stringValue();}
500 
504  operator char() {return (char)longValue();}
505 
509  operator unsigned char() {return (unsigned char)longValue();}
510 
514  operator int() {return (int)longValue();}
515 
519  operator unsigned int() {return (unsigned int)longValue();}
520 
524  operator short() {return (short)longValue();}
525 
529  operator unsigned short() {return (unsigned short)longValue();}
530 
534  operator long() {return longValue();}
535 
539  operator unsigned long() {return longValue();}
540 
544  operator double() {return doubleValue();}
545 
549  operator long double() {return doubleValue();}
550 
554  operator void *() {return pointerValue();}
555 
559  operator cOwnedObject *() {return getObjectValue();}
560 
564  operator cXMLElement *() {return xmlValue();}
566 };
567 
568 } // namespace omnetpp
569 
570 
571 #endif
572 
573 
void setTakeOwnership(bool tk)
Definition: cmsgpar.h:309
cMsgPar & operator=(cXMLElement *node)
Definition: cmsgpar.h:489
virtual cMsgPar * dup() const override
Definition: cmsgpar.h:169
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
double(* MathFunc4Args)(double, double, double, double)
Prototype for mathematical functions taking four arguments.
Definition: cnedmathfunction.h:73
double(* MathFunc2Args)(double, double)
Prototype for mathematical functions taking two arguments.
Definition: cnedmathfunction.h:57
cMsgPar & operator=(unsigned int i)
Definition: cmsgpar.h:444
bool getTakeOwnership() const
Definition: cmsgpar.h:314
cMsgPar & operator=(const char *s)
Definition: cmsgpar.h:424
cMsgPar & operator=(unsigned char c)
Definition: cmsgpar.h:434
Allows a value (string, bool, double, etc) to be attached to a cMessage object.
Definition: cmsgpar.h:52
double(* MathFunc3Args)(double, double, double)
Prototype for mathematical functions taking three arguments.
Definition: cnedmathfunction.h:65
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
A cObject that keeps track of its owner. It serves as base class for many classes in the OMNeT++ libr...
Definition: cownedobject.h:104
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
double(* MathFunc)(...)
Prototype for mathematical functions.
Definition: cnedmathfunction.h:33
cMsgPar & operator=(unsigned short i)
Definition: cmsgpar.h:454
double(* MathFuncNoArg)()
Prototype for mathematical functions taking no arguments.
Definition: cnedmathfunction.h:41
Definition: cabstracthistogram.h:21
cMsgPar & operator=(long double d)
Definition: cmsgpar.h:474
cMsgPar & operator=(void *ptr)
Definition: cmsgpar.h:479
cMsgPar & operator=(unsigned long l)
Definition: cmsgpar.h:464
cMsgPar & operator=(bool b)
Definition: cmsgpar.h:419
cMsgPar & operator=(double d)
Definition: cmsgpar.h:469
cMsgPar & operator=(short i)
Definition: cmsgpar.h:449
cMsgPar & operator=(int i)
Definition: cmsgpar.h:439
double(* MathFunc1Arg)(double)
Prototype for mathematical functions taking one argument.
Definition: cnedmathfunction.h:49
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
cMsgPar & operator=(long l)
Definition: cmsgpar.h:459
cMsgPar & operator=(char c)
Definition: cmsgpar.h:429
cMsgPar & operator=(cOwnedObject *obj)
Definition: cmsgpar.h:484