The enumeration class provides several meta information about an enum. More...
#include <enumeration.h>
Public Member Functions | |
type | get_declaring_type () const noexcept |
Returns the type of the class or struct that declares this enumeration. More... | |
variant | get_metadata (const variant &key) const |
Returns the meta data for the given key key . More... | |
string_view | get_name () const noexcept |
Returns the declared name of this enumeration. More... | |
array_range< string_view > | get_names () const noexcept |
Returns all enum names registered for this enumeration. More... | |
type | get_type () const noexcept |
Returns the type object of this enumeration. More... | |
type | get_underlying_type () const noexcept |
Returns the underlying type (int, unsigned int, etc.) of this enumeration. More... | |
array_range< variant > | get_values () const noexcept |
Returns all enum values registered for this enumeration. More... | |
bool | is_valid () const noexcept |
Returns true if this enumeration is valid, otherwise false. More... | |
variant | name_to_value (string_view name) const |
Returns the value of the given enumeration name , or an empty variant if the name is not defined. More... | |
operator bool () const noexcept | |
Convenience function to check if this enumeration is valid or not. More... | |
bool | operator!= (const enumeration &other) const noexcept |
Returns true if this enumeration is the not the same like the other . More... | |
bool | operator== (const enumeration &other) const noexcept |
Returns true if this enumeration is the same like the other . More... | |
string_view | value_to_name (argument value) const |
Returns the string_view that is used as the name of the given enumeration value , or an empty string_view if the value is not defined. More... | |
Detailed Description
The enumeration class provides several meta information about an enum.
A instance of an enumeration class can only be obtained from the type class or the property class. See type::get_enumeration() and property::get_enumeration().
For registration an enum, nested inside a class, see registration::class_<T>::enumeration() and for global enums see registration::enumeration().
Meta Information
An enumeration is described by it's declared name (get_name()), it's enumerator names (get_names()) and it's corresponding constant values (get_values()). The name is represented as string_view 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 name_to_value(), value_to_name() allow conversion between the value representation of an enumeration and its literal representation.
Copying and Assignment
A enumeration object is lightweight and can be copied by value. However, each copy will refer to the same underlying enumeration.
Typical Usage
- See also
- method, property, constructor and type
Member Function Documentation
|
noexcept |
Returns the type of the class or struct that declares this enumeration.
- Remarks
- When this enumeration does not belong to a class (i.e. is a global enumeration) it will return an invalid type object. When this enumeration is not valid, this function will return an invalid type object (see type::is_valid).
- Returns
- Type of the declaring class/struct for this enumeration.
Returns the meta data for the given key key
.
- Remarks
- When no meta data is registered with the given
key
, an invalid variant object is returned (see variant::is_valid).
- Returns
- A variant object, containing arbitrary data.
|
noexcept |
Returns the declared name of this enumeration.
- Returns
- Name of the enumeration.
|
noexcept |
Returns all enum names registered for this enumeration.
- Remarks
- When the enumeration is invalid then an empty range is returned.
- Returns
- A range of enumeration names.
|
noexcept |
Returns the type object of this enumeration.
- Returns
- Data type of the enumeration.
|
noexcept |
Returns the underlying type (int, unsigned int, etc.) of this enumeration.
- Returns
- Data type of the enumeration.
|
noexcept |
Returns all enum values registered for this enumeration.
- Remarks
- When the enumeration is invalid then an empty range is returned.
- Returns
- A range of enumeration values.
|
noexcept |
Returns true if this enumeration is valid, otherwise false.
- Returns
- True if this enumeration is valid, otherwise false.
variant rttr::enumeration::name_to_value | ( | string_view | name | ) | const |
Returns the value of the given enumeration name
, or an empty variant if the name is not defined.
- Returns
- A variant object, containing the value for the given
name
.
|
explicitnoexcept |
Convenience function to check if this enumeration is valid or not.
- Returns
- True if this enumeration is valid, otherwise false.
|
noexcept |
Returns true if this enumeration is the not the same like the other
.
- Returns
- True if both enumerations are different, otherwise false.
|
noexcept |
Returns true if this enumeration is the same like the other
.
- Returns
- True if both enumerations are equal, otherwise false.
string_view rttr::enumeration::value_to_name | ( | argument | value | ) | const |
Returns the string_view that is used as the name of the given enumeration value
, or an empty string_view if the value
is not defined.
- Returns
- A string_view object, containing the name for the given value.
The documentation for this class was generated from the following file: