Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
registry.hpp File Reference

Name tables mapping long and short names to units, with constexpr lookup. More...

#include "shamunits/Unit.hpp"
#include <string_view>
#include <span>
#include <stdexcept>
#include <string>
Include dependency graph for registry.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  shamunits::NamedUnit
 One registry entry: a unit and the two names it can be looked up by. More...

Namespaces

namespace  shamunits
 namespace containing the units library

Functions

constexpr const NamedUnit * shamunits::details::find_named (std::span< const NamedUnit > registry, std::string_view name) noexcept
 Entry whose long or short name is name, or nullptr.
Unit shamunits::details::unit_from_name (std::span< const NamedUnit > registry, std::string_view name, std::string_view kind="unit")
 Unit named name in registry; throws std::invalid_argument when unknown.
constexpr bool shamunits::details::names_are_valid (std::span< const NamedUnit > registry) noexcept
 True when no name is empty and no name appears twice, long and short names together.

Detailed Description

Name tables mapping long and short names to units, with constexpr lookup.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

Each category (units, prefixes, constants) owns one registry, a constexpr array of NamedUnit next to its table. Names only need to be unique within one registry, so "m" can be both metre (units) and milli (prefixes). Host-only: unlike Unit.hpp this uses the standard library and exceptions.

Definition in file registry.hpp.

Function Documentation

◆ find_named()

const NamedUnit * shamunits::details::find_named ( std::span< const NamedUnit > registry,
std::string_view name )
constexprnoexcept

Entry whose long or short name is name, or nullptr.

Definition at line 47 of file registry.hpp.

◆ names_are_valid()

bool shamunits::details::names_are_valid ( std::span< const NamedUnit > registry)
constexprnoexcept

True when no name is empty and no name appears twice, long and short names together.

Definition at line 70 of file registry.hpp.

◆ unit_from_name()

Unit shamunits::details::unit_from_name ( std::span< const NamedUnit > registry,
std::string_view name,
std::string_view kind = "unit" )
inline

Unit named name in registry; throws std::invalid_argument when unknown.

Definition at line 58 of file registry.hpp.