ADTF  3.18.2
cUnitConversion

Class for unit conversions. More...

Public Types

enum  {
  UNIT_NONE = 0 , UNIT_MILLIMETRE , UNIT_CENTIMETRE , UNIT_METRE ,
  UNIT_KILOMETRE , UNIT_MILES , UNIT_MICROSECOND , UNIT_MILLISECOND ,
  UNIT_SECOND , UNIT_MINUTE , UNIT_HOUR , UNIT_METRES_PER_SECOND ,
  UNIT_KILOMETRES_PER_HOUR , UNIT_MILES_PER_HOUR , UNIT_METRES_PER_SECOND_SQUARED , UNIT_GRAVITATION ,
  UNIT_MILLIGRAVITATION , UNIT_RADIAN , UNIT_DEGREE , UNIT_RADIANS_PER_SECOND ,
  UNIT_DEGREES_PER_SECOND , UNIT_DEGREE_CELSIUS , UNIT_DEGREE_FAHRENHEIT , UNIT_SI = 999 ,
  UNIT_USER_OFFSET = 1000
}
 

Public Member Functions

tResult Convert (tFloat64 *pf64Value, const cString &strUnitSource, const cString &strUnitDestination="SI")
 Unit Conversion. More...
 
tResult Convert (tFloat64 *pf64Value, tUInt eUnitSource, tUInt eUnitDestination=UNIT_SI)
 Unit Conversion. More...
 
tResult AddNewUnitString (tUInt eUnitIdentifier, const cString &strUnitString)
 This method adds a new identifier string for a unit. More...
 
tUInt AddNewBaseUnit ()
 This method adds a base unit to the UnitConverter and returns the created identifier handle. More...
 
tUInt AddNewDerivedUnit (tUInt eUnitBase, tFloat64 fNumerator, tFloat64 fDenominator=1.0, tFloat64 fOffset=0.0)
 This method adds a derived unit to the UnitConverter. More...
 
tUInt GetUnitIdentifier (const cString &strUnit)
 This method returns the handle of the unit corresponding to the input string. More...
 

Detailed Description

Class for unit conversions.

The cUnitConversion supports as-is the following unit identifier and associated unit strings.

In the table the degree sign (\xB0) and the superscript two sign (\xB2) are represented by there escape sequences.

Unit Identifier Unit Strings
UNIT_METRE m
UNIT_MILLIMETRE mm
UNIT_CENTIMETRE cm
UNIT_KILOMETRE km
UNIT_MILES miles
UNIT_METRES_PER_SECOND m/s, ms^-1, m*s^-1
UNIT_KILOMETRES_PER_HOUR km/h
UNIT_MILES_PER_HOUR mph
UNIT_METRES_PER_SECOND_SQUARED m/s2, ms^-2, m/s^2, m*s^-2, m/s\xB2
UNIT_GRAVITATION g
UNIT_MILLIGRAVITATION mg
UNIT_RADIAN rad
UNIT_DEGREE grad, \xB0
UNIT_RADIANS_PER_SECOND rad/s, rad/sec, rad/sek, radiant/s, radiant/sec, radiant/sek
UNIT_DEGREES_PER_SECOND \xB0/s, grad/s, grad/sec, grad/sek, \xB0/sec, \xB0/sek
UNIT_SECOND s, sec, sek
UNIT_MICROSECOND us
UNIT_MILLISECOND ms
UNIT_MINUTE min
UNIT_HOUR h
UNIT_DEGREE_CELSIUS C
UNIT_DEGREE_FAHRENHEIT F

Every unit conversion object can be extended to support even more units and units strings

Definition at line 51 of file unitconversion.h.

Member Function Documentation

◆ AddNewBaseUnit()

tUInt AddNewBaseUnit ( )

This method adds a base unit to the UnitConverter and returns the created identifier handle.

Returns
The new handle for the added unit.

◆ AddNewDerivedUnit()

tUInt AddNewDerivedUnit ( tUInt  eUnitBase,
tFloat64  fNumerator,
tFloat64  fDenominator = 1.0,
tFloat64  fOffset = 0.0 
)

This method adds a derived unit to the UnitConverter.

The last three arguments form a linear transformation from the derived unit to the base unit: fNumerator * UNIT_NEW / fDemoninator + fOffset = UNIT_BASE All existing conversions from the base unit to others units are translated to conversions from the derived unit to the other unit.

Parameters
eUnitBase[in] handle of the base unit
fNumerator[in] part of the linear transformation
fDenominator[in] part of the linear transformation
fOffset[in] part of the linear transformation
Returns
The new handle for the added unit

◆ AddNewUnitString()

tResult AddNewUnitString ( tUInt  eUnitIdentifier,
const cString strUnitString 
)

This method adds a new identifier string for a unit.

Parameters
eUnitIdentifier[in] unit for which a new string shall be added
strUnitString[in] new identifier string
Returns
Standard result code.

◆ Convert() [1/2]

tResult Convert ( tFloat64 pf64Value,
const cString strUnitSource,
const cString strUnitDestination = "SI" 
)

Unit Conversion.

This method converts a float value from one unit to another.

Parameters
pf64Value[inout] float value to convert
strUnitSource[in] description string of source unit
strUnitDestination[in] description string of unit to convert to
Returns
Standard result code.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ Convert() [2/2]

tResult Convert ( tFloat64 pf64Value,
tUInt  eUnitSource,
tUInt  eUnitDestination = UNIT_SI 
)

Unit Conversion.

This method converts a float value from one unit to another.

Parameters
pf64Value[inout] float value to convert
eUnitSource[in] handle of the source unit
eUnitDestination[in] handle of the unit to convert to
Returns
Standard result code.
This method is real-time safe.\nSee @ref page_real_time_safe.\n

◆ GetUnitIdentifier()

tUInt GetUnitIdentifier ( const cString strUnit)

This method returns the handle of the unit corresponding to the input string.

Parameters
strUnit[in] unit identifier string
Returns
The handle for the unit corresponding to the input string
This method is real-time safe.\nSee @ref page_real_time_safe.\n