Sen API
Sen Libraries
Loading...
Searching...
No Matches

Represents the definition of a unit. More...

#include <unit.h>

Classes

struct  EnsureTag

Public Member Functions

 Unit (UnitSpec spec, Private notUsable) noexcept
 Constructor is only usable by this class. Use make (see below).
 ~Unit () noexcept=default
UnitCategory getCategory () const noexcept
 Measurement type.
std::string_view getName () const noexcept
 Plain name.
std::string_view getNamePlural () const noexcept
 Plural name.
std::string_view getAbbreviation () const noexcept
 Unique abbreviation.
float64_t toSI (float64_t value) const noexcept
 Converts 'value' given in this unit to an equivalent SI unit.
float64_t fromSI (float64_t value) const noexcept
 Converts 'value' given in SI to this unit.
Result< float64_t, std::string > fromString (const std::string &str) const noexcept
 Parses a string, searching for a valid unit specification within the same category. Returns a valid value if the string contains a number and it also converts the value from the specified unit.
MemberHash getHash () const noexcept
 Returns a unique hash computed for the UnitSpec at compilation time.
bool operator== (const Unit &other) const noexcept
 Comparison.
bool operator!= (const Unit &other) const noexcept

Static Public Member Functions

static std::unique_ptr< Unitmake (UnitSpec spec)
 Moves the spec into a member.
static float64_t convert (const Unit &from, const Unit &to, float64_t value) noexcept
 Converts a a value between units.
static std::string_view getCategoryString (UnitCategory category) noexcept
 A string that describes the category.

Static Public Attributes

static constexpr EnsureTag ensurePresent {}
 Tag to request that a unit is required.

Detailed Description

Represents the definition of a unit.


Class Documentation

◆ sen::Unit::EnsureTag

struct sen::Unit::EnsureTag

Constructor & Destructor Documentation

◆ Unit()

sen::Unit::Unit ( UnitSpec spec,
Private notUsable )
noexcept

Constructor is only usable by this class. Use make (see below).

◆ ~Unit()

sen::Unit::~Unit ( )
defaultnoexcept

Member Function Documentation

◆ make()

std::unique_ptr< Unit > sen::Unit::make ( UnitSpec spec)
static

Moves the spec into a member.

◆ getCategory()

UnitCategory sen::Unit::getCategory ( ) const
nodiscardnoexcept

Measurement type.

◆ getName()

std::string_view sen::Unit::getName ( ) const
nodiscardnoexcept

Plain name.

◆ getNamePlural()

std::string_view sen::Unit::getNamePlural ( ) const
nodiscardnoexcept

Plural name.

◆ getAbbreviation()

std::string_view sen::Unit::getAbbreviation ( ) const
nodiscardnoexcept

Unique abbreviation.

◆ toSI()

float64_t sen::Unit::toSI ( float64_t value) const
nodiscardnoexcept

Converts 'value' given in this unit to an equivalent SI unit.

◆ fromSI()

float64_t sen::Unit::fromSI ( float64_t value) const
nodiscardnoexcept

Converts 'value' given in SI to this unit.

◆ fromString()

Result< float64_t, std::string > sen::Unit::fromString ( const std::string & str) const
nodiscardnoexcept

Parses a string, searching for a valid unit specification within the same category. Returns a valid value if the string contains a number and it also converts the value from the specified unit.

◆ convert()

float64_t sen::Unit::convert ( const Unit & from,
const Unit & to,
float64_t value )
staticnodiscardnoexcept

Converts a a value between units.

◆ getCategoryString()

std::string_view sen::Unit::getCategoryString ( UnitCategory category)
staticnodiscardnoexcept

A string that describes the category.

◆ getHash()

MemberHash sen::Unit::getHash ( ) const
nodiscardnoexcept

Returns a unique hash computed for the UnitSpec at compilation time.

◆ operator==()

bool sen::Unit::operator== ( const Unit & other) const
nodiscardnoexcept

Comparison.

◆ operator!=()

bool sen::Unit::operator!= ( const Unit & other) const
nodiscardnoexcept

Member Data Documentation

◆ ensurePresent

EnsureTag sen::Unit::ensurePresent {}
inlinestaticconstexpr

Tag to request that a unit is required.


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