Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
GenericMapperNoExt< Tag, EnumT, MapFn > Class Template Reference

Generic enum↔string mapper without external keys. More...

#include <generic_mapper.h>

Static Public Member Functions

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.
 

Detailed Description

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:

// Suppose observable_mapping() returns const std::map<Observables,std::string>&
struct ObsTag {};
auto names = ObsMapper::get_str(); // builtin names
auto all = ObsMapper::get_str_all(); // builtin + custom names
auto id = ObsMapper::id_of("BR(B->Kll)"); // lookup by name (case-insensitive)
auto s = ObsMapper::str(Observables::SomeObs);
Generic enum↔string mapper without external keys.
Template Parameters
TagTag used for the associated SymbolId<Tag>.
EnumTEnum type being mapped.
MapFnFunction returning the builtin map EnumT→std::string.

Definition at line 89 of file generic_mapper.h.

Member Function Documentation

◆ enum_elt()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static IdOf< Tag > GenericMapperNoExt< Tag, EnumT, MapFn >::enum_elt ( std::string_view  s)
static

Alias for id_of(), kept for compatibility.

Parameters
sName or alias to look up.
Returns
Corresponding IdOf<Tag>.

◆ enum_elt_legacy()

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
sName to look up (case-insensitive).
Returns
Matching EnumT value.
Exceptions
std::out_of_rangeif no matching enum value is found.

◆ enum_of()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::optional< EnumT > GenericMapperNoExt< Tag, EnumT, MapFn >::enum_of ( const IdOf< Tag > &  id)
static

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
idIdentifier to decode.
Returns
Matching EnumT if found, std::nullopt otherwise.

◆ get_enum()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::vector< EnumT > GenericMapperNoExt< Tag, EnumT, MapFn >::get_enum ( )
static

Returns the list of builtin enum values from MapFn().

Returns
Vector of EnumT values as defined in the static map.

◆ get_str()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::vector< std::string > GenericMapperNoExt< Tag, EnumT, MapFn >::get_str ( )
static

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.

◆ get_str_all()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::vector< std::string > GenericMapperNoExt< Tag, EnumT, MapFn >::get_str_all ( )
static

Returns all known names: builtin and custom.

This triggers initialization and then queries the underlying DynamicRegistry for all registered identifiers.

Returns
Vector of all distinct identifier strings.

◆ id_of()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static IdOf< Tag > GenericMapperNoExt< Tag, EnumT, MapFn >::id_of ( std::string_view  s)
static

Resolves a string into an IdOf<Tag> via the registry.

The lookup is case-insensitive and includes both builtin and custom-registered entries.

Parameters
sName or alias to look up.
Returns
Corresponding IdOf<Tag>.
Exceptions
std::runtime_errorif the name is unknown to the registry.

◆ init_builtins()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static void GenericMapperNoExt< Tag, EnumT, MapFn >::init_builtins ( )
static

Explicitly initializes builtin entries.

This simply forwards to ensure_init(). It can be used at startup to populate the registry eagerly instead of lazily.

◆ list_all()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::vector< IdOf< Tag > > GenericMapperNoExt< Tag, EnumT, MapFn >::list_all ( )
static

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>.

◆ register_custom()

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
canonicalCanonical name for the new identifier.
aliasesOptional list of aliases for lookup.
Returns
true if registration succeeded, false if blocked by a builtin entry with the same canonical name.

◆ str() [1/2]

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::string GenericMapperNoExt< Tag, EnumT, MapFn >::str ( const IdOf< Tag > &  id)
static

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
idIdentifier.
Returns
String representation of id.

◆ str() [2/2]

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static std::string GenericMapperNoExt< Tag, EnumT, MapFn >::str ( EnumT  e)
static

Returns the builtin string name corresponding to an enum value.

Parameters
eEnum value.
Returns
Corresponding string name from MapFn().
Exceptions
std::out_of_rangeif e is not present in the static map.

◆ to_id()

template<class Tag , class EnumT , const std::map< EnumT, std::string > &(*)() MapFn>
static IdOf< Tag > GenericMapperNoExt< Tag, EnumT, MapFn >::to_id ( EnumT  e)
static

Converts an enum value to an IdOf<Tag>.

The resulting identifier wraps the builtin string name obtained from MapFn().at(e).

Parameters
eEnum value.
Returns
Corresponding IdOf<Tag>.

The documentation for this class was generated from the following file: