NEML2 1.4.0
|
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) | |
EnumSelection & | operator= (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 > | |
T | as () const |
Statically cast the enum value to a C++ enum class. | |
Friends | |
std::stringstream & | operator>> (std::stringstream &ss, 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 ) |
|
inline |
Statically cast the enum value to a C++ enum class.
std::string candidates_str | ( | ) | const |
Stringified candidates.
|
inline |
Poor man's reflection implementation.
bool operator!= | ( | const EnumSelection & | other | ) | const |
Test for inequality.
EnumSelection & operator= | ( | const EnumSelection & | other | ) |
Assignment operator.
bool operator== | ( | const EnumSelection & | other | ) | const |
Test for inequality.
|
friend |
The input stream operator shall be the only entry point to modify the selection other than the assignment operator