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

Generic enum↔string mapper with external keys and dynamic aliases. More...

#include <generic_mapper.h>

Static Public Member Functions

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 std::vector< EnumT > get_enum ()
 Returns the list of builtin enum values.
 
static std::vector< std::string > get_str_all ()
 Returns all known names (builtin + custom).
 
static EnumT enum_elt_legacy (std::string_view s)
 Legacy enum lookup using only the static MapFn() table.
 
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 std::optional< IdOf< Tag > > from_external (const ExternalKey &k)
 Resolves an external key into an identifier.
 
static std::optional< ExternalKey > external_of (const IdOf< Tag > &id)
 Returns the external key associated with a given identifier.
 
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 bool set_external (const IdOf< Tag > &id, const ExternalKey &k)
 Sets or updates the external key of an existing identifier.
 
static std::vector< IdOf< Tag > > list_all ()
 Lists all distinct identifiers currently registered.
 
static std::string str (const IdOf< Tag > &id)
 Returns the string representation of an identifier.
 
static std::string str (EnumT e)
 Returns the builtin string name of 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, class ExternalKey, class Hash, const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
class GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >

Generic enum↔string mapper with external keys and dynamic aliases.

This template extends GenericMapperNoExt by adding support for an "external key" (ExternalKey), which can be used to represent e.g. FLHA indices, integer codes, or other external identifiers.

Initialization:

  • Builtin entries are created from the map returned by MapFn() and the external-key map returned by ExtFn().
  • Each EnumT value is mapped to a canonical name and optionally to an external key, stored in a DynamicRegistry<Tag,ExternalKey,Hash>.

Features:

  • Bidirectional mapping between EnumT and IdOf<Tag>.
  • Bidirectional mapping between external keys and IdOf<Tag>.
  • Case-insensitive lookup and dynamic alias registration.
Template Parameters
TagTag used for SymbolId<Tag>.
EnumTEnum type to map.
ExternalKeyType for the external key.
HashHash functor for ExternalKey in unordered_map.
MapFnFunction returning builtin EnumT→std::string map.
ExtFnFunction returning EnumT→ExternalKey map.

Definition at line 272 of file generic_mapper.h.

Member Function Documentation

◆ enum_elt()

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

Alias for id_of(), kept for compatibility.

Parameters
sName or alias.
Returns
Corresponding IdOf<Tag>.

◆ enum_elt_legacy()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static EnumT GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::enum_elt_legacy ( std::string_view  s)
static

Legacy enum lookup using only the static MapFn() table.

As in GenericMapperNoExt::enum_elt_legacy, this scans the static map and ignores custom registrations and external keys.

Parameters
sName to look up (case-insensitive).
Returns
Matching EnumT value.
Exceptions
std::out_of_rangeif no match is found.

◆ enum_of()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static std::optional< EnumT > GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::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 in 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.

◆ external_of()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static std::optional< ExternalKey > GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::external_of ( const IdOf< Tag > &  id)
static

Returns the external key associated with a given identifier.

Parameters
idIdentifier to query.
Returns
Matching ExternalKey if present, std::nullopt otherwise.

◆ from_external()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static std::optional< IdOf< Tag > > GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::from_external ( const ExternalKey &  k)
static

Resolves an external key into an identifier.

Uses the registry's external-key index to find the canonical identifier associated with k.

Parameters
kExternal key to look up.
Returns
Matching IdOf<Tag>, or std::nullopt if none.

◆ get_enum()

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

Returns the list of builtin enum values.

Returns
Vector of EnumT values from MapFn().

◆ get_str()

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

Returns the list of builtin string names from MapFn().

Only the static mapping is consulted; dynamic/custom entries are not included.

Returns
Vector of builtin names.

◆ get_str_all()

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

Returns all known names (builtin + custom).

This triggers initialization and then enumerates the registry to collect all identifier strings.

Returns
Vector of all identifier names.

◆ id_of()

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

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

The lookup is case-insensitive and takes into account builtin and custom aliases.

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

◆ init_builtins()

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

Explicitly initializes builtin entries.

Populates the registry from the static maps provided by MapFn() and ExtFn() if not already initialized.

◆ list_all()

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

Lists all distinct identifiers currently registered.

Includes both builtin and custom entries; each canonical id is returned once, regardless of the number of aliases.

Returns
Vector of IdOf<Tag>.

◆ register_custom()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static bool GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::register_custom ( std::string  canonical,
std::vector< std::string >  aliases = {},
std::optional< ExternalKey >  ext = std::nullopt 
)
static

Registers a custom entry with optional external key.

Similar to register_custom() in GenericMapperNoExt, but also allows attaching an external key that participates in from_external()/external_of() mappings.

Parameters
canonicalCanonical name for the identifier.
aliasesOptional aliases for lookup.
extOptional external key to associate.
Returns
true if registration succeeded, false if blocked by an existing builtin entry.

◆ set_external()

template<class Tag , class EnumT , class ExternalKey , class Hash , const std::map< EnumT, std::string > &(*)() MapFn, const std::map< EnumT, ExternalKey > &(*)() ExtFn>
static bool GenericMapperWithExt< Tag, EnumT, ExternalKey, Hash, MapFn, ExtFn >::set_external ( const IdOf< Tag > &  id,
const ExternalKey &  k 
)
static

Sets or updates the external key of an existing identifier.

If the identifier exists in the registry, its external key is set to k and the external-key index updated accordingly.

Parameters
idIdentifier whose external key should be set.
kNew external key value.
Returns
true if the identifier was found and updated, false otherwise.

◆ str() [1/2]

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

Returns the string representation of an identifier.

This simply returns id.str().

Parameters
idIdentifier.
Returns
String representation of id.

◆ str() [2/2]

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

Returns the builtin string name of an enum value.

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

◆ to_id()

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

Converts an enum value to an IdOf<Tag>.

The identifier wraps the builtin string returned by MapFn().at(e).

Parameters
eEnum value.
Returns
Corresponding IdOf<Tag>.

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