ezEngine  Milestone 7
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

EZ_FORCE_INLINE ezEnum ()
 Default constructor.
 
EZ_FORCE_INLINE ezEnum (typename Derived::Enum init)
 Construct from a C++ enum, and implicit conversion from enum type.
 
EZ_FORCE_INLINE void operator= (const SelfType &rh)
 Assignment operator.
 
EZ_FORCE_INLINE void operator= (const typename Derived::Enum value)
 Assignment operator.
 
EZ_FORCE_INLINE operator typename Derived::Enum () const
 Implicit conversion to enum type.
 

Private Attributes

StorageType m_value
 

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

Example:

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: