00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __CPAR_H
00019 #define __CPAR_H
00020
00021 #include "cownedobject.h"
00022 #include "cexpression.h"
00023 #include "cexception.h"
00024
00025 NAMESPACE_BEGIN
00026
00027 class cParImpl;
00028 class cExpression;
00029 class cXMLElement;
00030 class cProperties;
00031 class cComponent;
00032
00069 class SIM_API cPar : public cObject
00070 {
00071 friend class cComponent;
00072 public:
00073 enum Type {
00074 BOOL = 'B',
00075 DOUBLE = 'D',
00076 LONG = 'L',
00077 STRING = 'S',
00078 XML = 'X'
00079 };
00080
00081 private:
00082 cComponent *ownercomponent;
00083 cParImpl *p;
00084 cComponent *evalcontext;
00085
00086 private:
00087
00088 cPar() {ownercomponent = evalcontext = NULL; p = NULL;}
00089
00090 void init(cComponent *ownercomponent, cParImpl *p);
00091
00092 void moveto(cPar& other);
00093
00094 void beforeChange();
00095
00096 void afterChange();
00097
00098 public:
00099
00100 void acceptDefault();
00101
00102 void setImpl(cParImpl *p);
00103
00104 cParImpl *impl() const {return p;}
00105
00106 cParImpl *copyIfShared();
00107
00108 public:
00112 virtual ~cPar();
00113
00117 virtual const char *getName() const;
00118
00123 virtual std::string info() const;
00124
00128 virtual std::string detailedInfo() const;
00129
00135 virtual cObject *getOwner() const;
00136
00140 void operator=(const cPar& other);
00142
00148 Type getType() const;
00149
00153 static const char *getTypeName(Type t);
00154
00158 bool isNumeric() const;
00159
00164 bool isVolatile() const;
00165
00171 bool isExpression() const;
00172
00178 bool isShared() const;
00179
00185 bool isSet() const;
00186
00192 bool containsValue() const;
00193
00198 cProperties *getProperties() const;
00200
00203
00207 cPar& setBoolValue(bool b);
00208
00212 cPar& setLongValue(long l);
00213
00217 cPar& setDoubleValue(double d);
00218
00224 cPar& setStringValue(const char *s);
00225
00229 cPar& setStringValue(const std::string& s) {setStringValue(s.c_str()); return *this;}
00230
00234 cPar& setXMLValue(cXMLElement *node);
00235
00250 cPar& setExpression(cExpression *e, cComponent *evalcontext=NULL);
00251
00258 void setEvaluationContext(cComponent *ctx) {evalcontext = ctx;}
00259
00261
00264
00268 bool boolValue() const;
00269
00273 long longValue() const;
00274
00278 double doubleValue() const;
00279
00286 const char *getUnit() const;
00287
00296 const char *stringValue() const;
00297
00301 std::string stdstringValue() const;
00302
00317 cXMLElement *xmlValue() const;
00318
00322 cExpression *getExpression() const;
00323
00334 cComponent *getEvaluationContext() const {return evalcontext;}
00336
00339
00353 void read();
00354
00359 void convertToConst();
00360
00364 std::string str() const;
00365
00374 void parse(const char *text);
00376
00379
00383 cPar& operator=(bool b) {return setBoolValue(b);}
00384
00388 cPar& operator=(char c) {return setLongValue((long)c);}
00389
00393 cPar& operator=(unsigned char c) {return setLongValue((long)c);}
00394
00398 cPar& operator=(int i) {return setLongValue((long)i);}
00399
00403 cPar& operator=(unsigned int i) {return setLongValue((long)i);}
00404
00408 cPar& operator=(short i) {return setLongValue((long)i);}
00409
00413 cPar& operator=(unsigned short i) {return setLongValue((long)i);}
00414
00418 cPar& operator=(long l) {return setLongValue(l);}
00419
00423 cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00424
00428 cPar& operator=(double d) {return setDoubleValue(d);}
00429
00433 cPar& operator=(long double d) {return setDoubleValue((double)d);}
00434
00438 cPar& operator=(const char *s) {return setStringValue(s);}
00439
00443 cPar& operator=(const std::string& s) {return setStringValue(s);}
00444
00448 cPar& operator=(cXMLElement *node) {return setXMLValue(node);}
00449
00453 operator bool() const {return boolValue();}
00454
00458 operator char() const {return (char)longValue();}
00459
00463 operator unsigned char() const {return (unsigned char)longValue();}
00464
00468 operator int() const {return (int)longValue();}
00469
00473 operator unsigned int() const {return (unsigned int)longValue();}
00474
00478 operator short() const {return (short)longValue();}
00479
00483 operator unsigned short() const {return (unsigned short)longValue();}
00484
00488 operator long() const {return longValue();}
00489
00493 operator unsigned long() const {return longValue();}
00494
00498 operator double() const {return doubleValue();}
00499
00503 operator long double() const {return doubleValue();}
00504
00508 operator const char *() const {return stringValue();}
00509
00513 operator std::string() const {return stdstringValue();}
00514
00519 operator cXMLElement *() const {return xmlValue();}
00521 };
00522
00523 NAMESPACE_END
00524
00525
00526 #endif
00527
00528
00529
00530