NDEVR
API Documentation

Defines a unit of measurement for converting and displaying data values. More...

Inheritance diagram for Unit:
[legend]
Collaboration diagram for Unit:
[legend]

Public Member Functions

 Unit (StringView name, TranslatedString translated_id)
 Constructs a Unit with the given internal name and translated display name.
virtual ~Unit ()=default
 Virtual destructor.
virtual const TranslatedStringabbreviation (uint01 direction=X) const =0
 Returns the abbreviated name for this unit along the given axis direction.
virtual Unitclone () const
 Creates a deep copy of this unit.
virtual Unitclone (const StringView &new_name, const TranslatedString &new_display_name) const =0
 Creates a deep copy of this unit with a new name and display name.
template<class t_angle_type>
Angle< t_angle_type > convertAngleFromUnit (const fltp08 &unit_space, uint01 direction=X) const
 Converts a scalar value in this unit's space back to an Angle in program space.
virtual fltp08 convertFromString (const StringView &unit_string, uint01 direction=X) const
 Parses a string in this unit's format and converts the result to internal program space.
virtual fltp08 convertFromUnit (const fltp08 &unit_space, const uint01 direction=X) const =0
 Converts a value from this unit's representation back to internal program space.
virtual Ray< 3, fltp08convertFromUnit (const Ray< 3, fltp08 > &unit_space) const =0
 Converts a 3D ray from this unit's representation back to internal program space.
virtual Vertex< 3, fltp08convertFromUnit (const Vertex< 3, fltp08 > &unit_space) const =0
 Converts a 3D vertex from this unit's representation back to internal program space.
