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 111 of file common/SafeEnum.h.
typedef LayoutType representation_t |
Type of the representation.
Definition at line 115 of file common/SafeEnum.h.
|
explicitprotected |
Construction of an enumeration value.
Definition at line 121 of file common/SafeEnum.h.
const LayoutType* storage | ( | ) | const |
Return a pointer to the inner storage.
Definition at line 211 of file common/SafeEnum.h.
LayoutType value | ( | ) | const |
Explicit access to the inner value of the SafeEnum instance.
Definition at line 204 of file common/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 146 of file common/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 158 of file common/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 171 of file common/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 133 of file common/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 184 of file common/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 197 of file common/SafeEnum.h.