cmsgpar.h

00001 //==========================================================================
00002 //   CMSGPAR.H  - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //==========================================================================
00007 
00008 /*--------------------------------------------------------------*
00009   Copyright (C) 1992-2008 Andras Varga
00010   Copyright (C) 2006-2008 OpenSim Ltd.
00011 
00012   This file is distributed WITHOUT ANY WARRANTY. See the file
00013   `license' for details on this and other legal matters.
00014 *--------------------------------------------------------------*/
00015 
00016 #ifndef __CMSGPAR_H
00017 #define __CMSGPAR_H
00018 
00019 #include "cownedobject.h"
00020 #include "cnedmathfunction.h"
00021 
00022 NAMESPACE_BEGIN
00023 
00024 class  cStatistic;
00025 class  cXMLElement;
00026 
00027 
00052 class SIM_API cMsgPar : public cOwnedObject
00053 {
00054   protected:
00055     static const char *possibletypes;
00056 
00057   private:
00058     enum { SHORTSTR_MAXLEN = 27 };
00059 
00060     char typechar;     // S/B/L/D/F/T/P/O
00061     bool changedflag;
00062     bool tkownership;
00063 
00064     union {
00065        struct { bool sht; char *str;  } ls;   // S:long string
00066        struct { bool sht; char str[SHORTSTR_MAXLEN+1]; } ss;  // S:short str
00067        struct { long val;             } lng;  // L:long,B:bool
00068        struct { double val;           } dbl;  // D:double
00069        struct { MathFunc f; int argc;
00070                 double p1,p2,p3,p4;   } func; // F:math function
00071        struct { cStatistic *res;      } dtr;  // T:distribution
00072        struct { void *ptr;
00073                 VoidDelFunc delfunc;
00074                 VoidDupFunc dupfunc;
00075                 size_t itemsize;      } ptr;  // P:void* pointer
00076        struct { cOwnedObject *obj;    } obj;  // O:object pointer
00077        struct { cXMLElement *node;    } xmlp; // M:XML element pointer
00078     };
00079 
00080   private:
00081     void copy(const cMsgPar& other);
00082 
00083     // helper func: destruct old value
00084     void deleteOld();
00085 
00086     // helper func: rand.num with given distr.(T)
00087     double getFromstat();
00088 
00089     // setFromText() helper func.
00090     bool setfunction(char *w);
00091 
00092   protected:
00095 
00101     virtual void beforeChange();
00102 
00108     virtual void afterChange();
00110 
00111   public:
00114 
00118     cMsgPar(const cMsgPar& other);
00119 
00124     explicit cMsgPar(const char *name=NULL);
00125 
00130     explicit cMsgPar(const char *name, cMsgPar& other);
00131 
00135     virtual ~cMsgPar();
00136 
00148     cMsgPar& operator=(const cMsgPar& otherpar);
00150 
00153 
00158     virtual cMsgPar *dup() const  {return new cMsgPar(*this);}
00159 
00164     virtual std::string info() const;
00165 
00170     virtual std::string detailedInfo() const;
00171 
00176     virtual void forEachChild(cVisitor *v);
00177 
00183     virtual void parsimPack(cCommBuffer *buffer);
00184 
00190     virtual void parsimUnpack(cCommBuffer *buffer);
00192 
00195 
00199     cMsgPar& setBoolValue(bool b);
00200 
00204     cMsgPar& setLongValue(long l);
00205 
00211     cMsgPar& setStringValue(const char *s);
00212 
00216     cMsgPar& setDoubleValue(double d);
00217 
00223     cMsgPar& setDoubleValue(cStatistic *res);
00224 
00229     cMsgPar& setDoubleValue(MathFuncNoArg f);
00230 
00236     cMsgPar& setDoubleValue(MathFunc1Arg  f, double p1);
00237 
00243     cMsgPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
00244 
00250     cMsgPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
00251 
00257     cMsgPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
00258 
00265     cMsgPar& setPointerValue(void *ptr);
00266 
00271     cMsgPar& setObjectValue(cOwnedObject *obj);
00272 
00276     cMsgPar& setXMLValue(cXMLElement *node);
00277 
00297     void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
00298 
00304     void setTakeOwnership(bool tk) {tkownership=tk;}
00305 
00309     bool getTakeOwnership() const   {return tkownership;}
00311 
00314 
00318     bool boolValue();
00319 
00324     long longValue();
00325 
00329     const char *stringValue();
00330 
00335     double doubleValue();
00336 
00340     void *pointerValue();
00341 
00345     cOwnedObject *getObjectValue();
00346 
00350     cXMLElement *xmlValue();
00352 
00355 
00359     char getType() const;
00360 
00364     bool isNumeric() const;
00365 
00371     bool isConstant() const;
00372 
00378     bool hasChanged();
00380 
00387     void convertToConst();
00388 
00393     bool equalsTo(cMsgPar *par);
00395 
00401     virtual std::string str() const;
00402 
00406     _OPPDEPRECATED std::string getAsText() const  {return str();}
00407 
00415     virtual bool parse(const char *text, char type='?');
00416 
00420     _OPPDEPRECATED bool setFromText(const char *text, char type='?')  {return parse(text, '?');}
00422 
00425 
00429     cMsgPar& operator=(bool b)  {return setBoolValue(b);}
00430 
00434     cMsgPar& operator=(const char *s)  {return setStringValue(s);}
00435 
00439     cMsgPar& operator=(char c)  {return setLongValue((long)c);}
00440 
00444     cMsgPar& operator=(unsigned char c) {return setLongValue((long)c);}
00445 
00449     cMsgPar& operator=(int i)  {return setLongValue((long)i);}
00450 
00454     cMsgPar& operator=(unsigned int i)  {return setLongValue((long)i);}
00455 
00459     cMsgPar& operator=(short i)  {return setLongValue((long)i);}
00460 
00464     cMsgPar& operator=(unsigned short i)  {return setLongValue((long)i);}
00465 
00469     cMsgPar& operator=(long l)  {return setLongValue(l);}
00470 
00474     cMsgPar& operator=(unsigned long l) {return setLongValue((long)l);}
00475 
00479     cMsgPar& operator=(double d)  {return setDoubleValue(d);}
00480 
00484     cMsgPar& operator=(long double d)  {return setDoubleValue((double)d);}
00485 
00489     cMsgPar& operator=(void *ptr)  {return setPointerValue(ptr);}
00490 
00494     cMsgPar& operator=(cOwnedObject *obj)  {return setObjectValue(obj);}
00495 
00499     cMsgPar& operator=(cXMLElement *node) {return setXMLValue(node);}
00500 
00504     operator bool()  {return boolValue();}
00505 
00509     operator const char *()  {return stringValue();}
00510 
00514     operator char()  {return (char)longValue();}
00515 
00519     operator unsigned char() {return (unsigned char)longValue();}
00520 
00524     operator int()  {return (int)longValue();}
00525 
00529     operator unsigned int()  {return (unsigned int)longValue();}
00530 
00534     operator short()  {return (short)longValue();}
00535 
00539     operator unsigned short()  {return (unsigned short)longValue();}
00540 
00544     operator long()  {return longValue();}
00545 
00549     operator unsigned long() {return longValue();}
00550 
00554     operator double()  {return doubleValue();}
00555 
00559     operator long double()  {return doubleValue();}
00560 
00564     operator void *()  {return pointerValue();}
00565 
00569     operator cOwnedObject *()  {return getObjectValue();}
00570 
00574     operator cXMLElement *()  {return xmlValue();}
00576 };
00577 
00578 NAMESPACE_END
00579 
00580 
00581 #endif
00582 
00583 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3