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

Selection of an enum value from a list of candidates. More...

Detailed Description

Selection of an enum value from a list of candidates.

See also
neml2::EnumSelectionBase

#include <EnumSelection.h>

Inheritance diagram for EnumSelection:

Public Member Functions

 EnumSelection ()=default
 
 EnumSelection (const std::vector< std::string > &candidates, const std::string &selection)
 Create an enum selection from a list of candidates and a default selection.
 
 EnumSelection (const std::vector< std::string > &candidates, const std::vector< int > &values, const std::string &selection)
 Create an enum selection from a list of candidates, a list of values, and a default selection.
 
void select (const std::string &selection)
 Select a new value.
 
bool operator== (const EnumSelection &other) const
 Test for equality.
 
bool operator!= (const EnumSelection &other) const
 Test for inequality.
 
bool operator== (const std::string &other) const
 Test for selection equality.
 
bool operator!= (const std::string &other) const
 Test for selection 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.
 
template<typename T >
as () const
 Statically cast the enum value to a C++ enum class.
 
- Public Member Functions inherited from EnumSelectionBase
 EnumSelectionBase ()=default
 
 EnumSelectionBase (const std::vector< std::string > &candidates)
 Create an enum selection from a list of candidates.
 
 EnumSelectionBase (const std::vector< std::string > &candidates, const std::vector< int > &values)
 Create an enum selection from a list of candidates and their corresponding values.
 
const std::unordered_map< std::string, int > & candidates () const
 Candidates.
 
std::string candidates_str () const
 Stringified candidates.
 

Additional Inherited Members

- Protected Attributes inherited from EnumSelectionBase
std::unordered_map< std::string, int_candidate_map
 Mapping enum options to int.
 

Constructor & Destructor Documentation

◆ EnumSelection() [1/3]

EnumSelection ( )
default

◆ EnumSelection() [2/3]

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

Create an enum selection from a list of candidates and a default selection.

◆ EnumSelection() [3/3]

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

Create an enum selection from a list of candidates, a list of values, and a default selection.

Member Function Documentation

◆ as()

template<typename T >
T as ( ) const
inline

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

◆ 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!=() [1/2]

bool operator!= ( const EnumSelection & other) const

Test for inequality.

◆ operator!=() [2/2]

bool operator!= ( const std::string & other) const

Test for selection inequality.

◆ operator==() [1/2]

bool operator== ( const EnumSelection & other) const

Test for equality.

◆ operator==() [2/2]

bool operator== ( const std::string & other) const

Test for selection equality.

◆ select()

void select ( const std::string & selection)

Select a new value.