morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
morph::units::NamedQuantity< Name, U > Struct Template Reference

A Quantity that names itself on construction and slices losslessly back to a plain Quantity. The name lives in the shared history. More...

#include <quantity.hpp>

Inheritance diagram for morph::units::NamedQuantity< Name, U >:
morph::units::Quantity< U >

Public Types

using Base = Quantity<U>
 The plain base quantity type.

Public Member Functions

 NamedQuantity ()
 Constructs empty, then names.
 NamedQuantity (std::optional< math::Rational > adopted)
 Constructs from a payload, then names.
 NamedQuantity (Base quantity)
 Constructs from a plain quantity, then names.
Public Member Functions inherited from morph::units::Quantity< U >
constexpr Quantity () noexcept=default
 Constructs the empty state (no recorded derivation).
 Quantity (math::Rational engaged)
 Engages with engaged (which keeps its own runtime precision).
 Quantity (std::optional< math::Rational > adopted)
 Adopts an optional payload as-is.
 Quantity (const Quantity< U, OtherDecimals > &other)
 Converts from the same unit at another declared precision; the value, its runtime tag, and its derivation carry over unchanged.
constexpr bool hasValue () const noexcept
 Whether a value has been entered/measured.
constexpr bool withinDeclaredBounds () const noexcept
 Pre-decode validation seam: whether the current payload falls within this field's unit-declared bounds (UnitTraits<E>::bounds), when the unit declares any. An empty payload, or a unit with no declared bounds() (HasUnitBounds not satisfied), is always within bounds — this is an opt-in check, not a new default restriction, so a unit system that declares no bounds behaves exactly as it did before this feature existed.
constexpr const std::optional< math::Rational > & value () const noexcept
 The payload, for pattern-matching / -> access.
constexpr math::Rational value_or (const math::Rational &fallback) const noexcept
 The payload if engaged, otherwise a caller-supplied fallback.
constexpr const math::Rational & operator* () const noexcept
 Unchecked access to the engaged value (UB when empty, exactly like std::optional::operator*).
Quantity withDecimalPlaces (math::DecimalPlaces newPrecision) const
 Retags the value's runtime precision (the exact value itself is unchanged — precision only affects rounding and formatting).
Quantity roundedToDecimalPlaces (math::DecimalPlaces newPrecision, math::RoundingMode mode=math::RoundingMode::HalfAwayFromZero) const
 Rounds the value to a runtime precision, changing the exact value as well as the tag — unlike withDecimalPlaces, which retags only and leaves display and storage free to disagree.
Quantity atDeclaredPrecision () const
 Rounds the value to this field's declared precision — the one the generated schema advertises as x-decimalPlaces.
Quantity named (std::string label) const
 Seals this value with a name: equation() shows the name instead of expanding its derivation. Builds a fresh node (never mutates a shared one); a no-op returning empty on empty or with tracing off.
std::vector< std::string > equation (std::size_t maxSteps=kDefaultEquationSteps) const
 The worked derivation as print-ready lines (see docs/spec/util/quantity_type.md).
 operator Quantity< To > () const
 Implicit within-dimension conversion to another unit; delegates to convert, propagates empty, and records a provenance step.

Static Public Member Functions

static NamedQuantity fromDouble (double raw)
 Names a floating-point reading.
Static Public Member Functions inherited from morph::units::Quantity< U >
static constexpr UnitMeta unitMeta () noexcept
 The unit's static metadata (id, display text, default decimals).
static constexpr math::DecimalPlaces declaredPrecision () noexcept
 The declared precision as a DecimalPlaces strong type.
static constexpr std::span< const UnitAlternative< decltype(U)> > unitAlternatives () noexcept
 The convertible display/entry units for this field's unit, derived from UnitTraits::relations.
static Quantity fromDouble (double raw) noexcept
 Converts a floating-point reading at the declared precision.
static Quantity fromOptional (std::optional< math::Rational > adopted)
 Wraps an optional payload, preserving the declared precision.

Additional Inherited Members

Public Attributes inherited from morph::units::Quantity< U >
std::optional< math::Rational > payload
 The payload; std::nullopt means "not entered / not measured".
Static Public Attributes inherited from morph::units::Quantity< U >
static constexpr auto unit
 The unit this quantity is denominated in (compile-time).
static constexpr std::uint32_t declaredDecimals
 Declared decimal places of this field (compile-time).

Detailed Description

template<detail::FixedString Name, auto U>
struct morph::units::NamedQuantity< Name, U >

A Quantity that names itself on construction and slices losslessly back to a plain Quantity. The name lives in the shared history.

Template Parameters
NameCompile-time symbol name.
UUnit enumerator.

Definition at line 1157 of file quantity.hpp.

Member Typedef Documentation

◆ Base

template<detail::FixedString Name, auto U>
using morph::units::NamedQuantity< Name, U >::Base = Quantity<U>

The plain base quantity type.

Definition at line 1159 of file quantity.hpp.

Constructor & Destructor Documentation

◆ NamedQuantity() [1/3]

template<detail::FixedString Name, auto U>
morph::units::NamedQuantity< Name, U >::NamedQuantity ( )
inline

Constructs empty, then names.

Definition at line 1162 of file quantity.hpp.

◆ NamedQuantity() [2/3]

template<detail::FixedString Name, auto U>
morph::units::NamedQuantity< Name, U >::NamedQuantity ( std::optional< math::Rational > adopted)
inline

Constructs from a payload, then names.

Parameters
adoptedEngaged or empty payload.

Definition at line 1166 of file quantity.hpp.

◆ NamedQuantity() [3/3]

template<detail::FixedString Name, auto U>
morph::units::NamedQuantity< Name, U >::NamedQuantity ( Base quantity)
inline

Constructs from a plain quantity, then names.

Parameters
quantityThe source quantity.

Definition at line 1171 of file quantity.hpp.

Member Function Documentation

◆ fromDouble()

template<detail::FixedString Name, auto U>
NamedQuantity morph::units::NamedQuantity< Name, U >::fromDouble ( double raw)
inlinestaticnodiscard

Names a floating-point reading.

Not noexcept: unlike Base::fromDouble, this wraps the result in a NamedQuantity, whose construction calls named() — and with MORPH_QUANTITY_PROVENANCE enabled named() allocates an ASTNode (std::make_shared), which can throw std::bad_alloc.

Parameters
rawThe value to convert.
Returns
The named quantity.

Definition at line 1181 of file quantity.hpp.


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