cmsgpar.h Source File¶

API: cmsgpar.h Source File
API
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
22namespace omnetpp {
23
24class cStatistic;
25class cXMLElement;
26
27
52class 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
202
207
213 cMsgPar& setStringValue(const char *s);
214
219
226
232
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
268
273 cMsgPar& setObjectValue(cOwnedObject *obj);
274
279
290 void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
291
297 void setTakeOwnership(bool tk) {takeOwnership=tk;}
298
302 bool getTakeOwnership() const {return takeOwnership;}
304
307
311 bool boolValue();
312
317 long longValue();
318
322 const char *stringValue();
323
328 double doubleValue();
329
334
338 cOwnedObject *getObjectValue();
339
345
348
352 char getType() const;
353
357 bool isNumeric() const;
358
364 bool isConstant() const;
365
373
376
381
386 bool equalsTo(cMsgPar *par);
388
391
398 virtual bool parse(const char *text, char type='?');
400
403
407 cMsgPar& operator=(bool b) {return setBoolValue(b);}
408
412 cMsgPar& operator=(const char *s) {return setStringValue(s);}
413
417 cMsgPar& operator=(char c) {return setLongValue((long)c);}
418
422 cMsgPar& operator=(unsigned char c) {return setLongValue((long)c);}
423
427 cMsgPar& operator=(int i) {return setLongValue((long)i);}
428
432 cMsgPar& operator=(unsigned int i) {return setLongValue((long)i);}
433
437 cMsgPar& operator=(short i) {return setLongValue((long)i);}
438
442 cMsgPar& operator=(unsigned short i) {return setLongValue((long)i);}
443
447 cMsgPar& operator=(long l) {return setLongValue(l);}
448
452 cMsgPar& operator=(unsigned long l) {return setLongValue((long)l);}
453
457 cMsgPar& operator=(double d) {return setDoubleValue(d);}
458
462 cMsgPar& operator=(long double d) {return setDoubleValue((double)d);}
463
467 cMsgPar& operator=(void *ptr) {return setPointerValue(ptr);}
468
472 cMsgPar& operator=(cOwnedObject *obj) {return setObjectValue(obj);}
473
477 cMsgPar& operator=(cXMLElement *node) {return setXMLValue(node);}
478
482 operator bool() {return boolValue();}
483
487 operator const char *() {return stringValue();}
488
492 operator char() {return (char)longValue();}
493
497 operator unsigned char() {return (unsigned char)longValue();}
498
502 operator int() {return (int)longValue();}
503
507 operator unsigned int() {return (unsigned int)longValue();}
508
512 operator short() {return (short)longValue();}
513
517 operator unsigned short() {return (unsigned short)longValue();}
518
522 operator long() {return longValue();}
523
527 operator unsigned long() {return longValue();}
528
532 operator double() {return doubleValue();}
533
537 operator long double() {return doubleValue();}
538
542 operator void *() {return pointerValue();}
543
547 operator cOwnedObject *() {return getObjectValue();}
548
552 operator cXMLElement *() {return xmlValue();}
554};
555
556} // namespace omnetpp
557
558
559#endif
560
561
Buffer for the communications layer of parallel simulation.
Definition ccommbuffer.h:42
void(* VoidDelFunc)(void *)
Definition cmsgpar.h:58
cXMLElement * xmlValue()
virtual void beforeChange()
bool equalsTo(cMsgPar *par)
void setTakeOwnership(bool tk)
Definition cmsgpar.h:297
cMsgPar & setDoubleValue(MathFunc2Args f, double p1, double p2)
bool isNumeric() const
cMsgPar & operator=(int i)
Definition cmsgpar.h:427
cMsgPar & setDoubleValue(cStatistic *res)
cMsgPar & setLongValue(long l)
bool isConstant() const
cMsgPar & setDoubleValue(MathFunc3Args f, double p1, double p2, double p3)
cMsgPar & setDoubleValue(double d)
virtual void parsimPack(cCommBuffer *buffer) const override
const char * stringValue()
cMsgPar & operator=(long l)
Definition cmsgpar.h:447
void * pointerValue()
cMsgPar & setDoubleValue(MathFuncNoArg f)
virtual void afterChange()
cMsgPar & operator=(unsigned char c)
Definition cmsgpar.h:422
virtual void parsimUnpack(cCommBuffer *buffer) override
virtual cMsgPar * dup() const override
Definition cmsgpar.h:166
cMsgPar & operator=(void *ptr)
Definition cmsgpar.h:467
cMsgPar & operator=(double d)
Definition cmsgpar.h:457
cMsgPar & setObjectValue(cOwnedObject *obj)
void configPointer(VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0)
cMsgPar & operator=(long double d)
Definition cmsgpar.h:462
double doubleValue()
cMsgPar & operator=(const cMsgPar &otherpar)
cMsgPar(const char *name, cMsgPar &other)
cMsgPar & operator=(const char *s)
Definition cmsgpar.h:412
cMsgPar & setDoubleValue(MathFunc1Arg f, double p1)
char getType() const
cMsgPar & operator=(bool b)
Definition cmsgpar.h:407
virtual bool parse(const char *text, char type='?')
cMsgPar & operator=(char c)
Definition cmsgpar.h:417
void *(* VoidDupFunc)(void *)
Definition cmsgpar.h:63
cMsgPar & setXMLValue(cXMLElement *node)
bool getTakeOwnership() const
Definition cmsgpar.h:302
virtual void forEachChild(cVisitor *v) override
cMsgPar & setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4)
virtual std::string str() const override
cMsgPar & operator=(unsigned short i)
Definition cmsgpar.h:442
virtual ~cMsgPar()
cMsgPar & operator=(cXMLElement *node)
Definition cmsgpar.h:477
cOwnedObject * getObjectValue()
cMsgPar & operator=(unsigned long l)
Definition cmsgpar.h:452
cMsgPar & operator=(short i)
Definition cmsgpar.h:437
cMsgPar & operator=(cOwnedObject *obj)
Definition cmsgpar.h:472
cMsgPar & setBoolValue(bool b)
cMsgPar & operator=(unsigned int i)
Definition cmsgpar.h:432
cMsgPar(const cMsgPar &other)
cMsgPar & setPointerValue(void *ptr)
cMsgPar & setStringValue(const char *s)
cMsgPar(const char *name=nullptr)
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition cstatistic.h:35
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57
Represents an XML element in an XML configuration file.
Definition cxmlelement.h:76
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
double(* MathFunc1Arg)(double)
Prototype for mathematical functions taking one argument.
Definition cnedmathfunction.h:49
double(* MathFunc)(...)
Prototype for mathematical functions.
Definition cnedmathfunction.h:33
double(* MathFunc3Args)(double, double, double)
Prototype for mathematical functions taking three arguments.
Definition cnedmathfunction.h:65
double(* MathFuncNoArg)()
Prototype for mathematical functions taking no arguments.
Definition cnedmathfunction.h:41