OMNeT++ Simulation Library  5.6.1
cEnum Class Reference

#include <cenum.h>

Description

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.

Inheritance diagram for cEnum:
cOwnedObject cNamedObject cObject

Public Member Functions

Constructors, destructor, assignment.
 cEnum (const char *name=nullptr)
 
 cEnum (const char *name, const char *str,...)
 
 cEnum (const cEnum &cenum)
 
virtual ~cEnum ()
 
cEnumoperator= (const cEnum &list)
 
Redefined cObject member functions.
virtual cEnumdup () const override
 
virtual std::string str () const override
 
Insertion and lookup.
void insert (int value, const char *name)
 
void bulkInsert (const char *name1,...)
 
const char * getStringFor (int value)
 
int lookup (const char *name, int fallback=-1)
 
int resolve (const char *name)
 
std::map< std::string, int > getNameValueMap () const
 
- Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 
 cOwnedObject (const char *name, bool namepooling=true)
 
 cOwnedObject (const cOwnedObject &obj)
 
virtual ~cOwnedObject ()
 
cOwnedObjectoperator= (const cOwnedObject &o)
 
virtual void parsimPack (cCommBuffer *buffer) const override
 
virtual void parsimUnpack (cCommBuffer *buffer) override
 
virtual cObjectgetOwner () const override
 
virtual bool isOwnedObject () const override
 
virtual bool isSoftOwner () const
 
- Public Member Functions inherited from cNamedObject
 cNamedObject ()
 
 cNamedObject (const char *name, bool namepooling=true)
 
 cNamedObject (const cNamedObject &obj)
 
virtual ~cNamedObject ()
 
cNamedObjectoperator= (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)
 
virtual ~cObject ()
 
virtual const char * getClassName () const
 
bool isName (const char *s) const
 
virtual const char * getFullName () const
 
virtual std::string getFullPath () const
 
const cObjectgetThisPtr () const
 
virtual _OPPDEPRECATED std::string info () const
 
virtual _OPPDEPRECATED std::string detailedInfo () const
 
virtual void forEachChild (cVisitor *v)
 
cObjectfindObject (const char *name, bool deep=true)
 
void copyNotSupported () const
 

Static Public Member Functions

cEnum lookup.
static cEnumfind (const char *enumName, const char *contextNamespace=nullptr)
 
static cEnumget (const char *enumName, const char *contextNamespace=nullptr)
 
- Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
 
static long getLiveObjectCount ()
 
static void resetObjectCounters ()
 
static cDefaultListgetDefaultOwner ()
 

Additional Inherited Members

- Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
 
virtual void drop (cOwnedObject *obj)
 
void dropAndDelete (cOwnedObject *obj)
 

Constructor & Destructor Documentation

◆ cEnum() [1/3]

cEnum ( const char *  name = nullptr)
explicit

Constructor.

◆ cEnum() [2/3]

cEnum ( const char *  name,
const char *  str,
  ... 
)

Constructor that allows adding several values to the enum, in a way similar to bulkInsert(). The argument list begins with the object name, which should be followed by an alternating list of names and values, terminated by a nullptr: name1, value1, name2, value2, ..., nullptr.

Example:

enum State { IDLE=0, BUSY };
cEnum stateEnum("state", "IDLE", IDLE, "BUSY", BUSY, nullptr);

◆ cEnum() [3/3]

cEnum ( const cEnum cenum)

Copy constructor.

◆ ~cEnum()

virtual ~cEnum ( )
virtual

Destructor.

Member Function Documentation

◆ operator=()

cEnum& operator= ( const cEnum list)

Assignment operator. The name member is not copied; see cOwnedObject's operator=() for more details.

◆ dup()

virtual cEnum* dup ( ) const
inlineoverridevirtual

Creates and returns an exact copy of this object. See cObject for more details.

Reimplemented from cObject.

◆ str()

virtual std::string str ( ) const
overridevirtual

Returns a textual representation of this enum.

Reimplemented from cObject.

◆ insert()

void insert ( int  value,
const char *  name 
)

Add an item to the enum. If that numeric code exist, overwrite it.

◆ bulkInsert()

void bulkInsert ( const char *  name1,
  ... 
)

Adds several values to the enum. The argument list should be an alternating list of names and values, terminated by a nullptr: name1, value1, name2, value2, ..., nullptr.

Example:

cEnum stateEnum("state");
stateEnum.bulkInsert("IDLE", IDLE, "BUSY", BUSY, nullptr);

◆ getStringFor()

const char* getStringFor ( int  value)

Look up value and return string representation. Return nullptr if not found.

◆ lookup()

int lookup ( const char *  name,
int  fallback = -1 
)

Look up string and return numeric code. If not found, return second argument (or -1).

◆ resolve()

int resolve ( const char *  name)

Look up string and return numeric code. Throws an error if not found.

◆ getNameValueMap()

std::map<std::string,int> getNameValueMap ( ) const
inline

Returns a map with the enum members (names as key, and numeric value map value).

◆ find()

static cEnum* find ( const char *  enumName,
const char *  contextNamespace = nullptr 
)
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.

◆ get()

static cEnum* get ( const char *  enumName,
const char *  contextNamespace = nullptr 
)
static

Like find(), but throws an error if the object was not found.


The documentation for this class was generated from the following file: