enum_type
Smart enumerations.
A method of declaring enumerations that allow grouping within a structure.
Avoids the problem of clashing names that can occur with standard enumerations.
One way to think of the code is as a type with built-in constants and an optional conversion to a string
Example
struct CompassDirection
{
enum enum_type
{
North = 0,
South = 180,
East = 90,
West = 270
};
ETL_DECLARE_ENUM_TYPE(CompassDirection, int)
ETL_ENUM_TYPE(North, "North")
ETL_ENUM_TYPE(South, "South")
ETL_ENUM_TYPE(East, "East")
ETL_ENUM_TYPE(West, "West")
ETL_END_ENUM_TYPE
};
CompassDirection direction;
direction = CompassDirection::North;
int value = direction;
direction = CompassDirection(value);
direction = CompassDirection(3);
direction = value;
std::cout << "Direction = " << direction.c_str();
If a conversion to a string is not required then the ENUM_TYPE declarations may be omitted. In that case the c_str()
function will return a "?". This will also be the case for any enumeration value that does not have an ENUM_TYPE entry.