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

#include <hikogui/enum_metadata.hpp>

Public Types

using value_type = T
 

Public Member Functions

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.
 
constexpr bool contains (std::string_view 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.
 
constexpr value_type at (std::string_view name) const
 Get an enum-value from a name.
 
constexpr std::string_view const & at (value_type value) const
 Get a name from an enum-value.
 
constexpr value_type at (std::string_view name, value_type default_value) const noexcept
 Get an enum-value from a name.
 
constexpr std::string_view at (value_type value, std::string_view default_name) const noexcept
 Get a name from an enum-value.
 
constexpr value_type operator[] (std::string_view name) const noexcept
 Get an enum-value from a name.
 
constexpr std::string_view 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 T, std::size_t N>
class v1::enum_metadata< T, N >

A object that holds enum-values and strings.

Template Parameters
TThe enum-type.
NNumber of enum-values.

Constructor & Destructor Documentation

◆ enum_metadata()

template<typename T , std::size_t N>
template<typename... Args>
constexpr v1::enum_metadata< T, 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:66

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 T , std::size_t N>
constexpr value_type v1::enum_metadata< T, N >::at ( std::string_view 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 T , std::size_t N>
constexpr value_type v1::enum_metadata< T, N >::at ( std::string_view 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 T , std::size_t N>
constexpr std::string_view const & v1::enum_metadata< T, 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 T , std::size_t N>
constexpr std::string_view v1::enum_metadata< T, N >::at ( value_type value,
std::string_view default_name ) const
inlineconstexprnoexcept

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.

◆ contains() [1/2]

template<typename T , std::size_t N>
constexpr bool v1::enum_metadata< T, N >::contains ( std::string_view 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 T , std::size_t N>
constexpr bool v1::enum_metadata< T, N >::contains ( value_type value) const
inlineconstexprnoexcept

Check if the enum has a value.

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

◆ maximum()

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

Get the maximum value.

◆ minimum()

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

Get the minimum value.

◆ operator[]() [1/2]

template<typename T , std::size_t N>
constexpr value_type v1::enum_metadata< T, N >::operator[] ( std::string_view 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 T , std::size_t N>
constexpr std::string_view const & v1::enum_metadata< T, 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.

Field Documentation

◆ count

template<typename T , std::size_t N>
constexpr std::size_t v1::enum_metadata< T, N >::count = N
staticconstexpr

The number of enum values.

◆ values_are_continues

template<typename T , std::size_t N>
bool v1::enum_metadata< T, 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: