|
plptools
|
Wrapper class featuring range-checking and string representation of enumerated values. More...
#include <Enum.h>


Classes | |
| struct | sdata |
Public Member Functions | |
| Enum () | |
| default constructor. More... | |
| Enum (E init) | |
| initialize with Enumeration given. More... | |
| Enum (const std::string &s) | |
| initialize with the string representation XXX: throw Exception if not found ? More... | |
| Enum & | operator= (E setval) |
| assign an Enumeration of this type. More... | |
| Enum & | operator= (const Enum &rhs) |
| operator E () const | |
| returns the enumeration value hold with this enum. More... | |
| std::string | toString () const |
| returns the String representation for the value represented by this instance. More... | |
| operator const char * () const | |
| returns the C string representation for the value represented by this instance. More... | |
Static Public Member Functions | |
| static bool | inRange (long i) |
| This static member returns true, if the integer value given fits int the range of this Enumeration. More... | |
| static std::string | getEnumName () |
| returns the Name for this enumeration. More... | |
| static std::string | getStringFor (E e) |
| gives the String represenatation of a specific value of this Enumeration. More... | |
| static E | getValueFor (const std::string &s) |
| returns the Value for a specific String. More... | |
Public Attributes | |
| E | value |
| The actual value hold by this instance. More... | |
Static Public Attributes | |
| static sdata | staticData |
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, a macro is provided.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
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_BEGIN and ENUM_DEFINITION_END macros for this.
|
inline |
|
inline |
|
inline |
| E Enum< E >::value |