8#ifndef SEN_CORE_META_UNIT_H
9#define SEN_CORE_META_UNIT_H
60 return lhs.category == rhs.category && lhs.name == rhs.name && lhs.namePlural == rhs.namePlural &&
61 lhs.abbreviation == rhs.abbreviation && lhs.f == rhs.f && lhs.x == rhs.x && lhs.y == rhs.y;
132 [[nodiscard]]
bool operator==(const
Unit& other) const noexcept;
133 [[nodiscard]]
bool operator!=(const
Unit& other) const noexcept;
150 u32 operator()(
const UnitSpec& spec)
const noexcept
Here we define a set of template meta-programming helpers to let the compiler take some decisions bas...
Result<T, E> is a template type that can be used to return and propagate errors. The intent is to rep...
Definition result.h:135
Unit(UnitSpec spec, Private notUsable) noexcept
Constructor is only usable by this class. Use make (see below).
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....
static float64_t convert(const Unit &from, const Unit &to, float64_t value) noexcept
Converts a a value between units.
std::string_view getAbbreviation() const noexcept
Unique abbreviation.
static std::unique_ptr< Unit > make(UnitSpec spec)
Moves the spec into a member.
std::string_view getName() const noexcept
Plain name.
UnitCategory getCategory() const noexcept
Measurement type.
float64_t toSI(float64_t value) const noexcept
Converts 'value' given in this unit to an equivalent SI unit.
std::string_view getNamePlural() const noexcept
Plural name.
static std::string_view getCategoryString(UnitCategory category) noexcept
A string that describes the category.
MemberHash getHash() const noexcept
Returns a unique hash computed for the UnitSpec at compilation time.
static constexpr EnsureTag ensurePresent
Tag to request that a unit is required.
Definition unit.h:96
float64_t fromSI(float64_t value) const noexcept
Converts 'value' given in SI to this unit.
constexpr u32 hashSeed
Initial seed for all hashes.
Definition hash32.h:33
u32 hashCombine(u32 seed, const Types &... args) noexcept
Combines the hash of different values into a single 32-bit hash.
Definition hash32.h:214
#define SEN_PRIVATE_TAG
Definition compiler_macros.h:490
UnitCategory
Type of measurement.
Definition unit.h:30
@ time
Definition unit.h:34
@ angularAcceleration
Definition unit.h:47
@ length
Definition unit.h:32
@ density
Definition unit.h:37
@ area
Definition unit.h:39
@ angle
Definition unit.h:35
@ velocity
Definition unit.h:44
@ force
Definition unit.h:40
@ acceleration
Definition unit.h:46
@ mass
Definition unit.h:33
@ pressure
Definition unit.h:38
@ temperature
Definition unit.h:36
@ angularVelocity
Definition unit.h:45
@ frequency
Definition unit.h:43
double float64_t
Definition numbers.h:17
uint32_t u32
Definition numbers.h:25
This file contains functions related to hashing and compression. This is mainly used by Sen internals...
The hash of a member.
Definition type.h:39
Data about a given unit definition. Given f, x, y:
Definition unit.h:56
std::string namePlural
Plural name (i.e. "meters").
Definition unit.h:69
float64_t x
Offset to convert to SI.
Definition unit.h:72
float64_t f
Multiplication factor to convert to SI.
Definition unit.h:71
std::string abbreviation
Unique abbreviation (i.e. "m").
Definition unit.h:70
std::string name
Plain name (i.e. "meter").
Definition unit.h:68
friend bool operator==(const UnitSpec &lhs, const UnitSpec &rhs) noexcept
Definition unit.h:58
friend bool operator!=(const UnitSpec &lhs, const UnitSpec &rhs) noexcept
Definition unit.h:64
float64_t y
Offset to convert to SI.
Definition unit.h:73
UnitCategory category
The type of measurement.
Definition unit.h:67