UnitConvertor

The UnitConvertor class provides tool for converting units stored in a string form. It uses "base" unit for each "family" (length, speed etc) and perform conversions inside a family through conversion to and from base unit.

Constructors

this
this()

Default constructor, creates an empty convertor

Members

Functions

addConversionRule
void addConversionRule(ConversionRule rule)

Adds a conversion rule to convertor

canConvert
bool canConvert(string inUnit, string outUnit)

Checks if unit conversion from in unit to out unit is possible

clear
void clear()

Clears unit convertor removing all unit conversion rules

clearAliases
void clearAliases()

Removes all alias rules

conversions
string[] conversions(string unit)

Gets a list of units with a possible connection to/from a given unit

convert
LinearFunction convert(string inUnit, string outUnit)

Converts from in unit to out unit

convert
double convert(double value, string inUnit, string outUnit, double defaultValue)

Converts a given value from in unit to out unit

families
string[] families()

Method provides access to a list of families of units in this convertor

family
string family(string unit)

Gets a family for a given unit

loadAliasesFromJson
void loadAliasesFromJson(JSONValue object)

Loads unit aliases from json serialized object

loadFromJson
void loadFromJson(JSONValue json)

Deserializes unit conversion rules from JSON

toJson
JSONValue toJson()

Serializes current unit conversion rules to JSON

unitName
string unitName(string aliasName)

Gets unit name by alias using internal alias dictionary

units
string[] units(string family)

Method provides access to a list of units in this convertor within a given family, effectively providing a list of unit with a possible conversion from any unit of this list to any other

Variables

m_aliases
AliasDictionary m_aliases;

Undocumented in source.

m_baseUnitsByFamilies
string[string] m_baseUnitsByFamilies;

Undocumented in source.

m_families
ConversionFamily[string] m_families;

Undocumented in source.

m_familiesByUnit
string[string] m_familiesByUnit;

Undocumented in source.

Meta