OMNeT++ Simulation Library  5.6.1
cNedValue Class Reference

#include <cnedvalue.h>

Description

Value used during evaluating NED expressions.

See notes below.

Measurement unit strings:

For performance reasons, the functions that store a measurement unit will only store the const char * pointer and not copy the string itself. Consequently, the passed unit pointers must stay valid at least during the lifetime of the cNedValue object, or even longer if the same pointer propagates to other cNedValue objects. It is recommended that you only pass pointers that stay valid during the entire simulation. It is safe to use: (1) string constants from the code; (2) units strings from other cNedValues; and (3) stringpooled strings, e.g. from the getPooled() method or from cStringPool.

See also
cDynamicExpression, cNedFunction, Define_NED_Function()

Public Types

enum  Type
 

Public Member Functions

void operator= (const cNedValue &other)
 
Constructors
 cNedValue ()
 
 cNedValue (bool b)
 
 cNedValue (int l)
 
 cNedValue (int l, const char *unit)
 
 cNedValue (intpar_t l)
 
 cNedValue (intpar_t l, const char *unit)
 
 cNedValue (double d)
 
 cNedValue (double d, const char *unit)
 
 cNedValue (const char *s)
 
 cNedValue (const std::string &s)
 
 cNedValue (cXMLElement *x)
 
 cNedValue (const cPar &par)
 
Setter functions. Note that overloaded assignment operators also exist.
void set (bool b)
 
void set (intpar_t l, const char *unit=nullptr)
 
void set (int l, const char *unit=nullptr)
 
void set (double d, const char *unit=nullptr)
 
void setPreservingUnit (intpar_t l)
 
void setPreservingUnit (double d)
 
void setUnit (const char *unit)
 
void convertTo (const char *unit)
 
void convertToDouble ()
 
void set (const char *s)
 
void set (const std::string &s)
 
void set (cXMLElement *x)
 
void set (const cPar &par)
 
Getter functions. Note that overloaded conversion operators also exist.
bool boolValue () const
 
intpar_t intValue () const
 
_OPPDEPRECATED intpar_t longValue () const
 
intpar_t intValueInUnit (const char *targetUnit) const
 
double doubleValue () const
 
double doubleValueInUnit (const char *targetUnit) const
 
const char * getUnit () const
 
const char * stringValue () const
 
const std::string & stdstringValue () const
 
cXMLElementxmlValue () const
 
Overloaded assignment and conversion operators.
cNedValueoperator= (bool b)
 
cNedValueoperator= (char c)
 
cNedValueoperator= (unsigned char c)
 
cNedValueoperator= (short i)
 
cNedValueoperator= (unsigned short i)
 
cNedValueoperator= (int i)
 
cNedValueoperator= (unsigned int i)
 
cNedValueoperator= (long l)
 
cNedValueoperator= (unsigned long l)
 
cNedValueoperator= (long long l)
 
cNedValueoperator= (unsigned long long l)
 
cNedValueoperator= (double d)
 
cNedValueoperator= (long double d)
 
cNedValueoperator= (const char *s)
 
cNedValueoperator= (const std::string &s)
 
cNedValueoperator= (cXMLElement *node)
 
cNedValueoperator= (const cPar &par)
 
 operator bool () const
 
 operator char () const
 
 operator unsigned char () const
 
 operator int () const
 
 operator unsigned int () const
 
 operator short () const
 
 operator unsigned short () const
 
 operator long () const
 
 operator unsigned long () const
 
 operator long long () const
 
 operator unsigned long long () const
 
 operator double () const
 
 operator long double () const
 
 operator const char * () const
 
 operator std::string () const
 
 operator cXMLElement * () const
 

Type, unit conversion and misc.

Type getType () const
 
bool isNumeric () const
 
bool isSet () const
 
std::string str () const
 
static const char * getTypeName (Type t)
 
static double convertUnit (double d, const char *unit, const char *targetUnit)
 
static double parseQuantity (const char *str, const char *expectedUnit=nullptr)
 
static double parseQuantity (const char *str, std::string &outActualUnit)
 
static const char * getPooled (const char *s)
 

Member Enumeration Documentation

◆ Type

enum Type

Type of the value stored in a cNedValue object.

Member Function Documentation

◆ operator=() [1/18]

void operator= ( const cNedValue other)

Assignment

◆ getType()

Type getType ( ) const
inline

Returns the value type.

◆ getTypeName()

static const char* getTypeName ( Type  t)
static

Returns the given type as a string.

◆ isNumeric()

