Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
EnumMapperBase< Enum, Derived > Class Template Reference

CRTP base class for enum–string mappers. More...

#include <EnumMapper.h>

Static Public Member Functions

static std::string str (Enum e)
 Returns the string representation of an enum value.
 
static Enum enum_elt (const std::string &name)
 Returns the enum value associated to a given string.
 
static std::vector< std::string > get_str ()
 Returns all string representations defined in the mapping.
 
static std::vector< Enum > get_enum ()
 Returns all enum values defined in the mapping.
 

Detailed Description

template<typename Enum, typename Derived>
class EnumMapperBase< Enum, Derived >

CRTP base class for enum–string mappers.

This template implements a small set of convenience functions relying on a Derived class that must provide:

  • static const std::map<Enum, std::string>& mapping();
  • static const std::map<std::string, Enum>& inverse_mapping();

The design is based on CRTP (Curiously Recurring Template Pattern): struct MyEnumMap : EnumMapperBase<MyEnum, MyEnumMap> { ... };

The implementation assumes that:

  • mapping() returns an ordered map that is stable across calls,
  • inverse_mapping() is consistent with mapping(), typically built via invert_map(mapping()).
Template Parameters
EnumEnum type being mapped.
DerivedCRTP derived type implementing mapping() / inverse_mapping().

Definition at line 47 of file EnumMapper.h.

Member Function Documentation

◆ enum_elt()

template<typename Enum , typename Derived >
static Enum EnumMapperBase< Enum, Derived >::enum_elt ( const std::string &  name)
inlinestatic

Returns the enum value associated to a given string.

This function forwards to Derived::inverse_mapping().at(name). If name is not present in the inverse mapping, std::out_of_range is thrown.

Parameters
nameString representation of the enum value.
Returns
Corresponding enum value.
Exceptions
std::out_of_rangeif the string is not in the inverse mapping.

Definition at line 76 of file EnumMapper.h.

◆ get_enum()

template<typename Enum , typename Derived >
static std::vector< Enum > EnumMapperBase< Enum, Derived >::get_enum ( )
inlinestatic

Returns all enum values defined in the mapping.

The enum values are returned in the iteration order of Derived::mapping(), i.e. the key order of the underlying std::map<Enum, std::string>.

Returns
Vector containing all mapped enum values.

Definition at line 104 of file EnumMapper.h.

◆ get_str()

template<typename Enum , typename Derived >
static std::vector< std::string > EnumMapperBase< Enum, Derived >::get_str ( )
inlinestatic

Returns all string representations defined in the mapping.

The strings are returned in the iteration order of Derived::mapping(), which is the key order of the underlying std::map<Enum, std::string>.

Returns
Vector containing all mapped strings.

Definition at line 88 of file EnumMapper.h.

◆ str()

template<typename Enum , typename Derived >
static std::string EnumMapperBase< Enum, Derived >::str ( Enum  e)
inlinestatic

Returns the string representation of an enum value.

This function simply forwards to Derived::mapping().at(e). If e is not present in the mapping, std::out_of_range is thrown.

Parameters
eEnum value to convert.
Returns
Corresponding string name.
Exceptions
std::out_of_rangeif the enum value is not in the mapping.

Definition at line 60 of file EnumMapper.h.


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