Internal class, used as a base class for modules and channels. More...
#include <cdefaultlist.h>
Public Member Functions | |
Constructors, destructor, assignment. | |
cDefaultList (const char *name=NULL) | |
virtual | ~cDefaultList () |
Redefined cObject methods. | |
virtual bool | isSoftOwner () const |
virtual std::string | info () const |
virtual void | forEachChild (cVisitor *v) |
virtual void | parsimPack (cCommBuffer *buffer) |
virtual void | parsimUnpack (cCommBuffer *buffer) |
Container functions. | |
bool | getPerformFinalGC () const |
virtual void | setPerformFinalGC (bool b) |
int | defaultListSize () const |
cOwnedObject * | defaultListGet (int k) |
bool | defaultListContains (cOwnedObject *obj) const |
Protected Member Functions | |
Redefined cObject member functions | |
void | take (cOwnedObject *obj) |
void | drop (cOwnedObject *obj) |
Friends | |
class | cObject |
class | cOwnedObject |
class | cChannelType |
Internal class, used as a base class for modules and channels.
It is not intended for subclassing outside the simulation kernel.
cDefaultList acts as a "soft owner" (see object ownership discussion in cOwnedObject documentation).
virtual cDefaultList::~cDefaultList | ( | ) | [virtual] |
Destructor.
The contained objects will be deleted.
cOwnedObject* cDefaultList::defaultListGet | ( | int | k | ) |
Get the element at the given position.
k must be between 0 and defaultListSize()-1 (inclusive). If the index is out of bounds, NULL is returned.
virtual void cDefaultList::forEachChild | ( | cVisitor * | v | ) | [virtual] |
Calls v->visit(this) for each contained object.
See cObject for more details.
Reimplemented from cObject.
Reimplemented in cChannel, cComponent, cModule, and cSimpleModule.
bool cDefaultList::getPerformFinalGC | ( | ) | const [inline] |
Whether the destructor will delete garbage objects (owned objects that have not been deallocated by destructors of derived classes); see setPerformFinalGC() for details.
The default setting is false.
virtual std::string cDefaultList::info | ( | ) | const [virtual] |
Produces a one-line description of the object's contents.
See cObject for more details.
Reimplemented from cObject.
Reimplemented in cChannel, cDatarateChannel, cModule, and cSimpleModule.
virtual void cDefaultList::parsimPack | ( | cCommBuffer * | buffer | ) | [virtual] |
Packing and unpacking cannot be supported with this class.
This method raises an error.
Reimplemented from cNoncopyableOwnedObject.
Reimplemented in cChannel.
virtual void cDefaultList::parsimUnpack | ( | cCommBuffer * | buffer | ) | [virtual] |
Packing and unpacking cannot be supported with this class.
This method raises an error.
Reimplemented from cNoncopyableOwnedObject.
Reimplemented in cChannel.
virtual void cDefaultList::setPerformFinalGC | ( | bool | b | ) | [inline, virtual] |
Enables deleting of garbage objects in the destructor.
Garbage objects are objects that are on this default list at destruct time (see defaultListSize() and defaultListGet()); they are practically objects owned by this module or channel that have not been deallocated by destructors of derived classes.
This feature is turned off by default, because it cannot be implemented to work correctly in all cases. The garbage collection routine invokes the delete
operator on all objects on the default list. This, however, causes problems (crash) in some cases: when the object has been allocated as an element in an array (e.g. new cQueue[10]
), when the object is part of another object (e.g. struct X {cQueue q;};
), or any other case when the object's pointer is not deleteable. Note that the presence of such data structures in a module does not automatically rule out the use of the final GC mechanism. Final GC can still be turned on if care is taken that the module's destructor deallocates those arrays and structs/objects, so that the contained objects disappear before the GC process could see them. Conclusion: only turn on final GC if you know what you are doing.