ActiveLib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
active::measure::Unit< T, Type > Struct Template Reference

#include <Unit.h>

Collaboration diagram for active::measure::Unit< T, Type >:
Collaboration graph
[legend]

Public Member Functions

 Unit (Type type)
 
 Unit (Type first, Type second)
 
 Unit (Type type, uint8_t prec, bool isDecimal=true, bool suffixes=true)
 
 Unit (Type first, Type second, uint8_t prec, bool isDecimal=true)
 
 Unit (Type first, Type second, Type third, uint8_t prec, bool isDecimal=true)
 
bool isDecimal () const
 
double divisor () const
 
double eps () const
 
bool isMetric (Type type) const
 
double simpleRatio (double value, double factor, bool reversed) const
 
double conversion (Type type, double value, bool reversed=false) const
 
utility::String suffix (Type type) const
 
std::optional< Type > fromTag (const utility::String &text) const
 
utility::String toTag (Type type) const
 
std::optional< std::pair< Type, utility::String::size_type > > findSuffix (const utility::String &text, utility::String::size_type startPos=0) const
 

Public Attributes

Type primary
 The primary unit to display.
 
std::optional< Type > secondary
 An optional secondary unit, e.g. for foot/inch combos (nullopt = none)
 
std::optional< Type > tertiary
 An optional teriary unit, e.g. for degrees/minutes/seconds combos (nullopt = none, ignored if no secondary unit)
 
uint8_t precision = 4
 The display precision (decimal places for metric or 2^-n for fractional units.
 
double base = 10.0
 The numeric base for fractional quantities (10.0 = floating point to specified decimal places, other values create a fraction)
 
bool isUnitSuffix = true
 True if values should be displayed with a unit suffix, e.g. "100.0mm" rather than "100.0" (always true when multiple units)
 
bool isLeadingZero = false
 True if a value is displayed with multiple units and zero values (apart from the last unit) should be included, e.g. 0' 10" vs 10".
 

Detailed Description

template<typename T, typename Type>
struct active::measure::Unit< T, Type >

Template for all classes governing the formatting of measured values when converted to a string

Formatting options include:

Constructor & Destructor Documentation

◆ Unit() [1/5]

template<typename T , typename Type >
active::measure::Unit< T, Type >::Unit ( Type type)
inline

Constructor

Parameters
typeThe primary unit type

◆ Unit() [2/5]

template<typename T , typename Type >
active::measure::Unit< T, Type >::Unit ( Type first,
Type second )
inline

Constructor

Parameters
firstThe primary unit type
secondThe secondary unit type

◆ Unit() [3/5]

template<typename T , typename Type >
active::measure::Unit< T, Type >::Unit ( Type type,
uint8_t prec,
bool isDecimal = true,
bool suffixes = true )
inline

Constructor

Parameters
typeThe primary unit type
precThe unit display precision (decimal places for metric or 2^-n for fractional units)
isDecimalTrue if fractional values should display as decimal (floating point) numbers
suffixesTrue if the value should be displayed with the unit suffix, e.g. 100mm

◆ Unit() [4/5]

template<typename T , typename Type >
active::measure::Unit< T, Type >::Unit ( Type first,
Type second,
uint8_t prec,
bool isDecimal = true )
inline

Constructor

Parameters
firstThe primary unit type
secondThe secondary unit type
precThe unit display precision (decimal places for metric or 2^-n for fractional units)
isDecimalTrue if fractional values should display as decimal (floating point) numbers

◆ Unit() [5/5]

template<typename T , typename Type >
active::measure::Unit< T, Type >::Unit ( Type first,
Type second,
Type third,
uint8_t prec,
bool isDecimal = true )
inline

Constructor

Parameters
firstThe primary unit type
secondThe secondary unit type
thirdThe tertiary unit type
precThe unit display precision (decimal places for metric or 2^-n for fractional units)
isDecimalTrue if fractional values should display as decimal (floating point) numbers

Member Function Documentation

◆ conversion()

template<typename T , typename Type >
double active::measure::Unit< T, Type >::conversion ( Type type,
double value,
bool reversed = false ) const
inline

Convert a value of a specified unit type the standard unit (e.g. to metres for length)

Parameters
typeThe target unit type
valueThe value to convert
reversedTrue if the conversion should work in reverse (from a standard unit to the specified unit)
Returns
The converted value
Here is the call graph for this function:

◆ divisor()

template<typename T , typename Type >
double active::measure::Unit< T, Type >::divisor ( ) const
inline

The format divisor for fractional formatting

Returns
The divisor
Here is the caller graph for this function:

◆ eps()

template<typename T , typename Type >
double active::measure::Unit< T, Type >::eps ( ) const
inline

Get the formatted rounding/display precision

Returns
The rounding/display precision
Here is the call graph for this function:

◆ findSuffix()

template<typename T , typename Type >
std::optional< std::pair< Type, utility::String::size_type > > active::measure::Unit< T, Type >::findSuffix ( const utility::String & text,
utility::String::size_type startPos = 0 ) const
inline

Find the first unit type suffix in text, e.g. "mm" in "100mm"

Parameters
textThe text to find the suffix in
startPosThe character to start searching the text from
Returns
A unit type paired with the start position in the string (nullopt if no suffix is found)
Here is the call graph for this function:

◆ fromTag()

template<typename T , typename Type >
std::optional< Type > active::measure::Unit< T, Type >::fromTag ( const utility::String & text) const
inline

Get a unit type from a text tag

Parameters
textThe incoming tag
Returns
The equivalent unit type

◆ isDecimal()

template<typename T , typename Type >
bool active::measure::Unit< T, Type >::isDecimal ( ) const
inline

Determine if this format creates fractions

Returns
True if fractions are created
Here is the call graph for this function:

◆ isMetric()

template<typename T , typename Type >
bool active::measure::Unit< T, Type >::isMetric ( Type type) const
inline

Determine if the specified unit type is metric

Parameters
typeThe target unit type
Returns
True if the specified unit type is metric

◆ simpleRatio()

template<typename T , typename Type >
double active::measure::Unit< T, Type >::simpleRatio ( double value,
double factor,
bool reversed ) const
inline

A simple unit value conversion function (multiplying the value by a conversion factor)

Parameters
valueThe value to convert
factorThe conversion factor
reversedTrue if the conversion should work in reverse (from a standard unit to this unit)
Returns
The converted value
Here is the caller graph for this function:

◆ suffix()

template<typename T , typename Type >
utility::String active::measure::Unit< T, Type >::suffix ( Type type) const
inline

Get the abbreviated suffix for a unit type, e.g. "mm"

Parameters
typeThe target unit type
Returns
The unit type abbreviated suffix
Here is the call graph for this function:

◆ toTag()

template<typename T , typename Type >
utility::String active::measure::Unit< T, Type >::toTag ( Type type) const
inline

Get the tag name for a unit type, e.g. "millimetres"

Parameters
typeThe incoming unit type
Returns
The unit type tag
Here is the call graph for this function:

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