HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Data Fields | Static Public Attributes
hi::v1::enum_metadata< ValueType, NameType, N > Class Template Reference

#include <hikogui/utility/enum_metadata.hpp>

Public Types

using value_type = ValueType
 
using name_type = NameType
 

Public Member Functions

constexpr size_t size () const noexcept
 Get the number of enum values.
 
constexpr value_type minimum () const noexcept
 Get the minimum value.
 
constexpr value_type maximum () const noexcept
 Get the maximum value.
 
template<typename... Args>
constexpr enum_metadata (Args const &...args) noexcept
 Construct a enum-names table object.
 
template<std::convertible_to< name_type > Name>
constexpr bool contains (Name &&name) const noexcept
 Check if the enum has a name.
 
constexpr bool contains (value_type value) const noexcept
 Check if the enum has a value.
 
template<std::convertible_to< name_type > Name>
constexpr value_type at (Name &&name) const
 Get an enum-value from a name.
 
constexpr name_type const & at (value_type value) const
 Get a name from an enum-value.
 
template<std::convertible_to< name_type > Name>
constexpr std::optional< value_type > at_if (Name &&name) const noexcept
 Get an enum-value from a name.
 
template<std::convertible_to< name_type > Name>
constexpr value_type at (Name &&name, value_type default_value) const noexcept
 Get an enum-value from a name.
 
template<std::convertible_to< name_type > Name>
constexpr name_type at (value_type value, Name &&default_name) const noexcept
 Get a name from an enum-value.
 
template<std::convertible_to< name_type > Name>
constexpr value_type operator[] (Name &&name) const noexcept
 Get an enum-value from a name.
 
constexpr name_type const & operator[] (value_type value) const noexcept
 Get a name from an enum-value.
 

Data Fields

bool values_are_continues
 The numeric values in the enum do not contain a gap.
 

Static Public Attributes

static constexpr std::size_t count = N
 The number of enum values.
 

Detailed Description

template<typename ValueType, typename NameType, std::size_t N>
class hi::v1::enum_metadata< ValueType, NameType, N >

A object that holds enum-values and strings.

Template Parameters
ValueTypeThe enum-type.
NameTypeThe type used to convert to and from the EnumType.
NNumber of enum-values.

Constructor & Destructor Documentation

◆ enum_metadata()

template<typename ValueType , typename NameType , std::size_t N>
template<typename... Args>
constexpr hi::v1::enum_metadata< ValueType, NameType, N >::enum_metadata ( Args const &... args)
inlineconstexprnoexcept

Construct a enum-names table object.

Example usage:

enum class my_bool { yes, no };
constexpr auto my_bool_names = enum_metadata(my_bool::no, "no", my_bool::yes, "yes");
constexpr enum_metadata(Args const &...args) noexcept
Construct a enum-names table object.
Definition enum_metadata.hpp:87

The template parameters of the class will be deduced from the constructor. N = sizeof...(Args) / 2, T = decltype(args[0]).

Parameters
argsA list of a enum-value and names.

Member Function Documentation

◆ at() [1/4]

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr value_type hi::v1::enum_metadata< ValueType, NameType, N >::at ( Name && name) const
inlineconstexpr

Get an enum-value from a name.

Parameters
nameThe name to lookup in the enum.
Returns
The enum-value belonging with the name.
Exceptions
std::out_of_rangeWhen the name does not exist.

◆ at() [2/4]

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr value_type hi::v1::enum_metadata< ValueType, NameType, N >::at ( Name && name,
value_type default_value ) const
inlineconstexprnoexcept

Get an enum-value from a name.

Parameters
nameThe name to lookup in the enum.
default_valueThe default value to return when the name is not found.
Returns
The enum-value belonging with the name.

◆ at() [3/4]

template<typename ValueType , typename NameType , std::size_t N>
constexpr name_type const & hi::v1::enum_metadata< ValueType, NameType, N >::at ( value_type value) const
inlineconstexpr

Get a name from an enum-value.

Parameters
valueThe enum value to lookup.
Returns
The name belonging with the enum value.
Exceptions
std::out_of_rangeWhen the value does not exist.

◆ at() [4/4]

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr name_type hi::v1::enum_metadata< ValueType, NameType, N >::at ( value_type value,
Name && default_name ) const
inlineconstexprnoexcept

Get a name from an enum-value.

Parameters
valueThe enum value to lookup.
default_nameThe default name to return when value is not found.
Returns
The name belonging with the enum value.

◆ at_if()

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr std::optional< value_type > hi::v1::enum_metadata< ValueType, NameType, N >::at_if ( Name && name) const
inlineconstexprnoexcept

Get an enum-value from a name.

Parameters
nameThe name to lookup in the enum.
Returns
The enum-value belonging with the name or std::nullopt if name is not found.

◆ contains() [1/2]

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr bool hi::v1::enum_metadata< ValueType, NameType, N >::contains ( Name && name) const
inlineconstexprnoexcept

Check if the enum has a name.

Parameters
nameThe name to lookup in the enum.
Returns
True if the name is found.

◆ contains() [2/2]

template<typename ValueType , typename NameType , std::size_t N>
constexpr bool hi::v1::enum_metadata< ValueType, NameType, N >::contains ( value_type value) const
inlineconstexprnoexcept

Check if the enum has a value.

Parameters
valueThe value to lookup for the enum.
Returns
True if the value is found.

◆ maximum()

template<typename ValueType , typename NameType , std::size_t N>
constexpr value_type hi::v1::enum_metadata< ValueType, NameType, N >::maximum ( ) const
inlineconstexprnoexcept

Get the maximum value.

◆ minimum()

template<typename ValueType , typename NameType , std::size_t N>
constexpr value_type hi::v1::enum_metadata< ValueType, NameType, N >::minimum ( ) const
inlineconstexprnoexcept

Get the minimum value.

◆ operator[]() [1/2]

template<typename ValueType , typename NameType , std::size_t N>
template<std::convertible_to< name_type > Name>
constexpr value_type hi::v1::enum_metadata< ValueType, NameType, N >::operator[] ( Name && name) const
inlineconstexprnoexcept

Get an enum-value from a name.

Note
It is undefined-behavior to lookup a name that does not exist in the table.
Parameters
nameThe name to lookup in the enum.
Returns
The enum-value belonging with the name.

◆ operator[]() [2/2]

template<typename ValueType , typename NameType , std::size_t N>
constexpr name_type const & hi::v1::enum_metadata< ValueType, NameType, N >::operator[] ( value_type value) const
inlineconstexprnoexcept

Get a name from an enum-value.

Note
It is undefined-behavior to lookup a value that does not exist in the table.
Parameters
valueThe enum value to lookup.
Returns
The name belonging with the enum value.

◆ size()

template<typename ValueType , typename NameType , std::size_t N>
constexpr size_t hi::v1::enum_metadata< ValueType, NameType, N >::size ( ) const
inlineconstexprnoexcept

Get the number of enum values.

Field Documentation

◆ count

template<typename ValueType , typename NameType , std::size_t N>
constexpr std::size_t hi::v1::enum_metadata< ValueType, NameType, N >::count = N
staticconstexpr

The number of enum values.

◆ values_are_continues

template<typename ValueType , typename NameType , std::size_t N>
bool hi::v1::enum_metadata< ValueType, NameType, N >::values_are_continues

The numeric values in the enum do not contain a gap.


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