Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
generic_mapper.h
Go to the documentation of this file.
1#ifndef GENERIC_MAPPER_H
2#define GENERIC_MAPPER_H
3
4#include <map>
5#include <optional>
6#include <string_view>
7#include <vector>
8#include "dynamic_registry.h"
9#include "Map.h"
10
34// Utility
40template<class Tag>
42
51inline std::string nk(std::string_view s){ return normalize_key(s); }
52
53// ------------------------------ Without External Keys ------------------------------
54
87template<class Tag, class EnumT,
88 const std::map<EnumT, std::string>& (*MapFn)()>
91
93 static Reg& reg();
94
96 static bool& inited();
97
99 static void ensure_init();
100public:
107 static void init_builtins();
108
122 static EnumT enum_elt_legacy(std::string_view s);
123
132 static std::vector<std::string> get_str();
133
139 static std::vector<EnumT> get_enum();
140
149 static std::vector<std::string> get_str_all();
150
162 static IdOf<Tag> id_of(std::string_view s);
163
170 static IdOf<Tag> enum_elt(std::string_view s);
171
184 static bool register_custom(std::string canonical, std::vector<std::string> aliases={});
185
194 static std::vector<IdOf<Tag>> list_all();
195
205 static std::string str(const IdOf<Tag>& id);
206
215 static std::string str(EnumT e);
216
226 static IdOf<Tag> to_id(EnumT e);
227
238 static std::optional<EnumT> enum_of(const IdOf<Tag>& id);
239};
240
241// ------------------------------ With External Keys ------------------------------
242
269template<class Tag, class EnumT, class ExternalKey, class Hash,
270 const std::map<EnumT, std::string>& (*MapFn)(),
271 const std::map<EnumT, ExternalKey>& (*ExtFn)()>
274
276 static Reg& reg();
277
279 static bool& inited();
280
282 static void ensure_init();
283public:
290 static void init_builtins();
291
300 static std::vector<std::string> get_str();
301
307 static std::vector<EnumT> get_enum();
308
317 static std::vector<std::string> get_str_all();
318
330 static EnumT enum_elt_legacy(std::string_view s);
331
332
344 static IdOf<Tag> id_of(std::string_view s);
345
352 static IdOf<Tag> enum_elt(std::string_view s);
353
363 static std::optional<IdOf<Tag>> from_external(const ExternalKey& k);
364
371 static std::optional<ExternalKey> external_of(const IdOf<Tag>& id);
372
386 static bool register_custom(std::string canonical, std::vector<std::string> aliases={}, std::optional<ExternalKey> ext=std::nullopt);
387
398 static bool set_external(const IdOf<Tag>& id, const ExternalKey& k);
399
408 static std::vector<IdOf<Tag>> list_all();
409
418 static std::string str(const IdOf<Tag>& id);
419
428 static std::string str(EnumT e);
429
438 static IdOf<Tag> to_id(EnumT e);
439
450 static std::optional<EnumT> enum_of(const IdOf<Tag>& id);
451};
452
453#include "generic_mapper.tpp"
454
455#endif
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.