|
| static void | init_builtins () |
| | Explicitly initializes builtin entries.
|
| |
| static EnumT | enum_elt_legacy (std::string_view s) |
| | Legacy enum lookup using only the static MapFn() table.
|
| |
| static std::vector< std::string > | get_str () |
| | Returns the list of builtin string names from MapFn().
|
| |
| static std::vector< EnumT > | get_enum () |
| | Returns the list of builtin enum values from MapFn().
|
| |
| static std::vector< std::string > | get_str_all () |
| | Returns all known names: builtin and custom.
|
| |
| static IdOf< Tag > | id_of (std::string_view s) |
| | Resolves a string into an IdOf<Tag> via the registry.
|
| |
| static IdOf< Tag > | enum_elt (std::string_view s) |
| | Alias for id_of(), kept for compatibility.
|
| |
| static bool | register_custom (std::string canonical, std::vector< std::string > aliases={}) |
| | Registers a custom (non-builtin) entry in 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::string | str (EnumT e) |
| | Returns the builtin string name corresponding to an enum value.
|
| |
| static IdOf< Tag > | to_id (EnumT e) |
| | Converts an enum value to an IdOf<Tag>.
|
| |
| static std::optional< EnumT > | enum_of (const IdOf< Tag > &id) |
| | Attempts to recover the enum value associated with an identifier.
|
| |
template<class Tag, class EnumT, const std::map< EnumT, std::string > &(*)() MapFn>
class GenericMapperNoExt< Tag, EnumT, MapFn >
Generic enum↔string mapper without external keys.
This template provides a high-level interface to:
- expose builtin mappings between EnumT and std::string (via MapFn),
- support case-insensitive lookups,
- register additional user-defined symbols and aliases at runtime,
- map back and forth between EnumT and SymbolId<Tag>.
Initialization:
- Builtins are registered lazily on first use via ensure_init(), which reads the map returned by MapFn() and inserts entries into an internal DynamicRegistry<Tag, void, void>.
- init_builtins() can be called explicitly to force initialization.
Typical usage pattern:
struct ObsTag {};
auto names = ObsMapper::get_str();
auto all = ObsMapper::get_str_all();
auto id = ObsMapper::id_of("BR(B->Kll)");
auto s = ObsMapper::str(Observables::SomeObs);
Generic enum↔string mapper without external keys.
- Template Parameters
-
| Tag | Tag used for the associated SymbolId<Tag>. |
| EnumT | Enum type being mapped. |
| MapFn | Function returning the builtin map EnumT→std::string. |
Definition at line 89 of file generic_mapper.h.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
| static EnumT GenericMapperNoExt< Tag, EnumT, MapFn >::enum_elt_legacy |
( |
std::string_view |
s | ) |
|
|
static |
Legacy enum lookup using only the static MapFn() table.
This function emulates the pre-registry behavior by scanning the map returned by MapFn() and matching against the normalized key. It does not consult the dynamic registry and therefore ignores custom registrations.
- Parameters
-
| s | Name to look up (case-insensitive). |
- Returns
- Matching EnumT value.
- Exceptions
-
| std::out_of_range | if no matching enum value is found. |
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Attempts to recover the enum value associated with an identifier.
The identifier's string is normalized and compared against the builtin names from MapFn(). This does not consult the dynamic registry, so only builtin names are considered.
- Parameters
-
- Returns
- Matching EnumT if found, std::nullopt otherwise.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Returns the list of builtin string names from MapFn().
Only entries in the static map are returned; custom/user-defined aliases are not included.
- Returns
- Vector of builtin names.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Resolves a string into an IdOf<Tag> via the registry.
The lookup is case-insensitive and includes both builtin and custom-registered entries.
- Parameters
-
| s | Name or alias to look up. |
- Returns
- Corresponding IdOf<Tag>.
- Exceptions
-
| std::runtime_error | if the name is unknown to the registry. |
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Explicitly initializes builtin entries.
This simply forwards to ensure_init(). It can be used at startup to populate the registry eagerly instead of lazily.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Lists all distinct IdOf<Tag> entries in the registry.
This includes both builtin and custom entries, each appearing only once even if it has multiple aliases.
- Returns
- Vector of IdOf<Tag>.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
| static bool GenericMapperNoExt< Tag, EnumT, MapFn >::register_custom |
( |
std::string |
canonical, |
|
|
std::vector< std::string > |
aliases = {} |
|
) |
| |
|
static |
Registers a custom (non-builtin) entry in the registry.
The canonical name is stored as the primary identifier, and the supplied aliases are also registered as case-insensitive keys mapping to the same IdOf<Tag>.
- Parameters
-
| canonical | Canonical name for the new identifier. |
| aliases | Optional list of aliases for lookup. |
- Returns
- true if registration succeeded, false if blocked by a builtin entry with the same canonical name.
template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
Returns the string representation associated with an identifier.
This simply returns id.str(), i.e. the underlying canonical name stored in the SymbolId<Tag>.
- Parameters
-
- Returns
- String representation of
id.