Provides string representation for enums.
The class basically implements efficient integer-to-string and string-to-integer mapping. The primary usage is to support displaying symbolic names for integer enum values.
Public Member Functions | |
Constructors, destructor, assignment. | |
cEnum (const char *name=nullptr) | |
cEnum (const cEnum &cenum) | |
virtual | ~cEnum () |
cEnum & | operator= (const cEnum &list) |
Redefined cObject member functions. | |
virtual cEnum * | dup () const override |
virtual std::string | str () const override |
Insertion and lookup. | |
void | insert (intval_t value, const char *name) |
const char * | getStringFor (intval_t value) |
intval_t | lookup (const char *name, intval_t fallback=-1) |
intval_t | resolve (const char *name) |
const std::map< std::string, intval_t > & | getNameValueMap () const |
Public Member Functions inherited from cOwnedObject | |
cOwnedObject () | |
cOwnedObject (const char *name, bool namepooling=true) | |
cOwnedObject (const cOwnedObject &obj) | |
virtual | ~cOwnedObject () |
cOwnedObject & | operator= (const cOwnedObject &o) |
virtual void | parsimPack (cCommBuffer *buffer) const override |
virtual void | parsimUnpack (cCommBuffer *buffer) override |
virtual cObject * | getOwner () const override |
virtual bool | isOwnedObject () const override |
Public Member Functions inherited from cNamedObject | |
cNamedObject () | |
cNamedObject (const char *name, bool namepooling=true) | |
cNamedObject (const cNamedObject &obj) | |
virtual | ~cNamedObject () |
cNamedObject & | operator= (const cNamedObject &o) |
virtual void | setName (const char *s) |
virtual const char * | getName () const override |
virtual void | setNamePooling (bool b) |
virtual bool | getNamePooling () |
Public Member Functions inherited from cObject | |
cObject () | |
cObject (const cObject &other)=default | |
virtual | ~cObject () |
virtual const char * | getClassName () const |
bool | isName (const char *s) const |
virtual const char * | getFullName () const |
virtual std::string | getFullPath () const |
virtual std::string | getClassAndFullName () const |
virtual std::string | getClassAndFullPath () const |
const cObject * | getThisPtr () const |
virtual std::ostream & | printOn (std::ostream &os) const |
virtual bool | isSoftOwner () const |
virtual void | forEachChild (cVisitor *v) |
cObject * | findObject (const char *name, bool deep=true) |
virtual cClassDescriptor * | getDescriptor () const |
void | copyNotSupported () const |
Static Public Member Functions | |
cEnum lookup. | |
static cEnum * | find (const char *enumName, const char *contextNamespace=nullptr) |
static cEnum * | get (const char *enumName, const char *contextNamespace=nullptr) |
Static Public Member Functions inherited from cOwnedObject | |
static long | getTotalObjectCount () |
static long | getLiveObjectCount () |
static void | resetObjectCounters () |
static cSoftOwner * | getOwningContext () |
Additional Inherited Members | |
Protected Member Functions inherited from cObject | |
virtual void | take (cOwnedObject *obj) |
virtual void | drop (cOwnedObject *obj) |
void | dropAndDelete (cOwnedObject *obj) |
|
explicit |
Constructor.
|
inlinevirtual |
Destructor.
Assignment operator. The name member is not copied; see cOwnedObject's operator=() for more details.
|
inlineoverridevirtual |
|
overridevirtual |
Returns a textual representation of this enum.
Reimplemented from cObject.
void insert | ( | intval_t | value, |
const char * | name | ||
) |
Add an item to the enum. If that numeric code exist, overwrite it.
const char* getStringFor | ( | intval_t | value | ) |
Look up value and return string representation. Return nullptr if not found.
Look up string and return numeric code. If not found, return second argument (or -1).
intval_t resolve | ( | const char * | name | ) |
Look up string and return numeric code. Throws an error if not found.
|
inline |
Returns a map with the enum members (names as key, and numeric value map value).
|
static |
Returns the cEnum for the given enum name, or nullptr if not found. The enum must have been registered previously with the Register_Enum() macro.
|
static |
Like find(), but throws an error if the object was not found.