1#ifndef DYNAMIC_REGISTRY_H
2#define DYNAMIC_REGISTRY_H
7#include <unordered_map>
72 const std::string&
str()
const {
return name_; }
98 out.reserve(s.size());
99 for (
unsigned char c : s) {
101 out.push_back(
static_cast<char>(std::tolower(c)));
200template<
class Tag,
class ExternalKey,
class Hash = std::hash<ExternalKey>>
215 std::optional<ExternalKey>
ext;
221 std::unordered_map<std::string, Entry> by_name_;
223 std::unordered_map<ExternalKey, std::string, Hash> by_ext_;
250 std::vector<std::string> aliases,
251 std::optional<ExternalKey> ext,
264 std::optional<SymbolId<Tag>>
find(std::string_view name)
const;
346 std::unordered_map<std::string, Entry> by_name_;
364 std::vector<std::string> aliases,
373 std::optional<SymbolId<Tag>>
find(std::string_view name)
const;
386#include "dynamic_registry.tpp"
bool register_id(const SymbolId< Tag > &id, std::vector< std::string > aliases, bool builtin)
Registers or updates an identifier (no external key).
std::vector< SymbolId< Tag > > list_all() const
Lists all distinct identifiers in the registry.
std::optional< SymbolId< Tag > > find(std::string_view name) const
Finds an identifier by name (or alias), case-insensitively.
Case-insensitive registry of SymbolId entries with optional external keys.
std::optional< SymbolId< Tag > > find(std::string_view name) const
Finds an identifier by name (or alias), case-insensitively.
bool register_id(const SymbolId< Tag > &id, std::vector< std::string > aliases, std::optional< ExternalKey > ext, bool builtin)
Registers or updates an identifier in the registry.
std::vector< SymbolId< Tag > > list_all() const
Lists all distinct identifiers stored in the registry.
std::optional< ExternalKey > external_of(const SymbolId< Tag > &id) const
Returns the external key associated with a given identifier.
bool update_external(const SymbolId< Tag > &id, const ExternalKey &k)
Updates or sets the external key of a given identifier.
std::optional< SymbolId< Tag > > find_by_external(const ExternalKey &k) const
Finds an identifier by external key.
Returns an uppercase copy of the input string.
SymbolId(std::string n)
Constructs a SymbolId from a string.
const std::string & str() const
Returns the underlying string.
SymbolId()=default
Default constructor, creates an empty identifier.
bool operator==(const SymbolId< Tag > &a, const SymbolId< Tag > &b) noexcept
Case-insensitive equality comparison for SymbolId<Tag>.
std::string normalize_key(std::string_view s)
Normalizes a string key in a case-insensitive manner.
bool operator<(const SymbolId< Tag > &a, const SymbolId< Tag > &b) noexcept
Case-insensitive strict ordering for SymbolId<Tag>.
Hash specialization for SymbolId<Tag>.
Entry stored in the registry.
std::optional< ExternalKey > ext
Optional external key.
bool builtin
If true, entry cannot be overridden.
std::vector< std::string > aliases
Additional names mapping to this entry.
SymbolId< Tag > id
Canonical identifier.
SymbolId< Tag > id
Canonical identifier.
std::vector< std::string > aliases
Alias names.
size_t operator()(const SymbolId< Tag > &id) const noexcept
Computes the hash value of a SymbolId<Tag>.