16 #ifndef __OMNETPP_CNEDVALUE_H 17 #define __OMNETPP_CNEDVALUE_H 20 #include "simkerneldefs.h" 21 #include "cexception.h" 28 class cDynamicExpression;
58 enum Type {UNDEF=0, BOOL=
'B', INT=
'L', DOUBLE=
'D', STRING=
'S', XML=
'X', DBL=DOUBLE, STR=STRING} type;
67 static const char *OVERFLOW_MSG;
71 void assertType(
Type)
const {}
73 void assertType(
Type t)
const {
if (type!=t) cannotCastError(t);}
75 [[noreturn]]
void cannotCastError(
Type t)
const;
87 cNedValue(
double d,
const char *unit) {
set(d,unit);}
109 static const char *getTypeName(
Type t);
114 bool isNumeric()
const {
return type==DOUBLE || type==INT;}
119 bool isSet()
const {
return type!=UNDEF;}
124 std::string str()
const;
132 static double convertUnit(
double d,
const char *unit,
const char *targetUnit);
139 static double parseQuantity(
const char *str,
const char *expectedUnit=
nullptr);
151 static double parseQuantity(
const char *str, std::string& outActualUnit);
161 static const char *getPooled(
const char *s);
170 void set(
bool b) {type=BOOL; bl=b;}
177 void set(
intpar_t l,
const char *unit=
nullptr) {type=INT; intv=l; this->unit=unit;}
185 void set(
int l,
const char *unit=
nullptr) {
set((
intpar_t)l, unit);}
192 void set(
double d,
const char *unit=
nullptr) {type=DOUBLE; dbl=d; this->unit=unit;}
212 void setUnit(
const char* unit);
223 void convertTo(
const char *unit);
229 void convertToDouble();
235 void set(
const char *s) {type=STRING; this->s=s?s:
"";}
240 void set(
const std::string& s) {type=STRING; this->s=s;}
250 void set(
const cPar& par);
276 intpar_t intValueInUnit(
const char *targetUnit)
const;
281 double doubleValue()
const;
288 double doubleValueInUnit(
const char *targetUnit)
const;
294 const char *
getUnit()
const {
return (type==DOUBLE || type==INT) ? unit :
nullptr;}
299 const char *
stringValue()
const {assertType(STRING);
return s.c_str();}
403 operator bool()
const {
return boolValue();}
415 operator unsigned char()
const {
return checked_int_cast<
unsigned char>(intValue(), OVERFLOW_MSG);}
427 operator unsigned int()
const {
return checked_int_cast<
unsigned int>(intValue(), OVERFLOW_MSG);}
439 operator unsigned short()
const {
return checked_int_cast<
unsigned short>(intValue(), OVERFLOW_MSG);}
451 operator unsigned long()
const {
return checked_int_cast<
unsigned long>(intValue(), OVERFLOW_MSG);}
463 operator unsigned long long()
const {
return checked_int_cast<
unsigned long long>(intValue(), OVERFLOW_MSG);}
468 operator double()
const {
return doubleValue();}
474 operator long double()
const {
return doubleValue();}
479 operator const char *()
const {
return stringValue();}
484 operator std::string()
const {
return stdstringValue();}
cNedValue & operator=(const cPar &par)
Definition: cnedvalue.h:398
const char * stringValue() const
Definition: cnedvalue.h:299
Type
Definition: cnedvalue.h:58
_OPPDEPRECATED intpar_t longValue() const
Definition: cnedvalue.h:269
cNedValue & operator=(bool b)
Definition: cnedvalue.h:318
cNedValue & operator=(double d)
Definition: cnedvalue.h:373
cNedValue & operator=(const char *s)
Definition: cnedvalue.h:383
cNedValue & operator=(unsigned char c)
Definition: cnedvalue.h:328
Represents an XML element in an XML configuration file.
Definition: cxmlelement.h:73
cNedValue & operator=(long l)
Definition: cnedvalue.h:353
Represents a module or channel parameter.
Definition: cpar.h:68
cXMLElement * xmlValue() const
Definition: cnedvalue.h:309
int64_t intpar_t
Type for NED parameter values that store integers. It is guaranteed to be signed and at least as wide...
Definition: simkerneldefs.h:86
cNedValue & operator=(long double d)
Definition: cnedvalue.h:378
const std::string & stdstringValue() const
Definition: cnedvalue.h:304
cNedValue & operator=(long long l)
Definition: cnedvalue.h:363
Value used during evaluating NED expressions.
Definition: cnedvalue.h:50
void setPreservingUnit(intpar_t l)
Definition: cnedvalue.h:198
void setPreservingUnit(double d)
Definition: cnedvalue.h:204
const char * getUnit() const
Definition: cnedvalue.h:294
cNedValue & operator=(char c)
Definition: cnedvalue.h:323
bool isSet() const
Definition: cnedvalue.h:119
cNedValue & operator=(const std::string &s)
Definition: cnedvalue.h:388
cNedValue & operator=(short i)
Definition: cnedvalue.h:333
A stack-based expression evaluator class, for dynamically created expressions.
Definition: cdynamicexpression.h:36
cNedValue & operator=(unsigned long long l)
Definition: cnedvalue.h:368
bool boolValue() const
Definition: cnedvalue.h:259
Definition: cabstracthistogram.h:21
cNedValue & operator=(unsigned long l)
Definition: cnedvalue.h:358
cNedValue & operator=(unsigned int i)
Definition: cnedvalue.h:348
ToInt checked_int_cast(FromInt x, const char *errmsg=nullptr)
Safe integer cast: it throws an exception if in case of an overflow, i.e. when if the target type can...
Definition: simutil.h:54
cNedValue & operator=(int i)
Definition: cnedvalue.h:343
Type getType() const
Definition: cnedvalue.h:104
cNedValue & operator=(cXMLElement *node)
Definition: cnedvalue.h:393
bool isNumeric() const
Definition: cnedvalue.h:114
cNedValue & operator=(unsigned short i)
Definition: cnedvalue.h:338