# cQueue Class Reference
[Container classes]

`#include <cqueue.h>`

Inheritance diagram for cQueue:

List of all members.

## Detailed Description

Queue class.

cQueue is a container class that can hold objects derived from cObject. cQueue acts as a priority queue. The user must provide a function that can compare two objects. If no such function is given, cQueue implements a FIFO. Order (ascending or descending) can be specified.

By default, cQueue's destructor deletes all contained objects. This behaviour can be changed by calling takeOwnership(false) before inserting objects. More precisely, the behaviour can be controlled per-object: the insertion-time state of the takeOwnership flag will determine whether the inserted object will be deleted by the cQueue destructor or not.

The sorting function should look like: int CompareFunc(cObject* a, cObject* b);

They must return a negative value if a<b, 0 if a==b and a positive value if a>b.

See also:
  Iterator

## Public Member Functions

Constructors, destructor, assignment.
| cQueue (const cQueue &queue)
| cQueue (const char *name=NULL, CompareFunc cmp=NULL, bool a=false)
virtual | ~cQueue ()
cQueue & | operator= (const cQueue &queue)
Redefined cObject member functions.
virtual cPolymorphic * | dup () const
virtual std::string | info () const
virtual void | forEachChild (cVisitor *v)
virtual void | netPack (cCommBuffer *buffer)
virtual void | netUnpack (cCommBuffer *buffer)
Setup, insertion and removal functions.
virtual void | setup (CompareFunc cmp, bool a=false)
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 * | head () const
virtual cObject * | tail () const
virtual int | length () const
bool | empty () const
virtual bool | contains (cObject *obj) const
Ownership control flag.
void | takeOwnership (bool tk)
bool | takeOwnership () const

## Classes

class | Iterator
| Walks along a cQueue. More...

## Constructor & Destructor Documentation

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.

cQueue::cQueue | ( | const char * | name = `NULL`,
|  | CompareFunc | cmp = `NULL`,
|  | bool | a = `false`
| ) | `[explicit]`

| Constructor. It accepts the object name, the address of the comparing function and the sorting order (ascending=true, descending=false).

virtual cQueue::~cQueue | ( |  | ) | `[virtual]`

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

## Member Function Documentation

virtual void cQueue::clear | ( |  | ) | `[virtual]`

| As a result, the container will be empty. Contained objects that were owned by the queue will be deleted.

virtual bool cQueue::contains | ( | cObject * | obj | ) | const`[virtual]`

| Returns true if the queue contains the passed object.

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

| 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. Reimplemented from cObject.

bool cQueue::empty | ( |  | ) | const`[inline]`

| Returns true if the queue is empty.

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::head | ( |  | ) | const`[virtual]`

| Returns pointer to the object at the head of the queue. Returns NULL if the queue is empty.

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

| Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cPolymorphic.

virtual void cQueue::insert | ( | cObject * | obj | ) | `[virtual]`

| Inserts the given object into the queue, maintaining the sorting order. 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.

virtual int cQueue::length | ( |  | ) | const`[virtual]`

| Returns the number of objects contained in the queue.

virtual void cQueue::netPack | ( | cCommBuffer * | buffer | ) | `[virtual]`

| Serializes the object into a PVM or MPI send buffer. Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject.

virtual void cQueue::netUnpack | ( | cCommBuffer * | buffer | ) | `[virtual]`

| Deserializes the object from a PVM or MPI receive buffer Used by the simulation kernel for parallel execution. See cObject for more details. Reimplemented from cObject.

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 doesn't get copied; see cObject's operator=() for more details.

virtual cObject* cQueue::pop | ( |  | ) | `[virtual]`

| Unlinks and returns the last (tail) object in the queue. If the queue was empty, cRuntimeError is thrown.

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.

virtual void cQueue::setup | ( | CompareFunc | cmp,
|  | bool | a = `false`
| ) | `[virtual]`

| Changes the sort function and the sorting order. Doesn't re-sort the contents of the queue!

virtual cObject* cQueue::tail | ( |  | ) | const`[virtual]`

| Returns pointer to the last (tail) object in the queue. Returns NULL if the queue is empty.

bool cQueue::takeOwnership | ( |  | ) | const`[inline]`

| Returns the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.

void cQueue::takeOwnership | ( | bool | tk | ) | `[inline]`

| Sets the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.

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

- cqueue.h