00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CPAR_H
00021 #define __CPAR_H
00022
00023 #include "cobject.h"
00024
00025 #define SHORTSTR 27
00026
00027
00028
00029 class cPar;
00030 class cModulePar;
00031
00032
00033 class cStatistic;
00034 class cXMLElement;
00035
00036
00037
00038
00044 class SIM_API cExpression
00045 {
00046 public:
00047 virtual ~cExpression() {}
00048 virtual std::string getAsText() = 0;
00049 virtual bool parseText(const char *text) = 0;
00050 virtual cExpression *dup() = 0;
00051 };
00052
00078 class SIM_API cDoubleExpression : public cExpression
00079 {
00080 public:
00081 virtual std::string getAsText();
00082 virtual bool parseText(const char *text);
00083 virtual double evaluate() = 0;
00084 };
00085
00086
00087
00116 class SIM_API cPar : public cObject
00117 {
00118 public:
00123 struct ExprElem
00124 {
00125
00126
00127
00128
00129
00130
00131
00132 char type;
00133 union {
00134 double d;
00135 cPar *p;
00136 MathFuncNoArg f0;
00137 MathFunc1Arg f1;
00138 MathFunc2Args f2;
00139 MathFunc3Args f3;
00140 MathFunc4Args f4;
00141 char op;
00142 };
00143
00148 void operator=(int _i) {type='D'; d=_i; }
00149
00150
00155 void operator=(short _i) {type='D'; d=_i; }
00156
00161 void operator=(long _l) {type='D'; d=_l; }
00162
00167 void operator=(double _d) {type='D'; d=_d; }
00168
00176 void operator=(cPar *_p) {type='P'; p=_p; }
00177
00184 void operator=(cPar& _r);
00185
00195 void operator=(MathFuncNoArg _f) {type='0'; f0=_f;}
00196
00208 void operator=(MathFunc1Arg _f) {type='1'; f1=_f;}
00209
00222 void operator=(MathFunc2Args _f) {type='2'; f2=_f;}
00223
00236 void operator=(MathFunc3Args _f) {type='3'; f3=_f;}
00237
00250 void operator=(MathFunc4Args _f) {type='4'; f4=_f;}
00251
00265 void operator=(char _op) {type='@'; op=_op;}
00266 };
00267
00268 protected:
00269 static char *possibletypes;
00270 private:
00271 char typechar;
00272 bool inputflag;
00273 bool changedflag;
00274 bool tkownership;
00275 opp_string promptstr;
00276
00277 union {
00278 struct { bool sht; char *str; } ls;
00279 struct { bool sht; char str[SHORTSTR+1]; } ss;
00280 struct { long val; } lng;
00281 struct { double val; } dbl;
00282 struct { MathFunc f; int argc;
00283 double p1,p2,p3,p4; } func;
00284 struct { cStatistic *res; } dtr;
00285 struct { cDoubleExpression *expr; } cexpr;
00286 struct { ExprElem *xelem; int n; } expr;
00287 struct { cPar *par; } ind;
00288 struct { void *ptr;
00289 VoidDelFunc delfunc;
00290 VoidDupFunc dupfunc;
00291 size_t itemsize; } ptr;
00292 struct { cObject *obj; } obj;
00293 struct { cXMLElement *node; } xmlp;
00294 };
00295
00296 private:
00297
00298 void deleteold();
00299
00300
00301 double evaluate();
00302
00303
00304 double fromstat();
00305
00306
00307 bool setfunction(char *w);
00308
00309 protected:
00312
00318 virtual void beforeChange();
00319
00325 virtual void afterChange();
00327
00328 public:
00331
00335 cPar(const cPar& other);
00336
00341 explicit cPar(const char *name=NULL);
00342
00347 explicit cPar(const char *name, cPar& other);
00348
00352 virtual ~cPar();
00353
00365 cPar& operator=(const cPar& otherpar);
00367
00370
00375 virtual cPolymorphic *dup() const {return new cPar(*this);}
00376
00381 virtual std::string info() const;
00382
00387 virtual void writeContents(std::ostream& os);
00388
00393 virtual void forEachChild(cVisitor *v);
00394
00400 virtual void netPack(cCommBuffer *buffer);
00401
00407 virtual void netUnpack(cCommBuffer *buffer);
00409
00412
00416 cPar& setBoolValue(bool b);
00417
00421 cPar& setLongValue(long l);
00422
00428 cPar& setStringValue(const char *s);
00429
00433 cPar& setDoubleValue(double d);
00434
00440 cPar& setDoubleValue(cStatistic *res);
00441
00462 cPar& setDoubleValue(ExprElem *x, int n);
00463
00472 cPar& setDoubleValue(cDoubleExpression *expr);
00473
00478 cPar& setDoubleValue(MathFuncNoArg f);
00479
00485 cPar& setDoubleValue(MathFunc1Arg f, double p1);
00486
00492 cPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
00493
00499 cPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
00500
00506 cPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
00507
00514 cPar& setPointerValue(void *ptr);
00515
00520 cPar& setObjectValue(cObject *obj);
00521
00525 cPar& setXMLValue(cXMLElement *node);
00526
00546 void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
00547
00553 void takeOwnership(bool tk) {tkownership=tk;}
00554
00558 bool takeOwnership() const {return tkownership;}
00560
00563
00567 bool boolValue();
00568
00574 long longValue();
00575
00579 const char *stringValue();
00580
00586 double doubleValue();
00587
00591 void *pointerValue();
00592
00596 cObject *objectValue();
00597
00601 cXMLElement *xmlValue();
00603
00606
00614 cPar& setRedirection(cPar *par);
00615
00619 bool isRedirected() const {return typechar=='I';}
00620
00628 cPar *redirection();
00629
00633 void cancelRedirection();
00635
00638
00644 char type() const;
00645
00649 bool isNumeric() const;
00650
00656 bool isConstant() const;
00657
00661 const char *prompt() ;
00662
00666 void setPrompt(const char *s);
00667
00671 void setInput(bool ip);
00672
00677 bool isInput() const;
00678
00684 bool changed();
00686
00689
00693 cPar& read();
00694
00699 void convertToConst();
00700
00705 bool equalsTo(cPar *par);
00707
00710
00714 virtual std::string getAsText() const;
00715
00723 virtual bool setFromText(const char *text, char type='?');
00725
00728
00732 cPar& operator=(bool b) {return setBoolValue(b);}
00733
00737 cPar& operator=(const char *s) {return setStringValue(s);}
00738
00742 cPar& operator=(char c) {return setLongValue((long)c);}
00743
00747 cPar& operator=(unsigned char c) {return setLongValue((long)c);}
00748
00752 cPar& operator=(int i) {return setLongValue((long)i);}
00753
00757 cPar& operator=(unsigned int i) {return setLongValue((long)i);}
00758
00762 cPar& operator=(short i) {return setLongValue((long)i);}
00763
00767 cPar& operator=(unsigned short i) {return setLongValue((long)i);}
00768
00772 cPar& operator=(long l) {return setLongValue(l);}
00773
00777 cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00778
00782 cPar& operator=(double d) {return setDoubleValue(d);}
00783
00787 cPar& operator=(long double d) {return setDoubleValue((double)d);}
00788
00792 cPar& operator=(void *ptr) {return setPointerValue(ptr);}
00793
00797 cPar& operator=(cObject *obj) {return setObjectValue(obj);}
00798
00802 cPar& operator=(cXMLElement *node) {return setXMLValue(node);}
00803
00807 operator bool() {return boolValue();}
00808
00812 operator const char *() {return stringValue();}
00813
00817 operator char() {return (char)longValue();}
00818
00822 operator unsigned char() {return (unsigned char)longValue();}
00823
00827 operator int() {return (int)longValue();}
00828
00832 operator unsigned int() {return (unsigned int)longValue();}
00833
00837 operator short() {return (short)longValue();}
00838
00842 operator unsigned short() {return (unsigned short)longValue();}
00843
00847 operator long() {return longValue();}
00848
00852 operator unsigned long() {return longValue();}
00853
00857 operator double() {return doubleValue();}
00858
00862 operator long double() {return doubleValue();}
00863
00867 operator void *() {return pointerValue();}
00868
00872 operator cObject *() {return objectValue();}
00873
00877 operator cXMLElement *() {return xmlValue();}
00878
00880
00883
00889 static int cmpbyvalue(cObject *one, cObject *other);
00891 };
00892
00893
00894 inline void cPar::ExprElem::operator=(cPar& _r) {type='R'; p=(cPar *)_r.dup();}
00895
00896
00897
00906 class SIM_API cModulePar : public cPar
00907 {
00908 friend class cModule;
00909 private:
00910 cModule *omodp;
00911
00912 private:
00913
00914 void _construct();
00915
00916 public:
00919
00923 cModulePar(const cPar& other);
00924
00928 explicit cModulePar(const char *name=NULL);
00929
00933 explicit cModulePar(const char *name, cPar& other);
00934
00938 virtual ~cModulePar();
00939
00944 cModulePar& operator=(const cModulePar& otherpar);
00946
00949
00954 virtual cPolymorphic *dup() const {return new cPar(*this);}
00955
00959 virtual std::string fullPath() const;
00960
00965 virtual const char *fullPath(char *buffer, int bufsize) const;
00967
00973 virtual void afterChange();
00975
00978
00982 void setOwnerModule(cModule *om) {omodp=om;}
00983
00987 cModule *ownerModule() const {return omodp;}
00989 };
00990
00991 inline std::ostream& operator<< (std::ostream& os, const cPar& o) {
00992 return os << o.getAsText();
00993 }
00994
00995 inline std::ostream& operator<< (std::ostream& os, cPar& o) {
00996 return os << o.getAsText();
00997 }
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067 #endif
01068
01069