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 |
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 () |
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 |
| template<typename E > | |
| static E | resolveName (const char *name) |
| template<typename E > | |
| static const char * | getNameForValue (E value) |
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.
Referenced by cEnum::getNameForValue().
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.
Referenced by cEnum::resolveName().
|
inlinestatic |
Resolve a string and return the corresponding value in the enum type given as template argument. The enum must have been registered previously with one of the Register_Enum() macros.
Example:
References omnetpp::opp_typename(), and cEnum::resolve().
|
inlinestatic |
Resolve an enum value of type E and return the corresponding string representation. The enum must have been registered previously with one of the Register_Enum() macros.
Example:
References cEnum::getStringFor(), and omnetpp::opp_typename().
|
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 one of the Register_Enum() macros.
|
static |
Like find(), but throws an error if the object was not found.