|
Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
|
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_ |
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.
|
privatedefault |
|
inlinestatic |
Get the singleton instance.
Definition at line 47 of file UnitsRegistry.hpp.
Get the full name of a unit type.
| UnitT | The unit type to look up |
This function is thread-safe (const method with mutable mutex).
Definition at line 76 of file UnitsRegistry.hpp.
Get the symbol of a unit type.
| UnitT | The unit type to look up |
This function is thread-safe (const method with mutable mutex).
Definition at line 92 of file UnitsRegistry.hpp.
|
inline |
Register a unit type with its display information.
| UnitT | The unit type to register |
| name | Full unit name (e.g., "Meter") |
| symbol | Unit symbol (e.g., "m") |
This function is thread-safe.
Definition at line 62 of file UnitsRegistry.hpp.
|
mutableprivate |
Definition at line 103 of file UnitsRegistry.hpp.
|
private |
Definition at line 102 of file UnitsRegistry.hpp.