![]() |
XII Release 0.1.0
|
A custom enum implementation that allows to define the underlying storage type to control its memory footprint. More...
#include <Enum.h>
Public Types | |
using | SelfType = xiiEnum<Derived> |
using | StorageType = typename Derived::StorageType |
Public Member Functions | |
XII_ALWAYS_INLINE | xiiEnum () |
Default constructor. | |
XII_ALWAYS_INLINE | xiiEnum (const SelfType &rh) |
Copy constructor. | |
XII_ALWAYS_INLINE | xiiEnum (typename Derived::Enum init) |
Construct from a C++ enum, and implicit conversion from enum type. | |
XII_ALWAYS_INLINE void | operator= (const SelfType &rh) |
Assignment operator. | |
XII_ALWAYS_INLINE void | operator= (const typename Derived::Enum value) |
Assignment operator. | |
XII_ALWAYS_INLINE constexpr bool | operator== (const SelfType &rhs) const |
Comparison operator. | |
XII_ALWAYS_INLINE constexpr std::strong_ordering | operator<=> (const SelfType &rhs) const |
Comparison operator. | |
XII_ALWAYS_INLINE constexpr bool | operator== (typename Derived::Enum value) const |
Comparison operator. | |
XII_ALWAYS_INLINE constexpr std::strong_ordering | operator<=> (typename Derived::Enum value) const |
Comparison operator. | |
XII_ALWAYS_INLINE SelfType | operator| (const SelfType &rhs) const |
brief Bitwise operators | |
XII_ALWAYS_INLINE SelfType | operator& (const SelfType &rhs) const |
XII_ALWAYS_INLINE constexpr | operator typename Derived::Enum () const |
Implicit conversion to enum type. | |
XII_ALWAYS_INLINE StorageType | GetValue () const |
Returns the enum value as an integer. | |
XII_ALWAYS_INLINE void | SetValue (StorageType value) |
Sets the enum value through an integer. | |
A custom enum implementation that allows to define the underlying storage type to control its memory footprint.
Advantages over a simple C++ enum: 1) Storage type can be defined 2) Enum is default initialized automatically 3) Definition of the enum itself, the storage type and the default init value is in one place 4) It makes function definitions shorter, instead of: void function(xiiExampleEnumBase::Enum value) You can write: void function(xiiExampleEnum value) 5) In all other ways it works exactly like a C++ enum
Example:
struct xiiExampleEnumBase { using StorageType = xiiUInt8;
enum Enum { Value1 = 1, // normal value Value2 = 2, // normal value Value3 = 3, // normal value Default = Value1 // Default initialization value (required) }; }; using xiiExampleEnum = xiiEnum<xiiExampleEnumBase>;
This defines an "xiiExampleEnum" which is stored in a xiiUInt8 and is default initialized with Value1 For more examples see the enum test.