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.

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.

enum class Unit

Units.

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.

Public Functions

ErrorCode getErrorCode()

Return the current ErrorCode of the Units object.

Returns: ErrorCode - The current error code, or NONE if 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
ENUM is generated if an improper value is specified.

Parameters:
Returns:

Status

Status getBase(Type type, Unit *value)

Get basic unit types as output arguments.

See Also setBase()

Parameters:
Returns:

Status

Status setConversion(Type type, Unit value)

Set the conversion unit types (including temperature offset via TEMP_OFFSET . Specify conversion factors and temperature offset using setConversionFactor() .

See Also getConversion()

Parameters:
Returns:

Status

Status getConversion(Type type, Unit *value)

Get conversion unit types.

See setConversion()

Parameters:
Returns:

Status

Status getDescription(Type type, Unit value, char description[])

Get descriptive string.

Parameters:
  • type Type
  • value Unit
  • description[out] Character array to hold the descriptive string
Returns:

Status

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:

Status

Status getConversionFactor(Type type, double *value)

Get conversion factors.

See also setConversionFactor()

Parameters:
  • type Type
  • value[out] Conversion factor (or temperature offset)
Returns:

Status

Status computeConversionFactors()

Compute and set the conversion unit conversion factors.

Returns:Status
Status copy(Units *from)

Make a copy of a Units object.

Parameters:fromUnits object to copy from.
Returns:Status
Status print()

Print the content of the Units object.

Returns:Status