Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
EnumMapper.h
Go to the documentation of this file.
1#ifndef ENUM_MAPPER_H
2#define ENUM_MAPPER_H
3
4#include <map>
5#include <string>
6#include <vector>
7
46template <typename Enum, typename Derived>
48public:
60 static std::string str(Enum e) {
61 return Derived::mapping().at(e);
62 }
63
76 static Enum enum_elt(const std::string& name) {
77 return Derived::inverse_mapping().at(name);
78 }
79
88 static std::vector<std::string> get_str() {
89 std::vector<std::string> out;
90 for (const auto& [key, val] : Derived::mapping()) {
91 out.push_back(val);
92 }
93 return out;
94 }
95
104 static std::vector<Enum> get_enum() {
105 std::vector<Enum> out;
106 for (const auto& [key, val] : Derived::mapping()) {
107 out.push_back(key);
108 }
109 return out;
110 }
111};
112
130template <typename K, typename V>
131std::map<V, K> invert_map(const std::map<K, V>& original) {
132 std::map<V, K> inv;
133 for (const auto& [k, v] : original) {
134 inv[v] = k;
135 }
136 return inv;
137}
138
139#endif
std::map< V, K > invert_map(const std::map< K, V > &original)
Builds the inverse of a std::map by swapping keys and values.
Definition EnumMapper.h:131
CRTP base class for enum–string mappers.
Definition EnumMapper.h:47
static std::vector< std::string > get_str()
Returns all string representations defined in the mapping.
Definition EnumMapper.h:88
static Enum enum_elt(const std::string &name)
Returns the enum value associated to a given string.
Definition EnumMapper.h:76
static std::string str(Enum e)
Returns the string representation of an enum value.
Definition EnumMapper.h:60
static std::vector< Enum > get_enum()
Returns all enum values defined in the mapping.
Definition EnumMapper.h:104