Provides string representation for enums. More...
#include <cenum.h>
Public Member Functions | |
std::string | str () const |
Constructors, destructor, assignment. | |
cEnum (const char *name=NULL) | |
cEnum (const char *name, const char *str,...) | |
cEnum (const cEnum &cenum) | |
virtual | ~cEnum () |
cEnum & | operator= (const cEnum &list) |
Redefined cObject member functions. | |
virtual cEnum * | dup () const |
virtual std::string | info () const |
Insertion and lookup. | |
void | insert (int value, const char *name) |
const char * | getStringFor (int value) |
int | lookup (const char *name, int fallback=-1) |
Static Public Member Functions | |
static cEnum * | find (const char *name) |
static cEnum * | get (const char *name) |
Provides string representation for enums.
The class basically implements effective integer-to-string and string-to-integer mapping. Primary usage is to support displaying symbolic names for integer values that represent some code (such as an enum or #define).
cEnum::cEnum | ( | const char * | name, | |
const char * | str, | |||
... | ||||
) |
FIXME document properly: arglist: (enumname, string1, value1, string2, value2, .
.., NULL)
Example:
enum State { IDLE=0, BUSY }; cEnum stateEnum("state", "IDLE", IDLE, "BUSY", BUSY, NULL);
virtual cEnum* cEnum::dup | ( | ) | const [inline, virtual] |
static cEnum* cEnum::find | ( | const char * | name | ) | [static] |
Finds a registered enum by name.
Returns NULL if not found.
static cEnum* cEnum::get | ( | const char * | name | ) | [static] |
Returns the enum with the given name.
Throws an error if not found.
const char* cEnum::getStringFor | ( | int | value | ) |
Look up value and return string representation.
Return NULL if not found.
virtual std::string cEnum::info | ( | ) | const [virtual] |
void cEnum::insert | ( | int | value, | |
const char * | name | |||
) |
Add an item to the enum.
If that numeric code exist, overwrite it.
int cEnum::lookup | ( | const char * | name, | |
int | fallback = -1 | |||
) |
Look up string and return numeric code.
If not found, return second argument (or -1).
Assignment operator.
The name member is not copied; see cOwnedObject's operator=() for more details.