bool isNumeric ( ) const
inline

Returns true if the stored value is of a numeric type.

◆ isSet()

bool isSet ( ) const
inline

Returns true if the value is not empty, i.e. type is not UNDEF.

◆ str()

std::string str ( ) const

Returns the value in text form.

◆ convertUnit()

static double convertUnit ( double  d,
const char *  unit,
const char *  targetUnit 
)
static

Convert the given number into the target unit (e.g. milliwatt to watt). Throws an exception if conversion is not possible (unknown/unrelated units).

See also
convertTo(), doubleValueInUnit(), setUnit()

◆ parseQuantity() [1/2]

static double parseQuantity ( const char *  str,
const char *  expectedUnit = nullptr 
)
static

Invokes parseQuantity(), and converts the result into the given unit. If conversion is not possible (unrelated or unknown units), and error is thrown.

◆ parseQuantity() [2/2]

static double parseQuantity ( const char *  str,
std::string &  outActualUnit 
)
static

Converts a quantity given as string to a double, and returns it, together with the unit it was given in. If there are several numbers and units (see syntax), everything is converted into the last unit.

Syntax: <number> | (<number> <unit>)+

If there is a syntax error, or if unit mismatch is found (i.e. distance is given instead of time), the method throws an exception.

◆ getPooled()

static const char* getPooled ( const char *  s)
static

Returns a copy of the string that is guaranteed to stay valid until the program exits. Multiple calls with identical strings as parameter will return the same copy. Useful for getting measurement unit strings suitable for cNedValue; see related class comment.

See also
cStringPool, setUnit(), convertTo()

◆ set() [1/8]

void set ( bool  b)
inline

Sets the value to the given bool value.

◆ set() [2/8]

void set ( intpar_t  l,
const char *  unit = nullptr 
)
inline

Sets the value to the given integer value and measurement unit (optional). The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment).

◆ set() [3/8]

void set ( int  l,
const char *  unit = nullptr 
)
inline

Sets the value to the given integer value and measurement unit (optional). The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment). This is a convenience method that delegates to the intpar_t version.

◆ set() [4/8]

void set ( double  d,
const char *  unit = nullptr 
)
inline

Sets the value to the given double value and measurement unit (optional). The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment).

◆ setPreservingUnit() [1/2]

void setPreservingUnit ( intpar_t  l)
inline

Sets the value to the given integer value, preserving the current measurement unit. The object must already have the INT type.

◆ setPreservingUnit() [2/2]

void setPreservingUnit ( double  d)
inline

Sets the value to the given double value, preserving the current measurement unit. The object must already have the DOUBLE type.

◆ setUnit()

void setUnit ( const char *  unit)

Sets the measurement unit to the given value, leaving the numeric part of the quantity unchanged. The object must already have the DOUBLE type. The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment).

◆ convertTo()

void convertTo ( const char *  unit)

Permanently converts this value to the given unit. The value must already have the type DOUBLE. If the current unit cannot be converted to the given one, an error will be thrown. The unit string pointer is expected to stay valid during the entire simulation (see related class comment).

See also
doubleValueInUnit()

◆ convertToDouble()

void convertToDouble ( )

If this value is of type INT, converts it into DOUBLE; has no effect if it is already a DOUBLE; and throws an error otherwise.

◆ set() [5/8]

void set ( const char *  s)
inline

Sets the value to the given string value. The string itself will be copied. nullptr is also accepted and treated as an empty string.

◆ set() [6/8]

void set ( const std::string &  s)
inline

Sets the value to the given string value.

◆ set() [7/8]

void set ( cXMLElement x)
inline

Sets the value to the given cXMLElement.

◆ set() [8/8]

void set ( const cPar par)

Copies the value from a cPar.

◆ boolValue()

bool boolValue ( ) const
inline

Returns value as a boolean. The type must be BOOL.

◆ intValue()

intpar_t intValue ( ) const

Returns value as integer. The type must be INT.

◆ longValue()

_OPPDEPRECATED intpar_t longValue ( ) const
inline

For compatibility; delegates to intValue().

◆ intValueInUnit()

intpar_t intValueInUnit ( const char *  targetUnit) const

Returns the numeric value as an integer converted to the given unit. If the current unit cannot be converted to the given one, an error will be thrown. The type must be INT.

◆ doubleValue()

double doubleValue ( ) const

Returns value as double. The type must be DOUBLE or INT.

◆ doubleValueInUnit()

double doubleValueInUnit ( const char *  targetUnit) const

Returns the numeric value as a double converted to the given unit. If the current unit cannot be converted to the given one, an error will be thrown. The type must be DOUBLE or INT.

◆ getUnit()

const char* getUnit ( ) const
inline

Returns the unit ("s", "mW", "Hz", "bps", etc), or nullptr if there was no unit was specified. Unit is only valid for the DOUBLE and INT types.

◆ stringValue()

const char* stringValue ( ) const
inline

Returns value as const char *. The type must be STRING.

◆ stdstringValue()

const std::string& stdstringValue ( ) const
inline

Returns value as std::string. The type must be STRING.

◆ xmlValue()

cXMLElement* xmlValue ( ) const
inline

Returns value as pointer to cXMLElement. The type must be XML.

◆ operator=() [2/18]

cNedValue& operator= ( bool  b)
inline

Equivalent to set(bool).

◆ operator=() [3/18]

cNedValue& operator= ( char  c)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [4/18]

cNedValue& operator= ( unsigned char  c)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [5/18]

cNedValue& operator= ( short  i)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [6/18]

cNedValue& operator= ( unsigned short  i)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [7/18]

cNedValue& operator= ( int  i)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [8/18]

cNedValue& operator= ( unsigned int  i)
inline

Converts the argument to long, and calls set(intpar_t).

◆ operator=() [9/18]

cNedValue& operator= ( long  l)
inline

Equivalent to set(intpar_t).

◆ operator=() [10/18]

cNedValue& operator= ( unsigned long  l)
inline

Converts the argument to long, and calls set(intpar_t).

References omnetpp::checked_int_cast().

◆ operator=() [11/18]

cNedValue& operator= ( long long  l)
inline

Equivalent to set(intpar_t).

References omnetpp::checked_int_cast().

◆ operator=() [12/18]

cNedValue& operator= ( unsigned long long  l)
inline

Converts the argument to long, and calls set(intpar_t).

References omnetpp::checked_int_cast().

◆ operator=() [13/18]

cNedValue& operator= ( double  d)
inline

Equivalent to set(double).

◆ operator=() [14/18]

cNedValue& operator= ( long double  d)
inline

Converts the argument to double, and calls set(double).

◆ operator=() [15/18]

cNedValue& operator= ( const char *  s)
inline

Equivalent to set(const char *).

◆ operator=() [16/18]

cNedValue& operator= ( const std::string &  s)
inline

Equivalent to set(const std::string&).

◆ operator=() [17/18]

cNedValue& operator= ( cXMLElement node)
inline

Equivalent to set(cXMLElement *).

◆ operator=() [18/18]

cNedValue& operator= ( const cPar par)
inline

Equivalent to set(const cPar&).

◆ operator bool()

operator bool ( ) const
inline

Equivalent to boolValue().

◆ operator char()

operator char ( ) const
inline

Calls intValue() and converts the result to char. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator unsigned char()

operator unsigned char ( ) const
inline

Calls intValue() and converts the result to unsigned char. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator int()

operator int ( ) const
inline

Calls intValue() and converts the result to int. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator unsigned int()

operator unsigned int ( ) const
inline

Calls intValue() and converts the result to unsigned int. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator short()

operator short ( ) const
inline

Calls intValue() and converts the result to short. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator unsigned short()

operator unsigned short ( ) const
inline

Calls intValue() and converts the result to unsigned short. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator long()

operator long ( ) const
inline

Calls intValue() and converts the result to long. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator unsigned long()

operator unsigned long ( ) const
inline

Calls intValue() and converts the result to unsigned long. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator long long()

operator long long ( ) const
inline

Calls intValue() and converts the result to long long. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator unsigned long long()

operator unsigned long long ( ) const
inline

Calls intValue() and converts the result to unsigned long long. An exception is thrown if the conversion would result in a data loss,

References omnetpp::checked_int_cast().

◆ operator double()

operator double ( ) const
inline

Equivalent to doubleValue().

◆ operator long double()

operator long double ( ) const
inline

Calls doubleValue() and converts the result to long double. Note that this is a potentially lossy operation.

◆ operator const char *()

operator const char * ( ) const
inline

Equivalent to stringValue().

◆ operator std::string()

operator std::string ( ) const
inline

Equivalent to stdstringValue().

◆ operator cXMLElement *()

operator cXMLElement * ( ) const
inline

Equivalent to xmlValue(). NOTE: The lifetime of the returned object tree is limited; see xmlValue() for details.


The documentation for this class was generated from the following file: