Units
Overview
The Units class is used to define the units for physical quantities. The basic unit types supported are length, mass, time, temperature, angle and charge. The methods associated with a Units object are the following.
- Operations
setBase()- Set basic unit typesgetBase()- Get basic unit typessetConversion()- Set conversion unit typesgetConversion()- Get conversion unit typessetConversionFactor()- Set conversion factorsgetConversionFactor()- Get conversion factorscomputeConversionFactors()- Compute and set conversion factorsgetDescription()- Get descriptive string for a unit
- General functions
print()- Print object contentscopy()- Make a copy of a Units objectgetErrorCode()- Get error code
By default, the base and conversion units are set to SI and all
conversion factors are set to unity. Once a Units
object is instanced, set the base unit types using setBase().
If the Units
object is to be used to convert units, set the conversion unit types
using setConversion()
after setting the base unit type and set the conversion factors using
setConversionFactor().
Usually it is only necessary to set conversion factors if either the
base or conversion units type is user-defined. The conversion factors may be
automatically computed and set using computeConversionFactors().
The basic unit types are length, mass, time, temperature, angle and
charge. Associated with each unit type is a conversion unit type and conversion
factor. The conversion unit types are set using setConversion().
The conversion factor for each unit type is set using
setConversionFactor().
The conversion factors are applied to the base units to yield the
conversion units.
unit_conversion = factor*unit_base
Temperature conversion requires use of an offset. Specifically for temperature the conversion is as follows:
temp_conversion = factor*(temp_base + offset)
By default the conversion unit types are set to the basic unit types (SI units) and the conversion factors are all unity and the temperature offset is zero.
Class Members Descriptions
The currently available Units enumerations and functions are described in detail in this section.
-
class
Units Object for Units management.
Public Types
-
enum class
Type Unit types.
Values:
-
enumerator
LENGTH Length unit.
-
enumerator
MASS Mass unit.
-
enumerator
TIME Time unit.
-
enumerator
TEMP Temperature unit.
-
enumerator
TEMP_OFFSET Temperature offset unit.
-
enumerator
ANGLE Angle unit.
-
enumerator
CHARGE Charge unit.
-
enumerator
-
enum class
Unit -
Values:
-
enumerator
LENGTH_METER Meter.
-
enumerator
LENGTH_CENTIMETER Centimeter.
-
enumerator
LENGTH_MILLIMETER Millimeter.
-
enumerator
LENGTH_MICRON Micrometer.
-
enumerator
LENGTH_NANOMETER Nanometer.
-
enumerator
LENGTH_ANGSTROM Angstrom.
-
enumerator
LENGTH_KILOMETER Kilometer.
-
enumerator
LENGTH_INCH Inch.
-
enumerator
LENGTH_FOOT Foot.
-
enumerator
LENGTH_MILE Mile.
-
enumerator
LENGTH_USER User length unit.
-
enumerator
MASS_KILOGRAM Kilogram.
-
enumerator
MASS_GRAM Gram.
-
enumerator
MASS_POUND Pound.
-
enumerator
MASS_SLUG Slug.
-
enumerator
MASS_METRICTON Metric Ton.
-
enumerator
MASS_BLOB Blob.
-
enumerator
MASS_KILOGRAMFM Kilogram-force second squared per meter.
-
enumerator
MASS_KILOGRAMFMM Kilogram-force second squared per millimeter.
-
enumerator
MASS_USER User mass unit.
-
enumerator
MASS_NEWTONHOURSQUAREPERMM Newton hour squared per millimeter.
-
enumerator
MASS_MILLIGRAM Milligram.
-
enumerator
TIME_SECOND Second.
-
enumerator
TIME_MINUTE Minute.
-
enumerator
TIME_HOUR Hour.
-
enumerator
TIME_USER User time unit.
-
enumerator
TIME_MICROSECOND Microsecond.
-
enumerator
TIME_MILLISECOND Millisecond.
-
enumerator
TEMP_KELVIN Kelvin.
-
enumerator
TEMP_CELSIUS Degree Celsius.
-
enumerator
TEMP_RANKINE Degree Rankine.
-
enumerator
TEMP_FAHRENHEIT Degree Fahrenheit.
-
enumerator
TEMP_USER User temperature unit.
-
enumerator
ANGLE_RADIAN Radian.
-
enumerator
ANGLE_DEGREE Degree.
-
enumerator
ANGLE_CYCLE Cycle, 2 pi radians.
-
enumerator
ANGLE_USER User angle unit.
-
enumerator
CHARGE_COULOMB Coulomb.
-
enumerator
CHARGE_USER User charge unit.
-
enumerator
Public Functions
-
ErrorCode
getErrorCode() Return the current
ErrorCodeof the Units object.Returns: ErrorCode- The current error code, orNONEif no error.
-
Status
setBase(Type type, Unit value) Set the basic units type. The conversion unit type is also set to this type. The conversion factor is set to unity.
See Also
getBase()- Errors
-
ENUMis generated if an improper value is specified.
Parameters: Returns:
-
Status
getBase(Type type, Unit *value) Get basic unit types as output arguments.
See Also
setBase()Parameters: Returns:
-
Status
setConversion(Type type, Unit value) Set the conversion unit types (including temperature offset via
TEMP_OFFSET. Specify conversion factors and temperature offset usingsetConversionFactor().See Also
getConversion()Parameters: Returns:
-
Status
getConversion(Type type, Unit *value) Get conversion unit types.
See
setConversion()Parameters: Returns:
-
Status
getDescription(Type type, Unit value, char description[]) Get descriptive string.
Parameters: Returns:
-
Status
setConversionFactor(Type type, double value) Set the conversion factors for the selected conversion units. The temperature conversion requires an additional temperature offset.
See also
getConversionFactor()Parameters: - type –
Type - value – Conversion factor (or temperature offset)
Returns: - type –
-
Status
getConversionFactor(Type type, double *value) Get conversion factors.
See also
setConversionFactor()Parameters: - type –
Type - value – [out] Conversion factor (or temperature offset)
Returns: - type –
-
Status
computeConversionFactors() Compute and set the conversion unit conversion factors.
Returns: Status
-
enum class