dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
dimval::UnitRegistry Class Reference

Registry of unit descriptors. More...

#include <registry.hpp>

Public Member Functions

void register_unit (const UnitDescriptor &d)
 Register a descriptor. Existing entries with the same id are replaced.
 
template<UnitLike Unit>
bool register_unit ()
 Register a unit by tag — pulls the descriptor through Unit::descriptor().
 
const UnitDescriptorfind (const std::string_view id_or_symbol) const
 Look up by id, then by symbol. Returns nullptr if not found.
 
std::vector< UnitDescriptorlist () const
 Snapshot all registered descriptors.
 
std::vector< UnitDescriptorby_kind (const std::string_view kind) const
 Snapshot all descriptors whose kind matches.
 
bool compatible (const std::string_view a, const std::string_view b) const
 True iff both ids resolve and share the same kind.
 
std::size_t size () const
 Number of registered descriptors.
 

Static Public Member Functions

static UnitRegistryglobal ()
 Process-wide singleton.
 

Detailed Description

Registry of unit descriptors.

Lookups are guarded by a shared lock, registrations by a unique lock. Use UnitRegistry::global() for the process-wide instance; built-ins live there.

Member Function Documentation

◆ register_unit()

template<UnitLike Unit>
bool dimval::UnitRegistry::register_unit ( )
inline

Register a unit by tag — pulls the descriptor through Unit::descriptor().

Returns false if the id was already present (no replacement); true if this call inserted a fresh entry.


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