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

Case-insensitive registry of SymbolId entries with optional external keys. More...

#include <dynamic_registry.h>

Classes

struct  Entry
 Entry stored in the registry. More...
 

Public Member Functions

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::optional< SymbolId< Tag > > find (std::string_view name) const
 Finds an identifier by name (or alias), case-insensitively.
 
std::optional< SymbolId< Tag > > find_by_external (const ExternalKey &k) const
 Finds an identifier by external key.
 
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::vector< SymbolId< Tag > > list_all () const
 Lists all distinct identifiers stored in the registry.
 

Detailed Description

template<class Tag, class ExternalKey, class Hash = std::hash<ExternalKey>>
class DynamicRegistry< Tag, ExternalKey, Hash >

Case-insensitive registry of SymbolId entries with optional external keys.

The primary template manages:

  • a mapping from normalized string names (and aliases) to Entry objects,
  • an optional mapping from external keys (e.g. integer codes) to names.

Typical usage:

struct MyTag {};
using MyId = SymbolId<MyTag>;
using MyRegistry = DynamicRegistry<MyTag, int>;
MyRegistry reg;
reg.register_id(MyId{"Foo"}, {"foo", "FOO"}, 42, true);
auto id = reg.find("fOo"); // returns MyId{"Foo"}
auto id2 = reg.find_by_external(42);
Case-insensitive registry of SymbolId entries with optional external keys.
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.
Returns an uppercase copy of the input string.

Builtin entries can be protected against being overridden by later registrations.

Template Parameters
TagTag used for the SymbolId type.
ExternalKeyType of the external key (e.g. int, std::string).
HashHash functor type used for ExternalKey.

Definition at line 201 of file dynamic_registry.h.

Member Function Documentation

◆ external_of()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
std::optional< ExternalKey > DynamicRegistry< Tag, ExternalKey, Hash >::external_of ( const SymbolId< Tag > &  id) const

Returns the external key associated with a given identifier.

Parameters
idSymbolId to query.
Returns
The associated external key, or std::nullopt if none.

◆ find()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
std::optional< SymbolId< Tag > > DynamicRegistry< Tag, ExternalKey, Hash >::find ( std::string_view  name) const

Finds an identifier by name (or alias), case-insensitively.

The input name is normalized via normalize_key() and looked up in the internal map. If found, the corresponding SymbolId<Tag> is returned.

Parameters
nameName or alias to search for.
Returns
The corresponding SymbolId<Tag>, or std::nullopt if not found.

◆ find_by_external()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
std::optional< SymbolId< Tag > > DynamicRegistry< Tag, ExternalKey, Hash >::find_by_external ( const ExternalKey &  k) const

Finds an identifier by external key.

Looks up k in the external-key map and then resolves the associated canonical name to retrieve the SymbolId<Tag>.

Parameters
kExternal key value.
Returns
The corresponding SymbolId<Tag>, or std::nullopt if not found.

◆ list_all()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
std::vector< SymbolId< Tag > > DynamicRegistry< Tag, ExternalKey, Hash >::list_all ( ) const

Lists all distinct identifiers stored in the registry.

The registry may contain multiple entries for different aliases pointing to the same canonical id. This function returns each distinct canonical id exactly once.

Returns
Vector of all unique SymbolId<Tag> values.

◆ register_id()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
bool DynamicRegistry< Tag, ExternalKey, Hash >::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.

The given id is inserted with the provided aliases and optional external key. The canonical map key is normalize_key(id.str()).

Behavior:

  • If the canonical name does not exist yet, a new entry is created.
  • If it exists and is marked as builtin, the registration fails and the function returns false.
  • Otherwise, the existing entry is replaced.
  • All aliases are also indexed (case-insensitive), pointing to the same Entry, unless they belong to a builtin entry that should not be overwritten.
  • If an external key is provided, it is registered in by_ext_.
Parameters
idIdentifier to register.
aliasesList of aliases for lookup.
extOptional external key to associate.
builtinWhether this is a builtin entry (protected).
Returns
true if the registration succeeded, false if blocked by an existing builtin entry.

◆ update_external()

template<class Tag , class ExternalKey , class Hash = std::hash<ExternalKey>>
bool DynamicRegistry< Tag, ExternalKey, Hash >::update_external ( const SymbolId< Tag > &  id,
const ExternalKey &  k 
)

Updates or sets the external key of a given identifier.

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

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

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