cpar.h

00001 //==========================================================================
00002 //   CPAR.H  - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //  Author: Andras Varga
00007 //
00008 //==========================================================================
00009 
00010 /*--------------------------------------------------------------*
00011   Copyright (C) 1992-2008 Andras Varga
00012   Copyright (C) 2006-2008 OpenSim Ltd.
00013 
00014   This file is distributed WITHOUT ANY WARRANTY. See the file
00015   `license' for details on this and other legal matters.
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     // private constructor -- only cComponent is allowed to create parameters
00088     cPar() {ownercomponent = evalcontext = NULL; p = NULL;}
00089     // internal, called from cComponent
00090     void init(cComponent *ownercomponent, cParImpl *p);
00091     // internal
00092     void moveto(cPar& other);
00093     // internal: called each time before the value of this object changes.
00094     void beforeChange();
00095     // internal: called each time after the value of this object changes.
00096     void afterChange();
00097 
00098   public:
00099     // internal: applies the default value if there is one
00100     void acceptDefault();
00101     // internal
00102     void setImpl(cParImpl *p);
00103     // internal
00104     cParImpl *impl() const {return p;}
00105     // internal
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 
00347     void read();  //XXX make private, as it no longer evaluates non-volatile parameters!
00355     void finalize(); //XXX name not good! make private!
00356 
00361     void convertToConst();
00362 
00366     std::string str() const;
00367 
00376     void parse(const char *text);
00378 
00381 
00385     cPar& operator=(bool b)  {return setBoolValue(b);}
00386 
00390     cPar& operator=(char c)  {return setLongValue((long)c);}
00391 
00395     cPar& operator=(unsigned char c)  {return setLongValue((long)c);}
00396 
00400     cPar& operator=(int i)  {return setLongValue((long)i);}
00401 
00405     cPar& operator=(unsigned int i)  {return setLongValue((long)i);}
00406 
00410     cPar& operator=(short i)  {return setLongValue((long)i);}
00411 
00415     cPar& operator=(unsigned short i)  {return setLongValue((long)i);}
00416 
00420     cPar& operator=(long l)  {return setLongValue(l);}
00421 
00425     cPar& operator=(unsigned long l) {return setLongValue((long)l);}
00426 
00430     cPar& operator=(double d)  {return setDoubleValue(d);}
00431 
00435     cPar& operator=(long double d)  {return setDoubleValue((double)d);}
00436 
00440     cPar& operator=(const char *s)  {return setStringValue(s);}
00441 
00445     cPar& operator=(const std::string& s)  {return setStringValue(s);}
00446 
00450     cPar& operator=(cXMLElement *node)  {return setXMLValue(node);}
00451 
00455     operator bool() const  {return boolValue();}
00456 
00460     operator char() const  {return (char)longValue();}
00461 
00465     operator unsigned char() const  {return (unsigned char)longValue();}
00466 
00470     operator int() const  {return (int)longValue();}
00471 
00475     operator unsigned int() const  {return (unsigned int)longValue();}
00476 
00480     operator short() const  {return (short)longValue();}
00481 
00485     operator unsigned short() const  {return (unsigned short)longValue();}
00486 
00490     operator long() const  {return longValue();}
00491 
00495     operator unsigned long() const  {return longValue();}
00496 
00500     operator double() const  {return doubleValue();}
00501 
00505     operator long double() const  {return doubleValue();}
00506 
00510     operator const char *() const  {return stringValue();}
00511 
00515     operator std::string() const  {return stdstringValue();}
00516 
00521     operator cXMLElement *() const  {return xmlValue();}
00523 };
00524 
00525 NAMESPACE_END
00526 
00527 
00528 #endif
00529 
00530 
00531 
00532 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3