|
|
Wrapper class featuring range-checking and string representation of enumerated values.
The string representation capability is needed to provide a generic input frontend for any Enumeration because text labels are needed in GUIs, and, of course, aids debugging, because you can provide a readable presentation of an entry if something goes wrong.
NOTE, that wrapping an enumeration with this class does not mean any performance overhead at all since the compiler optimizes the member calls away. Nor does an instance of this class use more memory than the use of an usual Enumeration. (i.e. sizeof(E) == sizeof(Enum<E>)).
Besides that, it provides a great opportunity to check the code and make it bug free, esp. if you've to read the Enumeration from some dubious integer source (.. to make the dubious integer source bug free ;-)
So there is no reason, not to use this class. Alas, you've to provide a StringRepresentation for it, which may be tedious for large enumerations. To make the Definition easier and more readable, an ENUM_DEFINITION() macro is provided.
|
default constructor. Initialize with default value.
|
initialize with Enumeration given.
|
initialize with the string representation XXX: throw Exception if not found ?
inline Enum& |
assign an Enumeration of this type. In debug version, assert, that it is really in the Range of this Enumeration.
inline Enum& |
inline |
[const]
returns the enumeration value hold with this enum.
std::string |
[const]
returns the String representation for the value represented by this instance.
|
[const]
returns the C string representation for the value represented by this instance.
bool |
[static]
This static member returns true, if the integer value given fits int the range of this Enumeration. Use this to verify input/output. Fitting in the range of Enumeration here means, that there actually exists a String representation for it, so this Enumeration is needed to be initialized properly in its Enum<E>::sdata::sdata() constructor, you've to provide. For convenience, use the ENUM_DEFINITION() macro for this.
std::string |
[static]
returns the Name for this enumeration. Useful for error reporting.
std::string |
[static]
gives the String represenatation of a specific value of this Enumeration.
E |
[static]
returns the Value for a specific String. XXX: throw OutOfRangeException ?