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

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

Detailed Description

Selection of an enum value from a list of choices.

See also
neml2::EnumSelectionBase

#include <EnumSelection.h>

Inheritance diagram for EnumSelection:

Public Member Functions

 EnumSelection ()=default
 
 EnumSelection (const std::vector< std::string > &choices, const std::string &selection)
 Create an enum selection from a list of choices and a default selection.
 
 EnumSelection (const std::vector< std::string > &choices, const std::vector< int > &values, const std::string &selection)
 Create an enum selection from a list of choices, 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.
 
const std::string & selection () const
 Poor man's reflection implementation.
 
int value () 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 > &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.
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ EnumSelection() [1/3]

EnumSelection ( )
default

◆ EnumSelection() [2/3]

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

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

◆ EnumSelection() [3/3]

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

Create an enum selection from a list of choices, 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!=() [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.

◆ selection()

const std::string & selection ( ) const
inline

Poor man's reflection implementation.

◆ value()

int value ( ) const
inline

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