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

Classes

class  BaseMismatchException
 
class  UnknownConversionException
 

Public Types

typedef std::map< std::string,
double > 
conversionsMapType
 

Public Member Functions

 MeasurementUnit (const std::string &base_)
 
 MeasurementUnit (const std::string &base_, const conversionsMapType &conversions_)
 
double convert (const std::string &unit) const
 
double convert (const std::string &unit1, const std::string &unit2) const
 
std::string getBaseUnit () const
 
std::set< std::string > getAllUnits () const
 
void addConversion (std::string unit, double multiplier)
 
void addConversions (const conversionsMapType &conversions_)
 
MeasurementUnitcombine (const MeasurementUnit &other)
 
MeasurementUnitoperator= (const MeasurementUnit &other)
 

Static Public Member Functions

static MeasurementUnit prefixDerivation (const MeasurementUnit &prefix, const MeasurementUnit &target)
 
static MeasurementUnit fractionalDerivation (const MeasurementUnit &numerator, const MeasurementUnit &denominator, const std::string &separator)
 

Member Typedef Documentation

typedef std::map<std::string, double> fnss::MeasurementUnit::conversionsMapType

Map from unit to the multiplier required to convert to the base unit, eg. km -> 1000.

Constructor & Destructor Documentation

fnss::MeasurementUnit::MeasurementUnit ( const std::string &  base_)

Constructor.

Parameters
thebase the unit base(eg. sec, m).
fnss::MeasurementUnit::MeasurementUnit ( const std::string &  base_,
const conversionsMapType conversions_ 
)

Constructor.

Parameters
thebase the unit base(eg. sec, m).
theconversion map.

Member Function Documentation

void fnss::MeasurementUnit::addConversion ( std::string  unit,
double  multiplier 
)

Add or overwrite a conversion unit.

Parameters
unitthe unit the conversion if from.
multiplierthe multiplier of the conversion.
void fnss::MeasurementUnit::addConversions ( const conversionsMapType conversions_)

Adds conversion unit. Does not overwrite exiting units.

Parameters
conversionsconversionsMapType object to add.
MeasurementUnit & fnss::MeasurementUnit::combine ( const MeasurementUnit other)

Insert all the units from other into this. Does not overwrite existing units. Does not change this->base and other->base is just added to the conversions map.

Parameters
otherthe object to add the units from.
Returns
reference to for chaining.
double fnss::MeasurementUnit::convert ( const std::string &  unit) const

Convert the given unit to the base unit. Throws an exception if the conversion is not found in this->conversions.

Returns
unit conversion multiplier.
double fnss::MeasurementUnit::convert ( const std::string &  unit1,
const std::string &  unit2 
) const

Convert between the given units. Throws an exception if the conversion is not found in this->conversions.

Returns
the multiplier required to convert unit1 to unit2.
MeasurementUnit fnss::MeasurementUnit::fractionalDerivation ( const MeasurementUnit numerator,
const MeasurementUnit denominator,
const std::string &  separator 
)
static

Get an object with all the combinations of numerator over denominator units possible. The created unit string representation is "numerator + separator + denominator".

Parameters
numeratorthe numerator unit.
denominatorthe denominator unit.
separatorthe separator used in the string representation.
Returns
the resulting unit.
std::set< std::string > fnss::MeasurementUnit::getAllUnits ( ) const

Get a std::set of all known units for this measure(eg. ms, us, mm).

Returns
a std::set of all known units for this measure.
std::string fnss::MeasurementUnit::getBaseUnit ( ) const

Get the base unit.

Returns
the base unit.
MeasurementUnit & fnss::MeasurementUnit::operator= ( const MeasurementUnit other)

Assignment operator. Throws an exception if trying to assign an object with a different this->base.

MeasurementUnit fnss::MeasurementUnit::prefixDerivation ( const MeasurementUnit prefix,
const MeasurementUnit target 
)
static

Get an object with units constructed by applying all the units in the prefix object to all the units in the target object.

Parameters
prefixthe prefix unit.
targetthe target unit.

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