![]() |
Plasma Engine
2.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 = plEnum<Derived> |
using | StorageType = typename Derived::StorageType |
Public Member Functions | |
PL_ALWAYS_INLINE | plEnum () |
Default constructor. | |
PL_ALWAYS_INLINE | plEnum (const SelfType &rh) |
Copy constructor. | |
PL_ALWAYS_INLINE | plEnum (typename Derived::Enum init) |
Construct from a C++ enum, and implicit conversion from enum type. | |
PL_ALWAYS_INLINE void | operator= (const SelfType &rh) |
Assignment operator. | |
PL_ALWAYS_INLINE void | operator= (const typename Derived::Enum value) |
Assignment operator. | |
PL_ALWAYS_INLINE bool | operator== (const SelfType &rhs) const |
Comparison operators. | |
PL_ALWAYS_INLINE bool | operator!= (const SelfType &rhs) const |
PL_ALWAYS_INLINE bool | operator> (const SelfType &rhs) const |
PL_ALWAYS_INLINE bool | operator< (const SelfType &rhs) const |
PL_ALWAYS_INLINE bool | operator>= (const SelfType &rhs) const |
PL_ALWAYS_INLINE bool | operator<= (const SelfType &rhs) const |
PL_ALWAYS_INLINE bool | operator== (typename Derived::Enum value) const |
PL_ALWAYS_INLINE bool | operator!= (typename Derived::Enum value) const |
PL_ALWAYS_INLINE bool | operator> (typename Derived::Enum value) const |
PL_ALWAYS_INLINE bool | operator< (typename Derived::Enum value) const |
PL_ALWAYS_INLINE bool | operator>= (typename Derived::Enum value) const |
PL_ALWAYS_INLINE bool | operator<= (typename Derived::Enum value) const |
PL_ALWAYS_INLINE SelfType | operator| (const SelfType &rhs) const |
brief Bitwise operators | |
PL_ALWAYS_INLINE SelfType | operator& (const SelfType &rhs) const |
PL_ALWAYS_INLINE | operator typename Derived::Enum () const |
Implicit conversion to enum type. | |
PL_ALWAYS_INLINE StorageType | GetValue () const |
Returns the enum value as an integer. | |
PL_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(plExampleEnumBase::Enum value) you can write: void function(plExampleEnum value) 5) In all other ways it works exactly like a C++ enum
Example:
struct plExampleEnumBase { using StorageType = plUInt8;
enum Enum { Value1 = 1, // normal value Value2 = 2, // normal value Value3 = 3, // normal value Default = Value1 // Default initialization value (required) }; }; using plExampleEnum = plEnum<plExampleEnumBase>;
This defines an "plExampleEnum" which is stored in an plUInt8 and is default initialized with Value1 For more examples see the enum test.