Skip to content

Functions

Scaless edited this page Oct 18, 2023 · 1 revision

ALL functions are constexpr unless otherwise noted.

Value Enums

Function Description
T min() Returns the entry with the lowest numerical value.
T max() Returns the entry with the highest numerical value.
T default_value() Returns the default value for the enum.
bool is_contiguous() True if all values within the enum are contiguous.
int count() Number of entries in the enum.
int bits_required_storage() Number of bits required to represent any possible valid value contained in the enum.
Useful for determining the minimum number of bits to store the enum type in a bitfield.
Always > 0.
int bits_required_transmission() Number of bits required to represent the range of (max<T> - min<T>).
Useful for sending bits over the wire where the least number of bits is desireable, i.e. serialization.
May be different from value_enum::bits_required_storage if the enum minimum starts at a non-zero value.
Can be 0 if the enum contains only 1 value since no bits need to be transferred to represent a singular state.
T from_underlying_unsafe(underlying_type) Convert a raw numerical value to an enum value.
Call is_valid<T>(underlying_type) to verify the value before conversion.
underlying_type to_underlying(T) Convert an enum value to a raw numeric value.
bool is_valid<T>(underlying_type) Validate that a raw numeric value can be represented in the enum.
Generally used before calling from_underlying_unsafe.
<stringtype> to_string(T) Convert an enum value to a string.
String type depends on configuration file.
Returns an empty string if enum value is not valid.
std::pair<bool, T> from_string(<stringtype>) Convert a string to an enum value.
String type depends on configuration file.
The bool component of the pair is true on success.
std::array<T,#>& values<T>() Returns a reference to an array with all entries.
Can be used in range-for loops to iterate all possible values.

Flags Enums

Function Description
T min() Always 0 (no flags set).
T max() Returns a value with all possible flags set.
T default_value() Returns the default value for the enum.
bool is_contiguous() True if all flags within the enum can be set with no gaps.
int count() Number of flags in the enum.
int bits_required_storage() Number of bits required to the max<T> value of the enum.
Always > 0.
int bits_required_transmission() Number of bits required to represent the range of (max<T> - min<T>).
Due to min<T> always being 0, this value should always be equal to bits_required_storage for flags enums.
T from_underlying_unsafe(underlying_type) Convert a raw numerical value to an enum value.
Call is_valid<T>(underlying_type) to verify the value before conversion.
underlying_type to_underlying(T) Convert an enum value to a raw numeric value.
void zero(T& value) Zeroes the variable.
bool test(T value, T flags) Returns true if all flags bits are set in value.
void set(T& value, T flags) Sets bits for flags in value.
void unset(T& value, T flags) Un-sets bits for flags in value.
void toggle(T& value, T flags) Toggle bits at flags in value.
bool is_all(T) Returns true if all flag bits are set.
bool is_any(T) Returns true if any flag bit is set.
bool is_none(T) Returns true if no bits are set (value is zero).
bool is_single(T) Returns true if one flag bit is set.

Clone this wiki locally