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

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

Detailed Description

Selection of multiple enum value from a list of choices.

See also
neml2::EnumSelectionBase

#include <MultiEnumSelection.h>

Inheritance diagram for MultiEnumSelection:

Public Member Functions

 MultiEnumSelection ()=default
 
 MultiEnumSelection (const std::vector< std::string > &choices, const std::vector< std::string > &selections)
 Create a multi-enum selection from a list of choices and default selections.
 
 MultiEnumSelection (const std::vector< std::string > &choices, const std::vector< int > &values, const std::vector< std::string > &selections)
 Create a multi-enum selection from a list of choices, their corresponding values, and default selections.
 
void select (const std::vector< std::string > &selections)
 
std::size_t size () const
 Number of selected values.
 
bool operator== (const MultiEnumSelection &other) const
 Test for inequality.
 
bool operator!= (const MultiEnumSelection &other) const
 Test for inequality.
 
const std::vector< std::string > & selections () const
 Poor man's reflection implementation.
 
const std::vector< int > & values () const
 Selected values cast to int.
 
template<typename T >
std::vector< 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

◆ MultiEnumSelection() [1/3]

MultiEnumSelection ( )
default

◆ MultiEnumSelection() [2/3]

MultiEnumSelection ( const std::vector< std::string > & choices,
const std::vector< std::string > & selections )

Create a multi-enum selection from a list of choices and default selections.

◆ MultiEnumSelection() [3/3]

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

Create a multi-enum selection from a list of choices, their corresponding values, and default selections.

Member Function Documentation

◆ as()

template<typename T >
std::vector< T > as ( ) const
inline

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

◆ operator!=()

bool operator!= ( const MultiEnumSelection & other) const

Test for inequality.

◆ operator==()

bool operator== ( const MultiEnumSelection & other) const

Test for inequality.

◆ select()

void select ( const std::vector< std::string > & selections)

Select new values

Note
This will clear the current selection

◆ selections()

const std::vector< std::string > & selections ( ) const
inline

Poor man's reflection implementation.

◆ size()

std::size_t size ( ) const

Number of selected values.

◆ values()

const std::vector< int > & values ( ) const
inline

Selected values cast to int.