gtopt::NamesRegistry class

Public static functions

static auto instance() -> const NamesRegistry&

Constructors, destructors, conversion operators

NamesRegistry(const std::filesystem::path& json_path) explicit
Construct from a JSON file. Throws on read or parse error.
NamesRegistry(std::string_view json_content) explicit

Public functions

auto alias_for(std::string_view canonical, std::string_view dialect) const -> std::optional<std::string_view> noexcept
auto canonical_for(std::string_view alias) const -> std::optional<std::string_view> noexcept
auto canonical_for(std::string_view class_name, std::string_view alias) const -> std::optional<std::string_view> noexcept
auto canonical_to_aliases() const -> const gtopt::flat_map<std::string, std::vector<std::string>>& noexcept
auto dialect_for(std::string_view alias) const -> std::optional<std::string_view> noexcept
auto is_deprecated(std::string_view alias) const -> bool noexcept
auto size() const -> std::size_t noexcept
auto source_path() const -> const std::optional<std::filesystem::path>& noexcept

Function documentation

static const NamesRegistry& gtopt::NamesRegistry::instance()

Get the process-wide singleton, lazily loaded on first call. Lookups against the returned reference are thread-safe (the map is const after construction).

gtopt::NamesRegistry::NamesRegistry(std::string_view json_content) explicit

Construct from an explicit JSON string (used by tests and for the instance() boot path). Throws on parse error.

std::optional<std::string_view> gtopt::NamesRegistry::alias_for(std::string_view canonical, std::string_view dialect) const noexcept

Inverse lookup: find the alias from dialect that maps to the given canonical name. Returns nullopt when no entry matches — the caller should keep the canonical name unchanged on output. Used by the output JSON rewrite under --naming-dialect.

std::optional<std::string_view> gtopt::NamesRegistry::canonical_for(std::string_view alias) const noexcept

Resolve a global alias to its canonical name. Returns nullopt if alias is not a registered global alias (which includes the case where alias is itself already a canonical name). Class-scoped aliases are not consulted by this overload — use the (class, alias) overload below from element-typed resolution paths. This overload is used by canonicalize_json_keys (which has no element-type context).

std::optional<std::string_view> gtopt::NamesRegistry::canonical_for(std::string_view class_name, std::string_view alias) const noexcept

Resolve an alias scoped to a specific element class ("generator", "flow_right", …). Looks up the class-scoped table first (class_aliases[] in naming_dialects.json), then falls back to the global table. Used by resolve_single_param where the element class is known and aliases like discharge (canonical for flow, legacy for flow_right.target) need class-aware disambiguation.

const gtopt::flat_map<std::string, std::vector<std::string>>& gtopt::NamesRegistry::canonical_to_aliases() const noexcept

Returns the (canonical -> {aliases}) inverse view for global aliases. Used for diagnostics (e.g. --list-dialects). Class-scoped aliases are not included.

std::optional<std::string_view> gtopt::NamesRegistry::dialect_for(std::string_view alias) const noexcept

Look up the source dialect tag of a given alias (the dialect field on the entry in naming_dialects.json). Returns nullopt when the alias is unknown or its dialect tag was empty. Used by the input warn pass to flag mixed-dialect input under --naming-dialect.

bool gtopt::NamesRegistry::is_deprecated(std::string_view alias) const noexcept

True when alias is a global alias flagged "deprecated": true in naming_dialects.json — a renamed gtopt key kept only for back-compat. canonicalize_json_keys warns once per such alias and rejects an object that sets both it and its canonical key.

std::size_t gtopt::NamesRegistry::size() const noexcept

Number of (alias, canonical) entries. Useful for diagnostics and tests.

const std::optional<std::filesystem::path>& gtopt::NamesRegistry::source_path() const noexcept

Path the registry was loaded from, or nullopt if loaded from the built-in fallback or an explicit JSON string.