ezEngine  Milestone 9
ezEnum< 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 ezEnum< Derived >:

Public Types

typedef ezEnum< Derived > SelfType
typedef Derived::StorageType StorageType

Public Member Functions

 Default constructor.
EZ_ALWAYS_INLINE ezEnum (typename Derived::Enum init)
 Construct from a C++ enum, and implicit conversion from enum type.
EZ_ALWAYS_INLINE void operator= (const SelfType &rh)
 Assignment operator.
EZ_ALWAYS_INLINE void operator= (const typename Derived::Enum value)
 Assignment operator.
EZ_ALWAYS_INLINE bool operator== (const SelfType &rhs) const
 Comparison operators.
EZ_ALWAYS_INLINE bool operator!= (const SelfType &rhs) const
EZ_ALWAYS_INLINE bool operator> (const SelfType &rhs) const
EZ_ALWAYS_INLINE bool operator< (const SelfType &rhs) const
EZ_ALWAYS_INLINE bool operator>= (const SelfType &rhs) const
EZ_ALWAYS_INLINE bool operator<= (const SelfType &rhs) const
EZ_ALWAYS_INLINE bool operator== (typename Derived::Enum value) const
EZ_ALWAYS_INLINE bool operator!= (typename Derived::Enum value) const
EZ_ALWAYS_INLINE bool operator> (typename Derived::Enum value) const
EZ_ALWAYS_INLINE bool operator< (typename Derived::Enum value) const
EZ_ALWAYS_INLINE bool operator>= (typename Derived::Enum value) const
EZ_ALWAYS_INLINE bool operator<= (typename Derived::Enum value) const
EZ_ALWAYS_INLINE SelfType operator| (const SelfType &rhs) const
 brief Bitwise operators
EZ_ALWAYS_INLINE SelfType operator & (const SelfType &rhs) const
EZ_ALWAYS_INLINE operator typename Derived::Enum () const
 Implicit conversion to enum type.
EZ_ALWAYS_INLINE StorageType GetValue () const
 Returns the enum value as an integer.
EZ_ALWAYS_INLINE void SetValue (StorageType value)
 Sets the enum value through an integer.

Detailed Description

template<typename Derived>
struct ezEnum< 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(ezExampleEnumBase::Enum value) you can write: void function(ezExampleEnum value) 5) In all other ways it works exactly like a C++ enum


struct ezExampleEnumBase { typedef ezUInt8 StorageType;

enum Enum { Value1 = 1, // normal value Value2 = 2, // normal value Value3 = 3, // normal value Default = Value1 // Default initialization value (required) }; }; typedef ezEnum<ezExampleEnumBase> ezExampleEnum;

This defines an "ezExampleEnum" which is stored in an ezUInt8 and is default initialized with Value1 For more examples see the enum test.

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