The enumeration class provides several meta information about an enum. More...
#include <enumeration.h>
Public Member Functions | |
type | get_declaring_type () const |
Returns the type of the class or struct that declares this enumeration. More... | |
std::vector< std::string > | get_keys () const |
Returns all enum keys registered for this enumeration. More... | |
variant | get_metadata (int key) const |
Returns the metadata for the given key key . More... | |
variant | get_metadata (const std::string &key) const |
Returns the metadata for the given key key . More... | |
std::string | get_name () const |
Returns the name of this enumeration. More... | |
type | get_type () const |
Returns the type object of this enumeration. More... | |
type | get_underlying_type () const |
Returns the underlying type (int, unsigned int, etc.) of this enumeration. More... | |
std::vector< variant > | get_values () const |
Returns all enum values registered for this enumeration. More... | |
bool | is_valid () const |
Returns true if this enumeration is valid, otherwise false. More... | |
variant | key_to_value (const std::string &key) const |
Returns the value of the given enumeration key, or an empty variant if the key is not defined. More... | |
operator bool () const | |
Convenience function to check if this enumeration is valid or not. More... | |
bool | operator!= (const enumeration &other) const |
Returns true if this enumeration is the not the same like the other . More... | |
bool | operator== (const enumeration &other) const |
Returns true if this enumeration is the same like the other . More... | |
std::string | value_to_key (detail::argument value) const |
Returns the string that is used as the name of the given enumeration value , or an empty string if the value is not defined. More... | |
The enumeration class provides several meta information about an enum.
A instance of an enumeration class can only be obtained from the type class. See type::get_enum() and type::get_enumerations().
For registration an enum, nested inside a class, see class_::enumeration() and for global enums see register_global::enumeration.
An enumeration is described by it's name (get_name()), it's keys (get_keys()) and it's corresponding values (get_values()). The key is represented as std::string and the values are stored as the underlying enum value. When the enumeration was declared inside a class, then get_declaring_type() can be used to obtain the type of this class.
The conversion functions key_to_value(), value_to_key() allow conversion between the value representation of an enumeration and its literal representation.
A enumeration object is lightweight and can be copied by value. However, each copy will refer to the same underlying enumeration.
type rttr::enumeration::get_declaring_type | ( | ) | const |
Returns the type of the class or struct that declares this enumeration.
std::vector<std::string> rttr::enumeration::get_keys | ( | ) | const |
Returns all enum keys registered for this enumeration.
variant rttr::enumeration::get_metadata | ( | int | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).variant rttr::enumeration::get_metadata | ( | const std::string & | key | ) | const |
Returns the metadata for the given key key
.
key
, an invalid variant object is returned (see variant::is_valid).std::string rttr::enumeration::get_name | ( | ) | const |
Returns the name of this enumeration.
type rttr::enumeration::get_type | ( | ) | const |
Returns the type object of this enumeration.
type rttr::enumeration::get_underlying_type | ( | ) | const |
Returns the underlying type (int, unsigned int, etc.) of this enumeration.
std::vector<variant> rttr::enumeration::get_values | ( | ) | const |
Returns all enum values registered for this enumeration.
bool rttr::enumeration::is_valid | ( | ) | const |
Returns true if this enumeration is valid, otherwise false.
variant rttr::enumeration::key_to_value | ( | const std::string & | key | ) | const |
Returns the value of the given enumeration key, or an empty variant if the key is not defined.
rttr::enumeration::operator bool | ( | ) | const |
Convenience function to check if this enumeration is valid or not.
bool rttr::enumeration::operator!= | ( | const enumeration & | other | ) | const |
Returns true if this enumeration is the not the same like the other
.
bool rttr::enumeration::operator== | ( | const enumeration & | other | ) | const |
Returns true if this enumeration is the same like the other
.
std::string rttr::enumeration::value_to_key | ( | detail::argument | value | ) | const |
Returns the string that is used as the name of the given enumeration value
, or an empty string if the value
is not defined.