NEML2 1.4.0
Loading...
Searching...
No Matches
EnumSelection 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 <EnumSelection.h>

Public Member Functions

 EnumSelection ()=default
 
 EnumSelection (const EnumSelection &other)
 
 EnumSelection (const std::vector< std::string > &candidates, const std::string &selection)
 
 EnumSelection (const std::vector< std::string > &candidates, const std::vector< int > &values, const std::string &selection)
 
EnumSelectionoperator= (const EnumSelection &other)
 Assignment operator.
 
bool operator== (const EnumSelection &other) const
 Test for inequality.
 
bool operator!= (const EnumSelection &other) const
 Test for inequality.
 
 operator std::string () const
 Poor man's reflection implementation.
 
 operator int () const
 Implicit conversion to int to let it behave more like a enum.
 
const std::unordered_map< std::string, int > & candidates () const
 Candidates.
 
std::string candidates_str () const
 Stringified candidates.
 
template<typename T >
as () const
 Statically cast the enum value to a C++ enum class.
 

Friends

std::stringstream & operator>> (std::stringstream &ss, EnumSelection &)
 

Constructor & Destructor Documentation

◆ EnumSelection() [1/4]

EnumSelection ( )
default

◆ EnumSelection() [2/4]

◆ EnumSelection() [3/4]

EnumSelection ( const std::vector< std::string > & candidates,
const std::string & selection )

◆ EnumSelection() [4/4]

EnumSelection ( const std::vector< std::string > & candidates,
const std::vector< int > & values,
const std::string & selection )

Member Function Documentation

◆ as()

template<typename T >
T as ( ) const
inline

Statically cast the enum value to a C++ enum class.

◆ candidates()

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

Candidates.

◆ candidates_str()

std::string candidates_str ( ) const

Stringified candidates.

◆ operator int()

operator int ( ) const
inline

Implicit conversion to int to let it behave more like a enum.

◆ operator std::string()

operator std::string ( ) const
inline

Poor man's reflection implementation.

◆ operator!=()

bool operator!= ( const EnumSelection & other) const

Test for inequality.

◆ operator=()

Assignment operator.

◆ operator==()

bool operator== ( const EnumSelection & other) const

Test for inequality.

Friends And Related Symbol Documentation

◆ operator>>

std::stringstream & operator>> ( std::stringstream & ss,
EnumSelection &  )
friend

The input stream operator shall be the only entry point to modify the selection other than the assignment operator