00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CPAR_H
00023 #define __CPAR_H
00024
00025 #include "cobject.h"
00026
00027 #define SHORTSTR 27
00028
00029 #define NOPAR NO(cPar)
00030
00031
00032 class cPar;
00033 class cModulePar;
00034
00035
00036 class cStatistic;
00037
00038
00039
00050 struct sXElem
00051 {
00052
00053
00054
00055
00056
00057
00058
00059 char type;
00060 union {
00061 double d;
00062 cPar *p;
00063 MathFuncNoArg f0;
00064 MathFunc1Arg f1;
00065 MathFunc2Args f2;
00066 MathFunc3Args f3;
00067 char op;
00068 };
00069
00074 void operator=(int _i) {type='D'; d=_i; }
00075
00080 void operator=(long _l) {type='D'; d=_l; }
00081
00086 void operator=(double _d) {type='D'; d=_d; }
00087
00095 void operator=(cPar *_p) {type='P'; p=_p; }
00096
00103 void operator=(cPar& _r);
00104
00117 void operator=(MathFuncNoArg _f) {type='0'; f0=_f;}
00118
00131 void operator=(MathFunc1Arg _f) {type='1'; f1=_f;}
00132
00145 void operator=(MathFunc2Args _f) {type='2'; f2=_f;}
00146
00159 void operator=(MathFunc3Args _f) {type='3'; f3=_f;}
00160
00176 void operator=(char _op) {type='@'; op=_op;}
00177 };
00178
00179
00180
00207 class SIM_API cPar : public cObject
00208 {
00209 protected:
00210 static char *possibletypes;
00211 private:
00212 char typechar;
00213 bool inputflag;
00214 bool changedflag;
00215 opp_string promptstr;
00216
00217 union {
00218 struct { bool sht; char *str; } ls;
00219 struct { bool sht; char str[SHORTSTR+1]; } ss;
00220 struct { long val; } lng;
00221 struct { double val; } dbl;
00222 struct { MathFunc f; int argc;
00223 double p1,p2,p3; } func;
00224 struct { cStatistic *res; } dtr;
00225 struct { sXElem *xelem; int n; } expr;
00226 struct { cPar *par; } ind;
00227 struct { void *ptr;
00228 VoidDelFunc delfunc;
00229 VoidDupFunc dupfunc;
00230 size_t itemsize; } ptr;
00231 struct { cObject *obj; } obj;
00232 };
00233
00234 private:
00235
00236 void deleteold();
00237
00238
00239 double evaluate();
00240
00241
00242 double fromstat();
00243
00244
00245 bool setfunction(char *w);
00246
00247 protected:
00250
00256 virtual void beforeChange();
00257
00263 virtual void afterChange();
00265
00266 public:
00269
00273 cPar(const cPar& other);
00274
00279 explicit cPar(const char *name=NULL);
00280
00285 explicit cPar(const char *name, cPar& other);
00286
00290 virtual ~cPar();
00291
00303 cPar& operator=(const cPar& otherpar);
00305
00308
00312 virtual const char *className() const {return "cPar";}
00313
00318 virtual cObject *dup() const {return new cPar(*this);}
00319
00324 virtual void info(char *buf);
00325
00330 virtual const char *inspectorFactoryName() const {return "cParIFC";}
00331
00336 virtual void writeContents(ostream& os);
00337
00343 virtual int netPack();
00344
00350 virtual int netUnpack();
00352
00355
00359 cPar& setBoolValue(bool b);
00360
00364 cPar& setLongValue(long l);
00365
00371 cPar& setStringValue(const char *s);
00372
00376 cPar& setDoubleValue(double d);
00377
00383 cPar& setDoubleValue(cStatistic *res);
00384
00390 cPar& setDoubleValue(sXElem *x, int n);
00391
00396 cPar& setDoubleValue(MathFuncNoArg f);
00397
00403 cPar& setDoubleValue(MathFunc1Arg f, double p1);
00404
00410 cPar& setDoubleValue(MathFunc2Args f, double p1, double p2);
00411
00417 cPar& setDoubleValue(MathFunc3Args f, double p1, double p2, double p3);
00418
00425 cPar& setPointerValue(void *ptr);
00426
00432 cPar& setObjectValue(cObject *obj);
00433
00453 void configPointer( VoidDelFunc delfunc, VoidDupFunc dupfunc, size_t itemsize=0);
00455
00458
00462 bool boolValue();
00463
00469 long longValue();
00470
00474 const char *stringValue();
00475
00481 double doubleValue();
00482
00486 void *pointerValue();
00487
00491 cObject *objectValue();
00493
00496
00504 cPar& setRedirection(cPar *par);
00505
00509 bool isRedirected() const {return typechar=='I';}
00510
00518 cPar *redirection();
00519
00523 void cancelRedirection();
00525
00528
00534 char type() const;
00535
00539 bool isNumeric() const;
00540
00544 const char *prompt() ;
00545
00549 void setPrompt(const char *s);
00550
00554 void setInput(bool ip);
00555
00560 bool isInput() const;
00561
00567 bool changed();
00569
00572
00576 cPar& read();
00577
00582 void convertToConst();
00583
00588 bool equalsTo(cPar *par);
00590
00593
00598 virtual void getAsText(char *buf, int maxlen);
00599
00607 virtual bool setFromText(const char *text, char tp);
00609
00612
00616 cPar& operator=(bool b) {return setBoolValue(b);}
00617
00621 cPar& operator=(const char *s) {return setStringValue(s);}
00622
00626 cPar& operator=(char c) {return setLongValue((long)c);}
00627
00631 cPar& operator=(unsigned char c) {return setLongValue((long)c);}
00632
00636 cPar& operator=(int i) {return setLongValue((long)i);}
00637
00641 cPar& operator=(unsigned int i) {return setLongValue((long)i);}
00642
00646 cPar& operator=(long l) {return setLongValue(l);}
00647
00651 cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00652
00656 cPar& operator=(double d) {return setDoubleValue(d);}
00657
00661 cPar& operator=(long double d) {return setDoubleValue((double)d);}
00662
00666 cPar& operator=(void *ptr) {return setPointerValue(ptr);}
00667
00671 cPar& operator=(cObject *obj) {return setObjectValue(obj);}
00672
00676 operator bool() {return boolValue();}
00677
00681 operator const char *() {return stringValue();}
00682
00686 operator char() {return (char)longValue();}
00687
00691 operator unsigned char() {return (unsigned char)longValue();}
00692
00696 operator int() {return (int)longValue();}
00697
00701 operator unsigned int() {return (unsigned int)longValue();}
00702
00706 operator long() {return longValue();}
00707
00711 operator unsigned long() {return longValue();}
00712
00716 operator double() {return doubleValue();}
00717
00721 operator long double() {return doubleValue();}
00722
00726 operator void *() {return pointerValue();}
00727
00731 operator cObject *() {return objectValue();}
00733
00736
00742 static int cmpbyvalue(cObject *one, cObject *other);
00744 };
00745
00746
00747 inline void sXElem::operator=(cPar& _r) {type='R'; p=(cPar *)_r.dup();}
00748
00749
00750
00759 class SIM_API cModulePar : public cPar
00760 {
00761 friend class cModule;
00762 private:
00763 cModule *omodp;
00764
00765 private:
00766
00767 void _construct();
00768
00769 public:
00772
00776 cModulePar(const cPar& other);
00777
00781 explicit cModulePar(const char *name=NULL);
00782
00786 explicit cModulePar(const char *name, cPar& other);
00787
00791 virtual ~cModulePar();
00792
00797 cModulePar& operator=(const cModulePar& otherpar);
00799
00802
00806 virtual const char *className() const {return "cModulePar";}
00807
00812 virtual cObject *dup() const {return new cPar(*this);}
00813
00818 virtual const char *inspectorFactoryName() const {return "cModuleParIFC";}
00819
00823 virtual const char *fullPath() const;
00824
00829 virtual const char *fullPath(char *buffer, int bufsize) const;
00831
00834
00838 void setOwnerModule(cModule *om) {omodp=om;}
00839
00843 cModule *ownerModule() const {return omodp;}
00845 };
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915 #endif
00916
00917