NEML2 2.0.0
Loading...
Searching...
No Matches
EnumSelectionBase Class Reference

Detailed Description

Our poor man's implementation of enum reflection. This is a necessary ingredient for bridging runtime string parsed from input files and static enum types.

For developers, this class shall only be used for parsing purposes during the setup phase. Avoid directly working with this class at model evaluation phase at all cost!

#include <EnumSelectionBase.h>

Inheritance diagram for EnumSelectionBase:

Public Member Functions

 EnumSelectionBase ()=default
 
 EnumSelectionBase (const std::vector< std::string > &choices)
 Create an enum selection from a list of choices.
 
 EnumSelectionBase (const std::vector< std::string > &choices, const std::vector< int > &values)
 Create an enum selection from a list of choices and their corresponding values.
 
const std::unordered_map< std::string, int > & choices () const
 Choices.
 
std::string join (const std::string &separator=", ") const
 Join the choices into a single string with the given separator.
 

Protected Attributes

std::unordered_map< std::string, int > _choice_map
 Mapping enum options to int.
 

Constructor & Destructor Documentation

◆ EnumSelectionBase() [1/3]

EnumSelectionBase ( )
default

◆ EnumSelectionBase() [2/3]

EnumSelectionBase ( const std::vector< std::string > & choices)

Create an enum selection from a list of choices.

◆ EnumSelectionBase() [3/3]

EnumSelectionBase ( const std::vector< std::string > & choices,
const std::vector< int > & values )

Create an enum selection from a list of choices and their corresponding values.

Member Function Documentation

◆ choices()

const std::unordered_map< std::string, int > & choices ( ) const
inline

Choices.

◆ join()

std::string join ( const std::string & separator = ", ") const

Join the choices into a single string with the given separator.

Member Data Documentation

◆ _choice_map

std::unordered_map<std::string, int> _choice_map
protected

Mapping enum options to int.