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
00154 void operator=(long _l) {type='D'; d=_l; }
00155
00160 void operator=(double _d) {type='D'; d=_d; }
00161
00169 void operator=(cPar *_p) {type='P'; p=_p; }
00170
00177 void operator=(cPar& _r);
00178
00188 void operator=(MathFuncNoArg _f) {type='0'; f0=_f;}
00189
00201 void operator=(MathFunc1Arg _f) {type='1'; f1=_f;}
00202
00215 void operator=(MathFunc2Args _f) {type='2'; f2=_f;}
00216
00229 void operator=(MathFunc3Args _f) {type='3'; f3=_f;}
00230
00243 void operator=(MathFunc4Args _f) {type='4'; f4=_f;}
00244
00258 void operator=(char _op) {type='@'; op=_op;}
00259 };
00260
00261 protected:
00262 static char *possibletypes;
00263 private:
00264 char typechar;
00265 bool inputflag;
00266 bool changedflag;
00267 bool tkownership;
00268 opp_string promptstr;
00269
00270 union {
00271 struct { bool sht; char *str; } ls;
00272 struct { bool sht; char str[SHORTSTR+1]; } ss;
00273 struct { long val; } lng;
00274 struct { double val; } dbl;
00275 struct { MathFunc f; int argc;
00276 double p1,p2,p3,p4; } func;
00277 struct { cStatistic *res; } dtr;
00278 struct { cDoubleExpression *expr; } cexpr;
00279 struct { ExprElem *xelem; int n; } expr;
00280 struct { cPar *par; } ind;
00281 struct { void *ptr;
00282 VoidDelFunc delfunc;
00283 VoidDupFunc dupfunc;
00284 size_t itemsize; } ptr;
00285 struct { cObject *obj; } obj;
00286 struct { cXMLElement *node; } xmlp;
00287 };
00288
00289 private:
00290
00291 void deleteold();
00292
00293
00294 double evaluate();
00295
00296
00297 double fromstat();
00298
00299
00300 bool setfunction(char *w);
00301
00302 protected:
00305
00311 virtual void beforeChange();
00312
00318 virtual void afterChange();
00320
00321 public:
00324
00328 cPar(const cPar& other);
00329
00334 explicit cPar(const char *name=NULL);
00335
00340 explicit cPar(const char *name, cPar& other);
00341
00345 virtual ~cPar();
00346
00358 cPar& operator=(const cPar& otherpar);
00360
00363
00368 virtual cObject *dup() const {return new cPar(*this);}
00369
00374 virtual std::string info() const;
00375
00380 virtual void writeContents(std::ostream& os);
00381
00386 virtual void forEachChild(cVisitor *v);
00387
00393 virtual void netPack(cCommBuffer *buffer);
00394
00400 virtual void netUnpack(cCommBuffer *buffer);
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
00455 cPar& setDoubleValue(ExprElem *x, int n);
00456
00465 cPar& setDoubleValue(cDoubleExpression *expr);
00466
00471 cPar& setDoubleValue(MathFuncNoArg f);
00472
00478 cPar& setDoubleValue(MathFunc1Arg f, double p1);
00479
00485 cPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
00486
00492 cPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
00493
00499 cPar& setDoubleValue(MathFunc4Args f, double p1, double p2, double p3, double p4);
00500
00507 cPar& setPointerValue(void *ptr);
00508
00513 cPar& setObjectValue(cObject *obj);
00514
00518 cPar& setXMLValue(cXMLElement *node);
00519
00539 void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
00540
00546 void takeOwnership(bool tk) {tkownership=tk;}
00547
00551 bool takeOwnership() const {return tkownership;}
00553
00556
00560 bool boolValue();
00561
00567 long longValue();
00568
00572 const char *stringValue();
00573
00579 double doubleValue();
00580
00584 void *pointerValue();
00585
00589 cObject *objectValue();
00590
00594 cXMLElement *xmlValue();
00596
00599
00607 cPar& setRedirection(cPar *par);
00608
00612 bool isRedirected() const {return typechar=='I';}
00613
00621 cPar *redirection();
00622
00626 void cancelRedirection();
00628
00631
00637 char type() const;
00638
00642 bool isNumeric() const;
00643
00647 const char *prompt() ;
00648
00652 void setPrompt(const char *s);
00653
00657 void setInput(bool ip);
00658
00663 bool isInput() const;
00664
00670 bool changed();
00672
00675
00679 cPar& read();
00680
00685 void convertToConst();
00686
00691 bool equalsTo(cPar *par);
00693
00696
00701 virtual std::string getAsText() const;
00702
00710 virtual bool setFromText(const char *text, char tp);
00712
00715
00719 cPar& operator=(bool b) {return setBoolValue(b);}
00720
00724 cPar& operator=(const char *s) {return setStringValue(s);}
00725
00729 cPar& operator=(char c) {return setLongValue((long)c);}
00730
00734 cPar& operator=(unsigned char c) {return setLongValue((long)c);}
00735
00739 cPar& operator=(int i) {return setLongValue((long)i);}
00740
00744 cPar& operator=(unsigned int i) {return setLongValue((long)i);}
00745
00749 cPar& operator=(long l) {return setLongValue(l);}
00750
00754 cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00755
00759 cPar& operator=(double d) {return setDoubleValue(d);}
00760
00764 cPar& operator=(long double d) {return setDoubleValue((double)d);}
00765
00769 cPar& operator=(void *ptr) {return setPointerValue(ptr);}
00770
00774 cPar& operator=(cObject *obj) {return setObjectValue(obj);}
00775
00779 cPar& operator=(cXMLElement *node) {return setXMLValue(node);}
00780
00784 operator bool() {return boolValue();}
00785
00789 operator const char *() {return stringValue();}
00790
00794 operator char() {return (char)longValue();}
00795
00799 operator unsigned char() {return (unsigned char)longValue();}
00800
00804 operator int() {return (int)longValue();}
00805
00809 operator unsigned int() {return (unsigned int)longValue();}
00810
00814 operator long() {return longValue();}
00815
00819 operator unsigned long() {return longValue();}
00820
00824 operator double() {return doubleValue();}
00825
00829 operator long double() {return doubleValue();}
00830
00834 operator void *() {return pointerValue();}
00835
00839 operator cObject *() {return objectValue();}
00840
00844 operator cXMLElement *() {return xmlValue();}
00845
00847
00850
00856 static int cmpbyvalue(cObject *one, cObject *other);
00858 };
00859
00860
00861 inline void cPar::ExprElem::operator=(cPar& _r) {type='R'; p=(cPar *)_r.dup();}
00862
00863
00864
00873 class SIM_API cModulePar : public cPar
00874 {
00875 friend class cModule;
00876 private:
00877 cModule *omodp;
00878
00879 private:
00880
00881 void _construct();
00882
00883 public:
00886
00890 cModulePar(const cPar& other);
00891
00895 explicit cModulePar(const char *name=NULL);
00896
00900 explicit cModulePar(const char *name, cPar& other);
00901
00905 virtual ~cModulePar();
00906
00911 cModulePar& operator=(const cModulePar& otherpar);
00913
00916
00921 virtual cObject *dup() const {return new cPar(*this);}
00922
00926 virtual std::string fullPath() const;
00927
00932 virtual const char *fullPath(char *buffer, int bufsize) const;
00934
00937
00941 void setOwnerModule(cModule *om) {omodp=om;}
00942
00946 cModule *ownerModule() const {return omodp;}
00948 };
00949
00950 inline std::ostream& operator<< (std::ostream& os, const cPar& o) {
00951 return os << o.getAsText();
00952 }
00953
00954 inline std::ostream& operator<< (std::ostream& os, cPar& o) {
00955 return os << o.getAsText();
00956 }
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
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 #endif
01027
01028