template<class t_angle_type>
String convertToString (const Angle< t_angle_type > &program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
 Converts an angle value from program space to a formatted string in this unit.
virtual String convertToString (const fltp08 &program_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
 Converts a scalar value from program space to a formatted string in this unit.
template<class t_angle_type>
fltp08 convertToUnit (const Angle< t_angle_type > &program_space, uint01 direction=X) const
 Converts an angle value from program space to this unit's scalar representation.
virtual fltp08 convertToUnit (const fltp08 &program_space, const uint01 direction=X) const =0
 Converts a value from internal program space to this unit's representation.
virtual Ray< 3, fltp08convertToUnit (const Ray< 3, fltp08 > &program_space) const =0
 Converts a 3D ray from internal program space to this unit's representation.
virtual Vertex< 3, fltp08convertToUnit (const Vertex< 3, fltp08 > &program_space) const =0
 Converts a 3D vertex from internal program space to this unit's representation.
virtual fltp08 epsilon (fltp08 value, uint01 direction=X) const
 Returns a small epsilon value appropriate for comparisons in this unit at the given magnitude.
virtual fltp08 fromString (const StringView &unit_string, uint01 direction=X) const
 Parses a string into a scalar value in this unit's space without converting to program space.
virtual StringView getNextPreferredSeparator (const StringView &current_string, uint01 direction=X) const
 Returns the next preferred separator character sequence based on the current input string.
virtual Matrix< fltp08matrix () const =0
 Returns the transformation matrix representing this unit's conversion.
bool operator== (const Unit &other) const
 Checks equality between two units by comparing their matrices and names.
virtual const UnitsubUnit (uint01 direction) const =0
 Returns the sub-unit for a specific axis direction, if this unit is compound.
virtual void toFormula (StringAllocatingView &unit_string, uint01 direction=X) const
 Writes the unit conversion as a formula into the given string.
String toString (const fltp08 &unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
 Formats a value already in this unit's space into a display string.
virtual void toString (String &string, const fltp08 &unit_space, bool add_comma, uint04 min_decimals, uint04 max_decimals, uint04 min_digits, bool include_abv=true, uint01 direction=X) const
 Appends a formatted unit value to an existing string.
virtual TranslatedString translatedAxisName (uint04 index) const
 Returns the translated axis name for a given axis index.
TranslatedString translatedName () const
 Returns the translated display name of this unit.

Public Attributes

TranslatedString axis_abbreviations [4]
 Translated axis abbreviations for up to four axes.
TranslatedString axis_name_ids [4]
 Translated axis names for up to four axes.
const String name
 Internal identifier name for this unit.
const TranslatedString translated_id
 Translated display name for this unit.

Static Protected Member Functions

static Buffer< StringViewOperatorSplit (const StringView &string)
 Splits a string by operator characters for formula parsing.

Detailed Description

Defines a unit of measurement for converting and displaying data values.


See also
UnitManager, UnitDefinitions, CoordinateProjection

Definition at line 38 of file Unit.h.

Constructor & Destructor Documentation

◆ Unit()

Unit::Unit ( StringView name,
TranslatedString translated_id )

Constructs a Unit with the given internal name and translated display name.

Parameters
[in]nameThe internal identifier for this unit.
[in]translated_idThe translated display name for this unit.

References name, and translated_id.

Referenced by LocationElevationUnit::LocationElevationUnit(), ScaledOffsetUnit::ScaledOffsetUnit(), ScaledUnit::ScaledUnit(), LocationElevationUnit::clone(), ScaledOffsetUnit::clone(), ScaledUnit::clone(), clone(), clone(), operator==(), LocationElevationUnit::subUnit(), ScaledOffsetUnit::subUnit(), ScaledUnit::subUnit(), and subUnit().

Member Function Documentation

◆ abbreviation()

virtual const TranslatedString & Unit::abbreviation ( uint01 direction = X) const
nodiscardpure virtual

Returns the abbreviated name for this unit along the given axis direction.

Parameters
[in]directionThe axis direction index (default X).
Returns
The translated abbreviation string for this unit.

Implemented in LocationElevationUnit, ScaledOffsetUnit, and ScaledUnit.

Referenced by toString().

◆ clone() [1/2]

virtual Unit * Unit::clone ( ) const
nodiscardvirtual

Creates a deep copy of this unit.

Returns
A newly allocated clone of this unit.

References Unit().

◆ clone() [2/2]

virtual Unit * Unit::clone ( const StringView & new_name,
const TranslatedString & new_display_name ) const
nodiscardpure virtual

Creates a deep copy of this unit with a new name and display name.

Parameters
[in]new_nameThe new internal identifier.
[in]new_display_nameThe new translated display name.
Returns
A newly allocated clone with the specified name and display name.

Implemented in AngleUnit, DDMMSSAngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, ScaledUnit, ThreePartAngleUnit, TwoPartAngleUnit, and TwoPartUnit.

References Unit().

◆ convertAngleFromUnit()

template<class t_angle_type>
Angle< t_angle_type > Unit::convertAngleFromUnit ( const fltp08 & unit_space,
uint01 direction = X ) const
inlinenodiscard

Converts a scalar value in this unit's space back to an Angle in program space.

Parameters
[in]unit_spaceThe scalar value in this unit's space.
[in]directionThe axis direction index (default X).
Returns
The angle in internal program space.

Definition at line 144 of file Unit.h.

References convertFromUnit(), and INTERNAL_ANGLE.

◆ convertFromString()

virtual fltp08 Unit::convertFromString ( const StringView & unit_string,
uint01 direction = X ) const
inlinenodiscardvirtual

Parses a string in this unit's format and converts the result to internal program space.

Parameters
[in]unit_stringThe string to parse.
[in]directionThe axis direction index (default X).
Returns
The value in internal program space.

Reimplemented in LocationElevationUnit, and ScaledUnit.

Definition at line 209 of file Unit.h.

References convertFromUnit(), and fromString().

◆ convertFromUnit() [1/3]

virtual fltp08 Unit::convertFromUnit ( const fltp08 & unit_space,
const uint01 direction = X ) const
nodiscardpure virtual

Converts a value from this unit's representation back to internal program space.

Parameters
[in]unit_spaceThe value in this unit's space.
[in]directionThe axis direction index (default X).
Returns
The value converted to internal program space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

Referenced by convertAngleFromUnit(), and convertFromString().

◆ convertFromUnit() [2/3]

virtual Ray< 3, fltp08 > Unit::convertFromUnit ( const Ray< 3, fltp08 > & unit_space) const
nodiscardpure virtual

Converts a 3D ray from this unit's representation back to internal program space.

Parameters
[in]unit_spaceThe ray in this unit's space.
Returns
The ray converted to internal program space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

◆ convertFromUnit() [3/3]

virtual Vertex< 3, fltp08 > Unit::convertFromUnit ( const Vertex< 3, fltp08 > & unit_space) const
nodiscardpure virtual

Converts a 3D vertex from this unit's representation back to internal program space.

Parameters
[in]unit_spaceThe vertex in this unit's space.
Returns
The vertex converted to internal program space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

◆ convertToString() [1/2]

template<class t_angle_type>
String Unit::convertToString ( const Angle< t_angle_type > & program_space,
bool add_comma,
uint04 min_decimals,
uint04 max_decimals,
uint04 min_digits,
bool include_abv = true,
uint01 direction = X ) const
inlinenodiscard

Converts an angle value from program space to a formatted string in this unit.

Parameters
[in]program_spaceThe angle in internal program space.
[in]add_commaWhether to include comma separators for large numbers.
[in]min_decimalsMinimum number of decimal places to display.
[in]max_decimalsMaximum number of decimal places to display.
[in]min_digitsMinimum number of digits to display.
[in]include_abvWhether to append the unit abbreviation.
[in]directionThe axis direction index (default X).
Returns
A formatted string representing the angle in this unit.

Definition at line 120 of file Unit.h.

References convertToString().

Referenced by convertToString().

◆ convertToString() [2/2]

virtual String Unit::convertToString ( const fltp08 & program_space,
bool add_comma,
uint04 min_decimals,
uint04 max_decimals,
uint04 min_digits,
bool include_abv = true,
uint01 direction = X ) const
inlinenodiscardvirtual

Converts a scalar value from program space to a formatted string in this unit.

Parameters
[in]program_spaceThe value in internal program space.
[in]add_commaWhether to include comma separators for large numbers.
[in]min_decimalsMinimum number of decimal places to display.
[in]max_decimalsMaximum number of decimal places to display.
[in]min_digitsMinimum number of digits to display.
[in]include_abvWhether to append the unit abbreviation.
[in]directionThe axis direction index (default X).
Returns
A formatted string representing the value in this unit.

Reimplemented in LocationElevationUnit, and ScaledUnit.

Definition at line 160 of file Unit.h.

References convertToUnit(), and toString().

◆ convertToUnit() [1/4]

template<class t_angle_type>
fltp08 Unit::convertToUnit ( const Angle< t_angle_type > & program_space,
uint01 direction = X ) const
inlinenodiscard

Converts an angle value from program space to this unit's scalar representation.

Parameters
[in]program_spaceThe angle in internal program space.
[in]directionThe axis direction index (default X).
Returns
The angle value converted to this unit's space.

Definition at line 132 of file Unit.h.

References convertToUnit().

◆ convertToUnit() [2/4]

virtual fltp08 Unit::convertToUnit ( const fltp08 & program_space,
const uint01 direction = X ) const
nodiscardpure virtual

Converts a value from internal program space to this unit's representation.

Parameters
[in]program_spaceThe value in internal program space.
[in]directionThe axis direction index (default X).
Returns
The value converted to this unit's space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

Referenced by convertToString(), and convertToUnit().

◆ convertToUnit() [3/4]

virtual Ray< 3, fltp08 > Unit::convertToUnit ( const Ray< 3, fltp08 > & program_space) const
nodiscardpure virtual

Converts a 3D ray from internal program space to this unit's representation.

Parameters
[in]program_spaceThe ray in internal program space.
Returns
The ray converted to this unit's space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

◆ convertToUnit() [4/4]

virtual Vertex< 3, fltp08 > Unit::convertToUnit ( const Vertex< 3, fltp08 > & program_space) const
nodiscardpure virtual

Converts a 3D vertex from internal program space to this unit's representation.

Parameters
[in]program_spaceThe vertex in internal program space.
Returns
The vertex converted to this unit's space.

Implemented in AngleUnit, LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

◆ epsilon()

virtual fltp08 Unit::epsilon ( fltp08 value,
uint01 direction = X ) const
nodiscardvirtual

Returns a small epsilon value appropriate for comparisons in this unit at the given magnitude.

Parameters
[in]valueThe reference magnitude.
[in]directionThe axis direction index (default X).
Returns
An epsilon value suitable for floating-point comparisons.

Reimplemented in AngleUnit, DDMMSSAngleUnit, LocationElevationUnit, MatrixUnit, ThreePartAngleUnit, TwoPartAngleUnit, and TwoPartUnit.

◆ fromString()

virtual fltp08 Unit::fromString ( const StringView & unit_string,
uint01 direction = X ) const
inlinenodiscardvirtual

Parses a string into a scalar value in this unit's space without converting to program space.

Parameters
[in]unit_stringThe string to parse.
[in]directionThe axis direction index (default X).
Returns
The parsed value in this unit's space.

Reimplemented in DDMMSSAngleUnit, LocationElevationUnit, ScaledUnit, ThreePartAngleUnit, TwoPartAngleUnit, and TwoPartUnit.

Definition at line 220 of file Unit.h.

References StringView::getAs().

Referenced by convertFromString().

◆ getNextPreferredSeparator()

virtual StringView Unit::getNextPreferredSeparator ( const StringView & current_string,
uint01 direction = X ) const
nodiscardvirtual

Returns the next preferred separator character sequence based on the current input string.

Parameters
[in]current_stringThe current string being composed.
[in]directionThe axis direction index (default X).
Returns
A view of the next preferred separator string.

Reimplemented in DDMMSSAngleUnit, LocationElevationUnit, ThreePartAngleUnit, TwoPartAngleUnit, and TwoPartUnit.

◆ matrix()

virtual Matrix< fltp08 > Unit::matrix ( ) const
nodiscardpure virtual

Returns the transformation matrix representing this unit's conversion.

Returns
The unit conversion matrix.

Implemented in LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

Referenced by operator==().

◆ operator==()

bool Unit::operator== ( const Unit & other) const
inline

Checks equality between two units by comparing their matrices and names.

Parameters
[in]otherThe unit to compare against.
Returns
True if both units have the same matrix and name.

Definition at line 281 of file Unit.h.

References Unit(), matrix(), and name.

◆ OperatorSplit()

Buffer< StringView > Unit::OperatorSplit ( const StringView & string)
staticprotected

Splits a string by operator characters for formula parsing.

Parameters
[in]stringThe string to split.
Returns
A buffer of string views split at operator boundaries.

◆ subUnit()

virtual const Unit * Unit::subUnit ( uint01 direction) const
nodiscardpure virtual

Returns the sub-unit for a specific axis direction, if this unit is compound.

Parameters
[in]directionThe axis direction index.
Returns
A pointer to the sub-unit for the given direction.

Implemented in LocationElevationUnit, MatrixUnit, ScaledOffsetUnit, and ScaledUnit.

References Unit().

◆ toFormula()

virtual void Unit::toFormula ( StringAllocatingView & unit_string,
uint01 direction = X ) const
virtual

Writes the unit conversion as a formula into the given string.

Parameters
[in,out]unit_stringThe string to write the formula into.
[in]directionThe axis direction index (default X).

Reimplemented in LocationElevationUnit.

◆ toString() [1/2]

String Unit::toString ( const fltp08 & unit_space,
bool add_comma,
uint04 min_decimals,
uint04 max_decimals,
uint04 min_digits,
bool include_abv = true,
uint01 direction = X ) const
inlinenodiscard

Formats a value already in this unit's space into a display string.

Parameters
[in]unit_spaceThe value already converted to this unit's space.
[in]add_commaWhether to include comma separators for large numbers.
[in]min_decimalsMinimum number of decimal places to display.
[in]max_decimalsMaximum number of decimal places to display.
[in]min_digitsMinimum number of digits to display.
[in]include_abvWhether to append the unit abbreviation.
[in]directionThe axis direction index (default X).
Returns
A formatted display string.

Definition at line 176 of file Unit.h.

References toString().

Referenced by ScaledUnit::convertToString(), convertToString(), and toString().

◆ toString() [2/2]

virtual void Unit::toString ( String & string,
const fltp08 & unit_space,
bool add_comma,
uint04 min_decimals,
uint04 max_decimals,
uint04 min_digits,
bool include_abv = true,
uint01 direction = X ) const
inlinevirtual

Appends a formatted unit value to an existing string.

Parameters
[in,out]stringThe string to append the formatted value to.
[in]unit_spaceThe value already converted to this unit's space.
[in]add_commaWhether to include comma separators for large numbers.
[in]min_decimalsMinimum number of decimal places to display.
[in]max_decimalsMaximum number of decimal places to display.
[in]min_digitsMinimum number of digits to display.
[in]include_abvWhether to append the unit abbreviation.
[in]directionThe axis direction index (default X).

Reimplemented in DDMMSSAngleUnit, LocationElevationUnit, ThreePartAngleUnit, TwoPartAngleUnit, and TwoPartUnit.

Definition at line 194 of file Unit.h.

References abbreviation().

◆ translatedAxisName()

virtual TranslatedString Unit::translatedAxisName ( uint04 index) const
nodiscardvirtual

Returns the translated axis name for a given axis index.

Parameters
[in]indexThe axis index.
Returns
The translated axis name.

Reimplemented in LocationElevationUnit.

◆ translatedName()

TranslatedString Unit::translatedName ( ) const
nodiscard

Returns the translated display name of this unit.

Returns
The translated name.

The documentation for this struct was generated from the following file: