Mbed OS Reference
|
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... | |
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.
LayoutType value | ( | ) | const |
Explicit access to the inner value of the SafeEnum instance.
Definition at line 204 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.