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
00035
00036
00037
00043 class cExpression
00044 {
00045 public:
00046 virtual ~cExpression() {}
00047 virtual void getAsText(char *buf, int maxlen) = 0;
00048 virtual bool parseText(const char *text) = 0;
00049 virtual cExpression *dup() = 0;
00050 };
00051
00077 class cDoubleExpression : public cExpression
00078 {
00079 public:
00080 virtual void getAsText(char *buf, int maxlen);
00081 virtual bool parseText(const char *text);
00082 virtual double evaluate() = 0;
00083 };
00084
00085
00086
00114 class SIM_API cPar : public cObject
00115 {
00116 public:
00124 struct ExprElem
00125 {
00126
00127
00128
00129
00130
00131
00132
00133 char type;
00134 union {
00135 double d;
00136 cPar *p;
00137 MathFuncNoArg f0;
00138 MathFunc1Arg f1;
00139 MathFunc2Args f2;
00140 MathFunc3Args f3;
00141 MathFunc4Args f4;
00142 char op;
00143 };
00144
00149 void operator=(int _i) {type='D'; d=_i; }
00150
00155 void operator=(long _l) {type='D'; d=_l; }
00156
00161 void operator=(double _d) {type='D'; d=_d; }
00162
00170 void operator=(cPar *_p) {type='P'; p=_p; }
00171
00178 void operator=(cPar& _r);
00179
00189 void operator=(MathFuncNoArg _f) {type='0'; f0=_f;}
00190
00202 void operator=(MathFunc1Arg _f) {type='1'; f1=_f;}
00203
00216 void operator=(MathFunc2Args _f) {type='2'; f2=_f;}
00217
00230 void operator=(MathFunc3Args _f) {type='3'; f3=_f;}
00231
00244 void operator=(MathFunc4Args _f) {type='4'; f4=_f;}
00245
00261 void operator=(char _op) {type='@'; op=_op;}
00262 };
00263
00264 protected:
00265 static char *possibletypes;
00266 private:
00267 char typechar;
00268 bool inputflag;
00269 bool changedflag;
00270 opp_string promptstr;
00271
00272 union {
00273 struct { bool sht; char *str; } ls;
00274 struct { bool sht; char str[SHORTSTR+1]; } ss;
00275 struct { long val; } lng;
00276 struct { double val; } dbl;
00277 struct { MathFunc f; int argc;
00278 double p1,p2,p3,p4; } func;
00279 struct { cStatistic *res; } dtr;
00280 struct { cDoubleExpression *expr; } cexpr;
00281 struct { ExprElem *xelem; int n; } expr;
00282 struct { cPar *par; } ind;
00283 struct { void *ptr;
00284 VoidDelFunc delfunc;
00285 VoidDupFunc dupfunc;
00286 size_t itemsize; } ptr;
00287 struct { cObject *obj; } obj;
00288 };
00289
00290 private:
00291
00292 void deleteold();
00293
00294
00295 double evaluate();
00296
00297
00298 double fromstat();
00299
00300
00301 bool setfunction(char *w);
00302
00303 protected:
00306
00312 virtual void beforeChange();
00313
00319 virtual void afterChange();
00321
00322 public:
00325
00329 cPar(const cPar& other);
00330
00335 explicit cPar(const char *name=NULL);
00336
00341 explicit cPar(const char *name, cPar& other);
00342
00346 virtual ~cPar();
00347
00359 cPar& operator=(const cPar& otherpar);
00361
00364
00369 virtual cObject *dup() const {return new cPar(*this);}
00370
00375 virtual void info(char *buf);
00376
00381 virtual void writeContents(ostream& os);
00382
00386 virtual void forEach(ForeachFunc f);
00387
00393 virtual int netPack();
00394
00400 virtual int netUnpack();
00402
00405
00409 cPar& setBoolValue(bool b);
00410
00414 cPar& setLongValue(long l);
00415
00421 cPar& setStringValue(const char *s);
00422
00426 cPar& setDoubleValue(double d);
00427
00433 cPar& setDoubleValue(cStatistic *res);
00434
00440 cPar& setDoubleValue(ExprElem *x, int n);
00441
00449 cPar& setDoubleValue(cDoubleExpression *expr);
00450
00455 cPar& setDoubleValue(MathFuncNoArg f);
00456
00462 cPar& setDoubleValue(MathFunc1Arg f, double p1);
00463
00469 cPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
00470
00476 cPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
00477
00483 cPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
00484
00491 cPar& setPointerValue(void *ptr);
00492
00498 cPar& setObjectValue(cObject *obj);
00499
00519 void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
00521
00524
00528 bool boolValue();
00529
00535 long longValue();
00536
00540 const char *stringValue();
00541
00547 double doubleValue();
00548
00552 void *pointerValue();
00553
00557 cObject *objectValue();
00559
00562
00570 cPar& setRedirection(cPar *par);
00571
00575 bool isRedirected() const {return typechar=='I';}
00576
00584 cPar *redirection();
00585
00589 void cancelRedirection();
00591
00594
00600 char type() const;
00601
00605 bool isNumeric() const;
00606
00610 const char *prompt() ;
00611
00615 void setPrompt(const char *s);
00616
00620 void setInput(bool ip);
00621
00626 bool isInput() const;
00627
00633 bool changed();
00635
00638
00642 cPar& read();
00643
00648 void convertToConst();
00649
00654 bool equalsTo(cPar *par);
00656
00659
00664 virtual void getAsText(char *buf, int maxlen);
00665
00673 virtual bool setFromText(const char *text, char tp);
00675
00678
00682 cPar& operator=(bool b) {return setBoolValue(b);}
00683
00687 cPar& operator=(const char *s) {return setStringValue(s);}
00688
00692 cPar& operator=(char c) {return setLongValue((long)c);}
00693
00697 cPar& operator=(unsigned char c) {return setLongValue((long)c);}
00698
00702 cPar& operator=(int i) {return setLongValue((long)i);}
00703
00707 cPar& operator=(unsigned int i) {return setLongValue((long)i);}
00708
00712 cPar& operator=(long l) {return setLongValue(l);}
00713
00717 cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00718
00722 cPar& operator=(double d) {return setDoubleValue(d);}
00723
00727 cPar& operator=(long double d) {return setDoubleValue((double)d);}
00728
00732 cPar& operator=(void *ptr) {return setPointerValue(ptr);}
00733
00737 cPar& operator=(cObject *obj) {return setObjectValue(obj);}
00738
00742 operator bool() {return boolValue();}
00743
00747 operator const char *() {return stringValue();}
00748
00752 operator char() {return (char)longValue();}
00753
00757 operator unsigned char() {return (unsigned char)longValue();}
00758
00762 operator int() {return (int)longValue();}
00763
00767 operator unsigned int() {return (unsigned int)longValue();}
00768
00772 operator long() {return longValue();}
00773
00777 operator unsigned long() {return longValue();}
00778
00782 operator double() {return doubleValue();}
00783
00787 operator long double() {return doubleValue();}
00788
00792 operator void *() {return pointerValue();}
00793
00797 operator cObject *() {return objectValue();}
00799
00802
00808 static int cmpbyvalue(cObject *one, cObject *other);
00810 };
00811
00812
00813 inline void cPar::ExprElem::operator=(cPar& _r) {type='R'; p=(cPar *)_r.dup();}
00814
00815
00816
00825 class SIM_API cModulePar : public cPar
00826 {
00827 friend class cModule;
00828 private:
00829 cModule *omodp;
00830
00831 private:
00832
00833 void _construct();
00834
00835 public:
00838
00842 cModulePar(const cPar& other);
00843
00847 explicit cModulePar(const char *name=NULL);
00848
00852 explicit cModulePar(const char *name, cPar& other);
00853
00857 virtual ~cModulePar();
00858
00863 cModulePar& operator=(const cModulePar& otherpar);
00865
00868
00873 virtual cObject *dup() const {return new cPar(*this);}
00874
00878 virtual const char *fullPath() const;
00879
00884 virtual const char *fullPath(char *buffer, int bufsize) const;
00886
00889
00893 void setOwnerModule(cModule *om) {omodp=om;}
00894
00898 cModule *ownerModule() const {return omodp;}
00900 };
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970 #endif
00971
00972