OMNeT++ Simulation Library
5.6.1
|
#include <cqueue.h>
Queue class for objects derived from cObject.
The default behavior of cQueue is a FIFO: you insert elements at the back using insert(), and remove them at the front using pop().
cQueue may be set up to act as a priority queue. This requires the user to supply a comparison function.
Ownership of cOwnedObjects may be controlled by invoking setTakeOwnership() prior to inserting objects. Objects that cannot track their ownership (cObject but not cOwnedObject) are always treated as owned. Whether an object is owned or not affects the operation of the destructor, clean(), the copy constructor and the dup() method.
Classes | |
class | Comparator |
Base class for object comparators, used by cQueue for priority queuing. More... | |
class | Iterator |
Walks along a cQueue. More... | |
Public Types | |
typedef int(* | CompareFunc) (cObject *a, cObject *b) |
Function for comparing two cObjects, used by cQueue for priority queuing. More... | |
Public Member Functions | |
Constructors, destructor, assignment. | |
cQueue (const char *name=nullptr, Comparator *cmp=nullptr) | |
cQueue (const char *name, CompareFunc cmp) | |
cQueue (const cQueue &queue) | |
virtual | ~cQueue () |
cQueue & | operator= (const cQueue &queue) |
Redefined cObject member functions. | |
virtual cQueue * | dup () const override |
virtual std::string | str () const override |
virtual void | forEachChild (cVisitor *v) override |
virtual void | parsimPack (cCommBuffer *buffer) const override |
virtual void | parsimUnpack (cCommBuffer *buffer) override |
Setup, insertion and removal functions. | |
virtual void | setup (Comparator *cmp) |
virtual void | setup (CompareFunc cmp) |
virtual void | insert (cObject *obj) |
virtual void | insertBefore (cObject *where, cObject *obj) |
virtual void | insertAfter (cObject *where, cObject *obj) |
virtual cObject * | remove (cObject *obj) |
virtual cObject * | pop () |
virtual void | clear () |
Query functions. | |
virtual cObject * | front () const |
virtual cObject * | back () const |
virtual int | getLength () const |
bool | isEmpty () const |
_OPPDEPRECATED int | length () const |
_OPPDEPRECATED bool | empty () const |
virtual cObject * | get (int i) const |
virtual bool | contains (cObject *obj) const |
Ownership control flag. | |
void | setTakeOwnership (bool tk) |
bool | getTakeOwnership () 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 cObject * | getOwner () 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 () |
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) | |
virtual | ~cObject () |
virtual const char * | getClassName () const |
bool | isName (const char *s) const |
virtual const char * | getFullName () const |
virtual std::string | getFullPath () const |
const cObject * | getThisPtr () const |
virtual _OPPDEPRECATED std::string | info () const |
virtual _OPPDEPRECATED std::string | detailedInfo () const |
cObject * | findObject (const char *name, bool deep=true) |
void | copyNotSupported () const |
Additional Inherited Members | |
Static Public Member Functions inherited from cOwnedObject | |
static long | getTotalObjectCount () |
static long | getLiveObjectCount () |
static void | resetObjectCounters () |
static cDefaultList * | getDefaultOwner () |
Protected Member Functions inherited from cObject | |
virtual void | take (cOwnedObject *obj) |
virtual void | drop (cOwnedObject *obj) |
void | dropAndDelete (cOwnedObject *obj) |
cQueue | ( | const char * | name = nullptr , |
Comparator * | cmp = nullptr |
||
) |
Constructor. When comparator argument is nullptr, the queue will act as FIFO, otherwise as priority queue.
cQueue | ( | const char * | name, |
CompareFunc | cmp | ||
) |
Constructor. Sets up cQueue as a priority queue.
Copy constructor. Contained objects that are owned by the queue will be duplicated so that the new queue will have its own copy of them.
|
virtual |
Destructor. Deletes all contained objects that were owned by it.
Assignment operator. Duplication and assignment work all right with cQueue. Contained objects that are owned by the queue will be duplicated so that the new queue will have its own copy of them.
The name member is not copied; see cNamedObject's operator=() for more details.
|
inlineoverridevirtual |
Duplication and assignment are supported by cQueue. Contained objects that are owned by the queue will be duplicated so that the new queue will have its own copy of them.
Reimplemented from cObject.
Reimplemented in cPacketQueue.
|
overridevirtual |
Produces a one-line description of the object's contents. See cObject for more details.
Reimplemented from cObject.
Reimplemented in cPacketQueue.
|
overridevirtual |
|
overridevirtual |
Serializes the object into an MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details.
Reimplemented from cOwnedObject.
Reimplemented in cPacketQueue.
|
overridevirtual |
Deserializes the object from an MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details.
Reimplemented from cOwnedObject.
Reimplemented in cPacketQueue.
|
virtual |
Sets the comparator. This only affects future insertions, i.e. the queue's current content will not be re-sorted.
|
virtual |
Sets the comparator function. This only affects future insertions, i.e. the queue's current content will not be re-sorted.
|
virtual |
Adds an element to the back of the queue. Trying to insert nullptr is an error (throws cRuntimeError).
Inserts exactly before the given object. If the given position does not exist or if you try to insert nullptr, a cRuntimeError is thrown.
Inserts exactly after the given object. If the given position does not exist or if you try to insert nullptr, a cRuntimeError is thrown.
Unlinks and returns the object given. If the object is not in the queue, nullptr is returned.
|
virtual |
Unlinks and returns the front element in the queue. If the queue was empty, cRuntimeError is thrown.
Reimplemented in cPacketQueue.
|
virtual |
Empties the container. Contained objects that were owned by the queue (see getTakeOwnership()) will be deleted.
Reimplemented in cPacketQueue.
|
virtual |
Returns pointer to the object at the front of the queue. This is the element to be returned by pop(). Returns nullptr if the queue is empty.
Reimplemented in cPacketQueue.
Referenced by cPacketQueue::front().
|
virtual |
Returns pointer to the last (back) element in the queue. This is the element most recently added by insert(). Returns nullptr if the queue is empty.
Reimplemented in cPacketQueue.
Referenced by cPacketQueue::back().
|
virtual |
Returns the number of objects contained in the queue.
|
inline |
Returns true if the queue is empty.
|
inline |
DEPRECATED. Use getLength() instead.
|
inline |
DEPRECATED. Use isEmpty() instead.
|
virtual |
Returns the ith element in the queue, or nullptr if i is out of range. get(0) returns the front element. This method performs linear search.
Reimplemented in cPacketQueue.
Referenced by cPacketQueue::get().
|
virtual |
Returns true if the queue contains the given object.
|
inline |
Sets the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it. It does not affect objects already in the queue. When an inserted object is owned by the queue, that means it will be deleted when the queue object is deleted or cleared, and will be duplicated when the queue object is duplicated or copied.
Setting the flag to false does not affect the treatment of objects that are NOT cOwnedObject. Since they do not support the ownership protocol, they will always be treated by the queue as owned objects.
|
inline |
Returns the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it. See setTakeOwnedship() for more details.