Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
Phyth::UnitRegistry Class Reference

Singleton registry for unit names and symbols. More...

#include <UnitsRegistry.hpp>

Public Member Functions

template<typename UnitT >
void RegisterUnit (const std::string &name, const std::string &symbol)
 Register a unit type with its display information.
 
template<typename UnitT >
std::string GetName () const
 Get the full name of a unit type.
 
template<typename UnitT >
std::string GetSymbol () const
 Get the symbol of a unit type.
 

Static Public Member Functions

static UnitRegistry & GetInstance ()
 Get the singleton instance.
 

Private Member Functions

 UnitRegistry ()=default
 

Private Attributes

std::unordered_map< std::type_index, UnitInfo > registry_
 
std::mutex mutex_
 

Detailed Description

Singleton registry for unit names and symbols.

UnitRegistry stores display information for unit types. It is used by QuantityToString() to print human-readable unit names instead of raw dimension strings (e.g., "J" instead of "m^2*kg*s^-2").

The registry is thread-safe via a mutex.

Usage: // Register a unit manually UnitRegistry::GetInstance().RegisterUnit<Meter>("Meter", "m");

// Register a unit at static initialization time using UnitRegistrar static UnitRegistrar<Meter> meterRegistrar("Meter", "m");

// Retrieve registered info auto name = UnitRegistry::GetInstance().GetName<Meter>(); // "Meter" auto symbol = UnitRegistry::GetInstance().GetSymbol<Meter>(); // "m"

Definition at line 40 of file UnitsRegistry.hpp.

Constructor & Destructor Documentation

◆ UnitRegistry()

Phyth::UnitRegistry::UnitRegistry ( )
privatedefault

Member Function Documentation

◆ GetInstance()

static UnitRegistry & Phyth::UnitRegistry::GetInstance ( )
inlinestatic

Get the singleton instance.

Returns
Reference to the single UnitRegistry instance

Definition at line 47 of file UnitsRegistry.hpp.

◆ GetName()

template<typename UnitT >
std::string Phyth::UnitRegistry::GetName ( ) const
inline

Get the full name of a unit type.

Template Parameters
UnitTThe unit type to look up
Returns
The unit name, or empty string if not registered

This function is thread-safe (const method with mutable mutex).

Definition at line 76 of file UnitsRegistry.hpp.

◆ GetSymbol()

template<typename UnitT >
std::string Phyth::UnitRegistry::GetSymbol ( ) const
inline

Get the symbol of a unit type.

Template Parameters
UnitTThe unit type to look up
Returns
The unit symbol, or empty string if not registered

This function is thread-safe (const method with mutable mutex).

Definition at line 92 of file UnitsRegistry.hpp.

◆ RegisterUnit()

template<typename UnitT >
void Phyth::UnitRegistry::RegisterUnit ( const std::string &  name,
const std::string &  symbol 
)
inline

Register a unit type with its display information.

Template Parameters
UnitTThe unit type to register
Parameters
nameFull unit name (e.g., "Meter")
symbolUnit symbol (e.g., "m")

This function is thread-safe.

Definition at line 62 of file UnitsRegistry.hpp.

Member Data Documentation

◆ mutex_

std::mutex Phyth::UnitRegistry::mutex_
mutableprivate

Definition at line 103 of file UnitsRegistry.hpp.

◆ registry_

std::unordered_map<std::type_index, UnitInfo> Phyth::UnitRegistry::registry_
private

Definition at line 102 of file UnitsRegistry.hpp.


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