cubos::core::reflection::EnumTrait class

Provides enumeration functionality to an enumerated type.

Public types

using Tester = bool(*)(const void*instance)
Function pointer to test if a value matches the variant.
using Setter = void(*)(void*instance)
Function pointer to set the value of the variant.

Public static functions

template<typename T>
static auto toString(const T& value) -> const std::string&
Converts an enumeration value to its string representation.
template<typename T>
static auto fromString(T& value, const std::string& str) -> bool
Converts a string to a value of a specified type.
static auto end() -> Iterator
Gets an iterator to the last variant of the type.

Constructors, destructors, conversion operators

EnumTrait() defaulted
Constructs.
EnumTrait(EnumTrait&& other) noexcept
Move constructs.
Variant(std::string name, Tester tester, Setter setter)
Constructs a variant with a given name, tester function, and setter function.
Iterator(const Variant* variant)
Constructs.
Iterator(const Iterator& iterator) defaulted
Copy constructs.

Public functions

void addVariant(std::string name, Tester tester, Setter setter)
Adds a variant to the type.
auto withVariant(std::string name, Tester tester, Setter setter) && -> EnumTrait&&
Adds a variant to the type.
template<auto V>
auto withVariant(std::string name) && -> EnumTrait&&
Adds a variant to the type.
auto contains(const std::string& name) const -> bool
Checks if a variant with the given name exists.
auto at(const std::string& name) const -> const Variant&
Gets the variant with the specified name.
auto variant(const void* value) const -> const Variant&
Gets the variant associated with the given value.
auto begin() const -> Iterator
Gets an iterator to the first variant of the type.
auto size() const -> std::size_t
Returns how many enum variants there are in the trait.
auto test(const void* value) const -> bool
Tests if the given value matches the variant.
void set(void* value) const
Sets the value of the variant.
auto name() const -> const std::string&
Gets the name of the variant.
auto next() const -> const Variant*
Returns the next variant in the linked list.
auto operator=(const Iterator&) -> Iterator& defaulted
Copy assigns.
auto operator==(const Iterator&) const -> bool defaulted
Compares with another iterator.
auto operator*() const -> const Variant&
Accesses the variant referenced by this iterator.
auto operator->() const -> const Variant*
Accesses the variant referenced by this iterator.
auto operator++() -> Iterator&
Advances the iterator.

Function documentation

template<typename T>
static const std::string& cubos::core::reflection::EnumTrait::toString(const T& value)

Converts an enumeration value to its string representation.

Parameters
value Enumeration value to be converted.
Returns String representation.

template<typename T>
static bool cubos::core::reflection::EnumTrait::fromString(T& value, const std::string& str)

Converts a string to a value of a specified type.

Parameters
value in/out Variable to store the converted value.
str String to be converted to the specified value type.
Returns Whether the conversion was successful, false otherwise.

static Iterator cubos::core::reflection::EnumTrait::end()

Gets an iterator to the last variant of the type.

Returns Iterator.

cubos::core::reflection::EnumTrait::EnumTrait(EnumTrait&& other) noexcept

Move constructs.

Parameters
other Other trait.

cubos::core::reflection::EnumTrait::Variant(std::string name, Tester tester, Setter setter)

Constructs a variant with a given name, tester function, and setter function.

Parameters
name Variant name.
tester Function to test if a value matches the variant.
setter Function to set the value of the variant.

cubos::core::reflection::EnumTrait::Iterator(const Variant* variant)

Constructs.

Parameters
variant Variant.

cubos::core::reflection::EnumTrait::Iterator(const Iterator& iterator) defaulted

Copy constructs.

Parameters
iterator Iterator.

void cubos::core::reflection::EnumTrait::addVariant(std::string name, Tester tester, Setter setter)

Adds a variant to the type.

Parameters
name Variant name.
tester Function to test if a value matches the variant.
setter Function to set the value of the variant.

EnumTrait&& cubos::core::reflection::EnumTrait::withVariant(std::string name, Tester tester, Setter setter) &&

Adds a variant to the type.

Parameters
name Variant name.
tester Function to test if a value matches the variant.
setter Function to set the value of the variant.
Returns Trait.

template<auto V>
EnumTrait&& cubos::core::reflection::EnumTrait::withVariant(std::string name) &&

Adds a variant to the type.

Template parameters
V Enumeration value.
Parameters
name Variant name.
Returns Trait.

bool cubos::core::reflection::EnumTrait::contains(const std::string& name) const

Checks if a variant with the given name exists.

Parameters
name Variant name.
Returns Whether the variant exists.

const Variant& cubos::core::reflection::EnumTrait::at(const std::string& name) const

Gets the variant with the specified name.

Parameters
name Variant name.
Returns Reference.

const Variant& cubos::core::reflection::EnumTrait::variant(const void* value) const

Gets the variant associated with the given value.

Parameters
value Pointer to the value for which to retrieve the variant.
Returns Reference.

Iterator cubos::core::reflection::EnumTrait::begin() const

Gets an iterator to the first variant of the type.

Returns Iterator.

std::size_t cubos::core::reflection::EnumTrait::size() const

Returns how many enum variants there are in the trait.

Returns Variant count.

bool cubos::core::reflection::EnumTrait::test(const void* value) const

Tests if the given value matches the variant.

Parameters
value Pointer to value.
Returns Whether the value matches the variant.

void cubos::core::reflection::EnumTrait::set(void* value) const

Sets the value of the variant.

Parameters
value Pointer to value.

const std::string& cubos::core::reflection::EnumTrait::name() const

Gets the name of the variant.

Returns Variant name.

const Variant* cubos::core::reflection::EnumTrait::next() const

Returns the next variant in the linked list.

Returns Pointer to next variant or null if this is the last variant.

Iterator& cubos::core::reflection::EnumTrait::operator=(const Iterator&) defaulted

Copy assigns.

Returns This.

bool cubos::core::reflection::EnumTrait::operator==(const Iterator&) const defaulted

Compares with another iterator.

Returns Whether both point to the same variant.

const Variant& cubos::core::reflection::EnumTrait::operator*() const

Accesses the variant referenced by this iterator.

Returns Reference to the variant.

const Variant* cubos::core::reflection::EnumTrait::operator->() const

Accesses the variant referenced by this iterator.

Returns Pointer to the variant.

Iterator& cubos::core::reflection::EnumTrait::operator++()

Advances the iterator.

Returns Reference to this.