FNSS C++ library
C++ API for the Fast Network Simulation Setup (FNSS) toolchain
 All Classes Functions Typedefs Pages
Public Member Functions | List of all members
fnss::Quantity Class Reference

#include <quantity.h>

Public Member Functions

 Quantity (const double &value_, const std::string &unit_, const MeasurementUnit &converter_)
 
 Quantity (const double &value_, const MeasurementUnit &converter_)
 
 Quantity (const std::string &str, const MeasurementUnit &converter_)
 
 Quantity (const MeasurementUnit &converter_)
 
void fromString (const std::string &str)
 
std::string toString (const std::string &separator="") const
 
void convert (const std::string &unit)
 
double getValue () const
 
void setValue (const double &value)
 
std::string getUnit () const
 
void setUnit (const std::string &unit)
 
const MeasurementUnitgetMeasurementUnit () const
 
Quantityoperator= (const Quantity &other)
 
bool operator< (const Quantity &other) const
 
bool operator<= (const Quantity &other) const
 
bool operator> (const Quantity &other) const
 
bool operator>= (const Quantity &other) const
 
bool operator== (const Quantity &other) const
 

Detailed Description

Models a quantity and allows for conversions between measurement units of the same type.

Author
Cosmin Cocora.

Constructor & Destructor Documentation

fnss::Quantity::Quantity ( const double &  value_,
const std::string &  unit_,
const MeasurementUnit converter_ 
)

Constructor with explicit numerical value and unit.

Parameters
valuethe numeric value of the quantity.
unitthe value of the quantity's unit.
converterthe MeasurementUnit object used for conversions. The object is not copied, only the reference is stored.
fnss::Quantity::Quantity ( const double &  value_,
const MeasurementUnit converter_ 
)

Constructor with explicit numerical value.

The unit is assigned to the base of this->converter. Mainly declared to avoid calls of the type Quantity(0, someUnit) that would otherwise match the string constructor.

Parameters
valuethe numeric value of the quantity.
converterthe MeasurementUnit object used for conversions. The object is not copied, only the reference is stored.
fnss::Quantity::Quantity ( const std::string &  str,
const MeasurementUnit converter_ 
)

Constructor that parses a string to obtain the numerical value and unit.

If not provided in the input, the unit is assumed to be the base of this->converter.

Parameters
strthe std::string to be parsed for value and unit data.
converterthe MeasurementUnit object used for conversions. The object is not copied, only the reference is stored.
fnss::Quantity::Quantity ( const MeasurementUnit converter_)

Constructor.

Parameters
converterthe MeasurementUnit object used for conversions. The object is not copied, only the reference is stored.

Member Function Documentation

void fnss::Quantity::convert ( const std::string &  unit)

Convert to the specified unit(eg. from GB/s to Tb/h).

Parameters
unitthe unit to convert to.
void fnss::Quantity::fromString ( const std::string &  str)

Parse a string to obtain the numerical value and unit. The previously stored data is discarded.

Parameters
strthe std::string to be parsed for value and unit data.
const MeasurementUnit & fnss::Quantity::getMeasurementUnit ( ) const

Get a const reference to the MeasurementUnit object that is using for conversions.

Returns
the const reference to the MeasurementUnit object being used.
std::string fnss::Quantity::getUnit ( ) const

Get method for the unit of the quantity.

Returns
the unit of the quantity.
double fnss::Quantity::getValue ( ) const

Get method for the numerical value of the quantity.

Returns
the numerical value of the quantity.
bool fnss::Quantity::operator< ( const Quantity other) const

Comparison operator that takes into account the quantity's measurement unit.

bool fnss::Quantity::operator<= ( const Quantity other) const

Comparison operator that takes into account the quantity's measurement unit.

Quantity & fnss::Quantity::operator= ( const Quantity other)

Assignment operator.

Throws an exception if the MeasurementUnit reference of the other object has a different base from the MeasurementUnit reference of .

bool fnss::Quantity::operator== ( const Quantity other) const

Comparison operator that takes into account the quantity's measurement unit.

bool fnss::Quantity::operator> ( const Quantity other) const

Comparison operator that takes into account the quantity's measurement unit.

bool fnss::Quantity::operator>= ( const Quantity other) const

Comparison operator that takes into account the quantity's measurement unit.

void fnss::Quantity::setUnit ( const std::string &  unit)

Set method for the unit of the quantity.

Parameters
unitthe unit to set.
void fnss::Quantity::setValue ( const double &  value)

Set method for the numerical value of the quantity.

Parameters
valuethe numerical value to set.
std::string fnss::Quantity::toString ( const std::string &  separator = "") const

Obtain a string representation of the object(eg. "5 GB/s").

If not provided in the input, the unit is assumed to be the base of this->converter.

Parameters
separatorthe std::the separator to insert between value and unit.
Returns
the std::string representation of the object.

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