Helper class used to define safe enumerations. More...
#include <SafeEnum.h>
Public Types | |
typedef LayoutType | representation_t |
Type of the representation. More... | |
Public Member Functions | |
LayoutType | value () const |
Explicit access to the inner value of the SafeEnum instance. More... | |
const LayoutType * | storage () const |
Return a pointer to the inner storage. More... | |
Protected Member Functions | |
SafeEnum (LayoutType value) | |
Construction of an enumeration value. More... | |
Friends | |
bool | operator== (Target lhs, Target rhs) |
Equal to operator for Target instances. More... | |
bool | operator!= (Target lhs, Target rhs) |
Not equal to operator for Target instances. More... | |
bool | operator< (Target lhs, Target rhs) |
Less than operator for Target instances. More... | |
bool | operator<= (Target lhs, Target rhs) |
Less than or equal to operator for Target instances. More... | |
bool | operator> (Target lhs, Target rhs) |
Greater than operator for Target instances. More... | |
bool | operator>= (Target lhs, Target rhs) |
Greater than or equal to operator for Target instances. More... | |
Helper class used to define safe enumerations.
C++ 98 enums expose different security holes:
This template class expose a framework to overcome those issues:
First enum has to be defined in a structure which inherit from this class. The target type is the name of the structure containing the enumeration while LayoutType is the inner type used to stored the enum.
Comparison operator are provided so it is not possible to compare a SafeEnum of a type to another SafeEnum of a different type.
Implicit conversion to integer is not defined, users have to either use the value function which return the integer value stored in an EnumType. Client class can also define their own conversion operation.
Target | structure containing the enumeration definition. |
LayoutType | Inner type used to store enumeration value. |
Definition at line 109 of file SafeEnum.h.
typedef LayoutType representation_t |
Type of the representation.
Definition at line 113 of file SafeEnum.h.
|
explicitprotected |
Construction of an enumeration value.
Definition at line 119 of file SafeEnum.h.
const LayoutType* storage | ( | ) | const |
Return a pointer to the inner storage.
Definition at line 209 of file SafeEnum.h.
LayoutType value | ( | ) | const |
Explicit access to the inner value of the SafeEnum instance.
Definition at line 202 of file SafeEnum.h.
|
friend |
Not equal to operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 144 of file SafeEnum.h.
|
friend |
Less than operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 156 of file SafeEnum.h.
|
friend |
Less than or equal to operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 169 of file SafeEnum.h.
|
friend |
Equal to operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 131 of file SafeEnum.h.
|
friend |
Greater than operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 182 of file SafeEnum.h.
|
friend |
Greater than or equal to operator for Target instances.
lhs | left hand side of the comparison |
rhs | right hand side of the comparison |
Definition at line 195 of file SafeEnum.h.