cQueue Class Reference
[Container classes]

Queue class for objects derived from cObject. More...

#include <cqueue.h>

Inheritance diagram for cQueue:
cOwnedObject cNamedObject cObject cPacketQueue

List of all members.

Classes

class  Iterator
 Walks along a cQueue. More...

Public Member Functions

Constructors, destructor, assignment.

 cQueue (const char *name=NULL, CompareFunc cmp=NULL)
 cQueue (const cQueue &queue)
virtual ~cQueue ()
cQueueoperator= (const cQueue &queue)
Redefined cObject member functions.

virtual cQueuedup () const
virtual std::string info () const
virtual void forEachChild (cVisitor *v)
virtual void parsimPack (cCommBuffer *buffer)
virtual void parsimUnpack (cCommBuffer *buffer)
Setup, insertion and removal functions.

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
int length () const
bool empty () const
cObjectget (int i) const
virtual bool contains (cObject *obj) const
Ownership control flag.

void setTakeOwnership (bool tk)
bool getTakeOwnership () const

Detailed Description

Queue class for objects derived from cObject.

The default behaviour 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

Constructor & Destructor Documentation

cQueue::cQueue ( const char *  name = NULL,
CompareFunc  cmp = NULL 
)

Constructor.

When comparison function argument is NULL, the queue will act as FIFO, otherwise as priority queue.

cQueue::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.

virtual cQueue::~cQueue (  )  [virtual]

Destructor.

Deletes all contained objects that were owned by it.


Member Function Documentation

virtual cObject* cQueue::back (  )  const [virtual]

Returns pointer to the last (back) element in the queue.

This is the element most recently added by insert(). Returns NULL if the queue is empty.

Reimplemented in cPacketQueue.

Referenced by cPacketQueue::get().

virtual void cQueue::clear (  )  [virtual]

Empties the container.

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

Reimplemented in cPacketQueue.

virtual cQueue* cQueue::dup (  )  const [inline, virtual]

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.

virtual void cQueue::forEachChild ( cVisitor v  )  [virtual]

Calls v->visit(this) for each contained object.

See cObject for more details.

Reimplemented from cObject.

virtual cObject* cQueue::front (  )  const [virtual]

Returns pointer to the object at the front of the queue.

This is the element to be returned by pop(). Returns NULL if the queue is empty.

Reimplemented in cPacketQueue.

Referenced by cPacketQueue::back().

cObject* cQueue::get ( int  i  )  const

Returns the ith element in the queue, or NULL if i is out of range.

get(0) returns the front element. This method performs linear search.

Reimplemented in cPacketQueue.

bool cQueue::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.

virtual std::string cQueue::info (  )  const [virtual]

Produces a one-line description of the object's contents.

See cObject for more details.

Reimplemented from cObject.

Reimplemented in cPacketQueue.

virtual void cQueue::insert ( cObject obj  )  [virtual]

Adds an element to the back of the queue.

Trying to insert a NULL pointer is an error (throws cRuntimeError).

virtual void cQueue::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 a NULL pointer, cRuntimeError is thrown.

virtual void cQueue::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 a NULL pointer, cRuntimeError is thrown.

cQueue& 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.

virtual void cQueue::parsimPack ( cCommBuffer buffer  )  [virtual]

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.

virtual void cQueue::parsimUnpack ( cCommBuffer buffer  )  [virtual]

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 cObject* cQueue::pop (  )  [virtual]

Unlinks and returns the front element in the queue.

If the queue was empty, cRuntimeError is thrown.

Reimplemented in cPacketQueue.

virtual cObject* cQueue::remove ( cObject obj  )  [virtual]

Unlinks and returns the object given.

If the object is not in the queue, NULL pointer is returned.

void cQueue::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.

virtual void cQueue::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.


The documentation for this class was generated from the following file:
Generated on Tue Dec 2 11:16:30 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3