1#ifndef GENERIC_MAPPER_H
2#define GENERIC_MAPPER_H
87template<
class Tag,
class EnumT,
88 const std::map<EnumT, std::string>& (*MapFn)()>
96 static bool& inited();
99 static void ensure_init();
184 static bool register_custom(std::string canonical, std::vector<std::string> aliases={});
215 static std::string
str(EnumT e);
269template<
class Tag,
class EnumT,
class ExternalKey,
class Hash,
270 const std::map<EnumT, std::string>& (*MapFn)(),
271 const std::map<EnumT, ExternalKey>& (*ExtFn)()>
279 static bool& inited();
282 static void ensure_init();
386 static bool register_custom(std::string canonical, std::vector<std::string> aliases={}, std::optional<ExternalKey> ext=std::nullopt);
428 static std::string
str(EnumT e);
453#include "generic_mapper.tpp"
Static mappings between enum classes and string (or FLHA) identifiers.
Case-insensitive registry of SymbolId entries without external keys.
Case-insensitive registry of SymbolId entries with optional external keys.
Generic enum↔string mapper without external keys.
static bool register_custom(std::string canonical, std::vector< std::string > aliases={})
Registers a custom (non-builtin) entry in the registry.
static EnumT enum_elt_legacy(std::string_view s)
Legacy enum lookup using only the static MapFn() table.
static std::string str(EnumT e)
Returns the builtin string name corresponding to an enum value.
static std::vector< std::string > get_str_all()
Returns all known names: builtin and custom.
static std::vector< EnumT > get_enum()
Returns the list of builtin enum values from MapFn().
static void init_builtins()
Explicitly initializes builtin entries.
static std::vector< std::string > get_str()
Returns the list of builtin string names from MapFn().
static IdOf< Tag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.
static std::vector< IdOf< Tag > > list_all()
Lists all distinct IdOf<Tag> entries in the registry.
static std::string str(const IdOf< Tag > &id)
Returns the string representation associated with an identifier.
static std::optional< EnumT > enum_of(const IdOf< Tag > &id)
Attempts to recover the enum value associated with an identifier.
static IdOf< Tag > to_id(EnumT e)
Converts an enum value to an IdOf<Tag>.
static IdOf< Tag > enum_elt(std::string_view s)
Alias for id_of(), kept for compatibility.
Generic enum↔string mapper with external keys and dynamic aliases.
static void init_builtins()
Explicitly initializes builtin entries.
static bool register_custom(std::string canonical, std::vector< std::string > aliases={}, std::optional< ExternalKey > ext=std::nullopt)
Registers a custom entry with optional external key.
static std::vector< IdOf< Tag > > list_all()
Lists all distinct identifiers currently registered.
static EnumT enum_elt_legacy(std::string_view s)
Legacy enum lookup using only the static MapFn() table.
static std::vector< EnumT > get_enum()
Returns the list of builtin enum values.
static std::optional< ExternalKey > external_of(const IdOf< Tag > &id)
Returns the external key associated with a given identifier.
static std::optional< EnumT > enum_of(const IdOf< Tag > &id)
Attempts to recover the enum value associated with an identifier.
static std::string str(EnumT e)
Returns the builtin string name of an enum value.
static std::vector< std::string > get_str()
Returns the list of builtin string names from MapFn().
static IdOf< Tag > enum_elt(std::string_view s)
Alias for id_of(), kept for compatibility.
static std::vector< std::string > get_str_all()
Returns all known names (builtin + custom).
static std::optional< IdOf< Tag > > from_external(const ExternalKey &k)
Resolves an external key into an identifier.
static IdOf< Tag > to_id(EnumT e)
Converts an enum value to an IdOf<Tag>.
static bool set_external(const IdOf< Tag > &id, const ExternalKey &k)
Sets or updates the external key of an existing identifier.
static IdOf< Tag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.
static std::string str(const IdOf< Tag > &id)
Returns the string representation of an identifier.
Returns an uppercase copy of the input string.
std::string normalize_key(std::string_view s)
Normalizes a string key in a case-insensitive manner.
std::string nk(std::string_view s)
Shortcut helper to normalize a string_view into a canonical key.