OMNeT++ Simulation Library  5.6.1
cQueue Class Reference

#include <cqueue.h>

Description

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.

See also
Iterator
Inheritance diagram for cQueue:
cOwnedObject cNamedObject cObject cPacketQueue

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 ()
 
cQueueoperator= (const cQueue &queue)
 
Redefined cObject member functions.
virtual cQueuedup () 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 cObjectremove (cObject *obj)
 
virtual cObjectpop ()
 
virtual void clear ()
 
Query functions.
virtual cObjectfront () const
 
virtual cObjectback () const
 
virtual int getLength () const
 
bool isEmpty () const
 
_OPPDEPRECATED int length () const
 
_OPPDEPRECATED bool empty () const
 
virtual cObjectget (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 ()
 
cOwnedObjectoperator= (const cOwnedObject &o)
 
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
 
cObjectfindObject (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 cDefaultListgetDefaultOwner ()
 
- Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
 
virtual void drop (cOwnedObject *obj)
 
void dropAndDelete (cOwnedObject *obj)
 

Constructor & Destructor Documentation

◆ cQueue() [1/3]

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() [2/3]

cQueue ( const char *  name,
CompareFunc  cmp 
)

Constructor. Sets up cQueue as a priority queue.

◆ cQueue() [3/3]

cQueue ( const cQueue 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.

◆ ~cQueue()

virtual ~cQueue ( )
virtual

Destructor. Deletes all contained objects that were owned by it.

Member Function Documentation

◆ operator=()

cQueue& operator= ( const cQueue queue)

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.

◆ dup()

virtual cQueue* dup ( ) const
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.

◆ str()

virtual std::string str ( ) const
overridevirtual

Produces a one-line description of the object's contents. See cObject for more details.

Reimplemented from cObject.

Reimplemented in cPacketQueue.

◆ forEachChild()

virtual void forEachChild ( cVisitor v)
overridevirtual

Calls v->visit(this) for each contained object. See cObject for more details.

Reimplemented from cObject.

◆ parsimPack()

virtual void parsimPack ( cCommBuffer buffer) const
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.

◆ parsimUnpack()

virtual void parsimUnpack ( cCommBuffer buffer)
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.

◆ setup() [1/2]

virtual void setup ( Comparator cmp)
virtual

Sets the comparator. This only affects future insertions, i.e. the queue's current content will not be re-sorted.

◆ setup() [2/2]

virtual void setup ( CompareFunc  cmp)
virtual

Sets the comparator function. This only affects future insertions, i.e. the queue's current content will not be re-sorted.

◆ insert()

virtual void insert ( cObject obj)
virtual

Adds an element to the back of the queue. Trying to insert nullptr is an error (throws cRuntimeError).

◆ insertBefore()

virtual void insertBefore ( cObject where,
cObject obj 
)
virtual

Inserts exactly before the given object. If the given position does not exist or if you try to insert nullptr, a cRuntimeError is thrown.

◆ insertAfter()

virtual void insertAfter ( cObject where,
cObject obj 
)
virtual

Inserts exactly after the given object. If the given position does not exist or if you try to insert nullptr, a cRuntimeError is thrown.

◆ remove()

virtual cObject* remove ( cObject obj)
virtual

Unlinks and returns the object given. If the object is not in the queue, nullptr is returned.

◆ pop()

virtual cObject* pop ( )
virtual

Unlinks and returns the front element in the queue. If the queue was empty, cRuntimeError is thrown.

Reimplemented in cPacketQueue.

◆ clear()

virtual void clear ( )
virtual

Empties the container. Contained objects that were owned by the queue (see getTakeOwnership()) will be deleted.

Reimplemented in cPacketQueue.

◆ front()

virtual cObject* front ( ) const
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().

◆ back()

virtual cObject* back ( ) const
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().

◆ getLength()

virtual int getLength ( ) const
virtual

Returns the number of objects contained in the queue.

◆ isEmpty()

bool isEmpty ( ) const
inline

Returns true if the queue is empty.

◆ length()

_OPPDEPRECATED int length ( ) const
inline

DEPRECATED. Use getLength() instead.

◆ empty()

_OPPDEPRECATED bool empty ( ) const
inline

DEPRECATED. Use isEmpty() instead.

◆ get()

virtual cObject* get ( int  i) const
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().

◆ contains()

virtual bool contains ( cObject obj) const
virtual

Returns true if the queue contains the given object.

◆ setTakeOwnership()

void setTakeOwnership ( bool  tk)
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.

◆ getTakeOwnership()

bool getTakeOwnership ( ) const
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.


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