Plasma Engine  2.0
Loading...
Searching...
No Matches
plEnum< Derived > Struct Template Reference

A custom enum implementation that allows to define the underlying storage type to control its memory footprint. More...

#include <Enum.h>

Inheritance diagram for plEnum< Derived >:

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.
 

Detailed Description

template<typename Derived>
struct plEnum< Derived >

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.


The documentation for this struct was generated from the following file: