Base class for several classes in the OMNeT++ library. More...
Public Member Functions
Constructors, destructor, assignment.
|cOwnedObject (const char *name, bool namepooling=true)|
|cOwnedObject (const cOwnedObject &obj)|
|cOwnedObject &||operator= (const cOwnedObject &o)|
|virtual void||parsimPack (cCommBuffer *buffer)|
|virtual void||parsimUnpack (cCommBuffer *buffer)|
Static Public Member Functions
|static long||getTotalObjectCount ()|
|static long||getLiveObjectCount ()|
|static void||resetObjectCounters ()|
|virtual cObject *||getOwner () const|
|virtual bool||isOwnedObject () const|
|virtual bool||isSoftOwner () const|
|static cDefaultList *||getDefaultOwner ()|
Base class for several classes in the OMNeT++ library.
Ownership management helps OMNeT++ catch common programming errors. As a definition, ownership means the exclusive right and duty to delete owned objects.
cOwnedObjects hold a pointer to their owner objects; the getOwner() method returns this pointer. An example will help to understand how it is used:
Some more details, in case you are writing a class that acts as a container:
Create object without a name.
The object will be initially owned by defaultOwer().
|cOwnedObject::cOwnedObject||(||const char *||name,|
|bool|| namepooling = |
Create object with given name.
The object will be initially owned by defaultOwer(). Name pooling is an optimization feature.
|static cDefaultList* cOwnedObject::getDefaultOwner||(||)||
The object that will be the owner of new or dropped (see drop()) objects.
The default owner is set internally, it is usually the simple module processing the current event.
|static long cOwnedObject::getLiveObjectCount||(||)||
Returns the number of objects that currently exist in the program.
The counter is incremented by cOwnedObject constructor and decremented by the destructor. May be useful for profiling or debugging memory leaks.
|static long cOwnedObject::getTotalObjectCount||(||)||
Returns the total number of objects created since the start of the program (or since the last reset).
The counter is incremented by cOwnedObject constructor. Counter is
signed to make it easier to detect if it overflows during very long simulation runs. May be useful for profiling or debugging memory leaks.
|virtual bool cOwnedObject::isSoftOwner||(||)|| const
An object A is a "soft owner" if it allows a B object take() an object A owns. "Hard owners" will raise an error if some other object tries to take() an object they own. The only soft owner class is cDefaultList.
Reimplemented in cDefaultList.
The assignment operator.
Derived classes should contain similar methods (
Assigment copies the contents of the object EXCEPT for the name string. If you want to copy the name string, you can do it by hand:
Ownership of the object is not affected by assigments.
|static void cOwnedObject::resetObjectCounters||(||)||