siplasplas
A library for C++ reflection and introspection
cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames > Class Template Reference

Stores static reflection information of an enumeration type. More...

#include <siplasplas/reflection/static/enum.hpp>

Public Types

using type = EnumType
 Alias to the enumeration type.
 
using Type = EnumType
 Alias to the enumeration type.
 
using UnderlyingType = typename std::underlying_type< EnumType >::type
 Underlying integral type of the enumeration.
 
using SourceInfo = SourceInfo_
 Source information of the enumeration type. See cpp::static_reflection::meta::SourceInfo.
 
using names_array_t = std::array< const char *, sizeof...(ConstantsNames)>
 Array type returned by names()
 
using values_array_t = const EnumType[sizeof...(Constants)]
 Array type returned by values()
 

Static Public Member Functions

static constexpr std::size_t count ()
 Returns the number of constants declared in the enumeration type.
 
static constexpr const names_array_tnames ()
 Returns the set of enum constants names. More...
 
static constexpr const values_array_tvalues ()
 Returns the set of enum constants values. More...
 
static constexpr EnumType value (std::size_t i)
 Returns the value of the i-th constant of the enumeration. More...
 
static constexpr const char * name (std::size_t i)
 Returns the name of the i-th constant of the enumeration. More...
 
static constexpr const char * toString (const EnumType value)
 Returns a string representation of the given enumeration value. More...
 
static constexpr EnumType fromString (const char *name)
 Returns an enumeration value from the given enumeration constant name. More...
 
static constexpr bool has (const char *name)
 Checks if there's an enumeration constant with the given name. More...
 
static constexpr bool has (const UnderlyingType value)
 Checks if there's an enumeration constant with the given value. More...
 

Detailed Description

template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
class cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >

Stores static reflection information of an enumeration type.

This class stores information of a given enumeration type and exposes it as methods that can be used to query for enumeration values, get string representations of enumeration values, indexing the enumeration, etc.

Member Function Documentation

template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr EnumType cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::fromString ( const char *  name)
inlinestatic

Returns an enumeration value from the given enumeration constant name.

This function searches for an enumeration constant with the given name. Is assumed that the given name is not qualified with the enumeration type name. The behavior is undefined if there's no enumeration constant declared with that name. See has().

Parameters
namePointer to a null terminated C string with the non-qualified constant name
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr bool cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::has ( const char *  name)
inlinestatic

Checks if there's an enumeration constant with the given name.

This function searches for an enumeration constant with the given name. Is assumed that the given name is not qualified with the enumeration type name.

Parameters
namePointer to a null terminated C string with the name
Returns
True if there's a constant declared with that name, false otherwise.
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr bool cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::has ( const UnderlyingType  value)
inlinestatic

Checks if there's an enumeration constant with the given value.

Returns
True if there's a constant declared with the given value, false otherwise
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr const char* cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::name ( std::size_t  i)
inlinestatic

Returns the name of the i-th constant of the enumeration.

Equivalent to names()[i]

Parameters
iZero-indexed index of the constant

Note: Constants are indexed from top to bottom:

enum class JoystickAxis
{
X, // Enum<JoystickAxis>::value(0)
Y // Enum<JoystickAxis>::value(1)
};

the behavior is undefined if i >= count().

Returns
A pointer to a constexpr null terminated C string with the name of the i-th constant
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr const names_array_t& cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::names ( )
inlinestatic

Returns the set of enum constants names.

Returns
A const reference to a constexpr std::array with C strings containing tha names
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr const char* cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::toString ( const EnumType  value)
inlinestatic

Returns a string representation of the given enumeration value.

If the value is the value of the i-th constant of the enumeration, returns the i-th constant name. The behavior is undefined if the enumeration declaration has no constant with that value (Such as when converting an arbitrary integral value to the enumeration). See has().

Parameters
valueEnumeration value
Returns
A pointer to a constexpr null terminated C string with the name of the corresponding enumeration constant. This function doesn't qualify its result with the enumeration type name, the name is returned as declared in the enum declaration.
template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr EnumType cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::value ( std::size_t  i)
inlinestatic

Returns the value of the i-th constant of the enumeration.

Equivalent to values()[i]

Parameters
iZero-indexed index of the constant

Note: Constants are indexed from top to bottom:

enum class JoystickAxis
{
X, // Enum<JoystickAxis>::value(0)
Y // Enum<JoystickAxis>::value(1)
};

the behavior is undefined if i >= count().

template<typename SourceInfo, typename EnumType, typename Constants, typename ConstantsNames>
static constexpr const values_array_t& cpp::static_reflection::meta::Enum< SourceInfo, EnumType, Constants, ConstantsNames >::values ( )
inlinestatic

Returns the set of enum constants values.

Returns
A const reference to a constexpr C array with the EnumType values

The documentation for this class was generated from the following file: