cNEDValue Class Reference
[Enums, types, function typedefs]

Value used during evaluating NED expressions. More...

#include <cnedvalue.h>

List of all members.

Public Types

enum  Type

Public Member Functions

void operator= (const cNEDValue &other)
Constructors

 cNEDValue ()
 cNEDValue (bool b)
 cNEDValue (long l)
 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 (long l)
void set (double d, const char *unit=NULL)
void setPreservingUnit (double d)
void setUnit (const char *unit)
void convertTo (const char *unit)
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
long longValue () const
double doubleValue () const
double doubleValueInUnit (const char *unit) 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= (int i)
cNEDValueoperator= (unsigned int i)
cNEDValueoperator= (short i)
cNEDValueoperator= (unsigned short i)
cNEDValueoperator= (long l)
cNEDValueoperator= (unsigned 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 double () const
 operator long double () const
 operator const char * () const
 operator std::string () const
 operator cXMLElement * () const

Public Attributes

enum cNEDValue::Type type

Friends

class cDynamicExpression

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=NULL)
static double parseQuantity (const char *str, std::string &outActualUnit)
static const char * getPooled (const char *s)

Detailed Description

Value used during evaluating NED expressions.

See notes below.

Double vs long:

There is no long field in cNEDValue; the reason is that the NED expression evaluator stores all numbers as double. The IEEE double's mantissa is 53 bits, so double can accurately represent long on 32-bit architectures. On 64-bit architectures the usual size of long is 64 bits, so precision loss will occur when converting very large integers to double. Note, however, that simulations that trigger this precision loss would not be able to run on 32-bit architectures at all.

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()

Member Function Documentation

bool cNEDValue::boolValue (  )  const [inline]

Returns value as a boolean.

The type must be BOOL.

void cNEDValue::convertTo ( const char *  unit  ) 

Permanently converts this value to the given unit.

The value must already have the type DBL. 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()
static double cNEDValue::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()
double cNEDValue::doubleValue (  )  const [inline]

Returns value as double.

The type must be DBL.

double cNEDValue::doubleValueInUnit ( const char *  unit  )  const [inline]

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 DBL.

References cDynamicExpression::convertUnit().

static const char* cNEDValue::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()
const char* cNEDValue::getUnit (  )  const [inline]

Returns the unit ("s", "mW", "Hz", "bps", etc), or NULL if there was no unit was specified.

Unit is only valid for the DBL type.

bool cNEDValue::isSet (  )  const [inline]

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

type is not UNDEF.

long cNEDValue::longValue (  )  const [inline]

Returns value as long.

The type must be DBL (Note: there is no LONG.)

cNEDValue::operator char (  )  const [inline]

Calls longValue() and converts the result to char.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

cNEDValue::operator cXMLElement * (  )  const [inline]

Equivalent to xmlValue().

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

References cDynamicExpression::xmlValue().

cNEDValue::operator int (  )  const [inline]

Calls longValue() and converts the result to int.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

cNEDValue::operator long double (  )  const [inline]

Calls doubleValue() and converts the result to long double.

Note that this is a potentially lossy operation.

References cDynamicExpression::doubleValue().

cNEDValue::operator short (  )  const [inline]

Calls longValue() and converts the result to short.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

cNEDValue::operator unsigned char (  )  const [inline]

Calls longValue() and converts the result to unsigned char.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

cNEDValue::operator unsigned int (  )  const [inline]

Calls longValue() and converts the result to unsigned int.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

cNEDValue::operator unsigned long (  )  const [inline]

Calls longValue() and converts the result to unsigned long.

Note that the result may be misleading!

References cDynamicExpression::longValue().

cNEDValue::operator unsigned short (  )  const [inline]

Calls longValue() and converts the result to unsigned short.

Note that this is a potentially lossy operation.

References cDynamicExpression::longValue().

static double cNEDValue::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.

static double cNEDValue::parseQuantity ( const char *  str,
const char *  expectedUnit = NULL 
) [static]

Invokes parseQuantity(), and converts the result into the given unit.

If conversion is not possible (unrelated or unknown units), and error is thrown.

void cNEDValue::set ( const char *  s  )  [inline]

Sets the value to the given string value.

The string itself will be copied. NULL is also accepted and treated as an empty string.

void cNEDValue::set ( double  d,
const char *  unit = NULL 
) [inline]

Sets the value to the given double value and measurement unit.

The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment).

void cNEDValue::setPreservingUnit ( double  d  )  [inline]

Sets the value to the given double value, preserving the current measurement unit.

The object must already have the DBL type.

void cNEDValue::setUnit ( const char *  unit  )  [inline]

Sets the measurement unit to the given value, leaving the numeric part of the quantity unchanged.

The object must already have the DBL type. The unit string pointer is expected to stay valid during the entire duration of the simulation (see related class comment).

const std::string& cNEDValue::stdstringValue (  )  const [inline]

Returns value as std::string.

The type must be STR.

Referenced by operator std::string().

const char* cNEDValue::stringValue (  )  const [inline]

Returns value as const char *.

The type must be STR.

cXMLElement* cNEDValue::xmlValue (  )  const [inline]

Returns value as pointer to cXMLElement.

The type must be XML.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:29 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3