Main Page Modules Class Hierarchy Compound List File List Compound Members

# cQueue Class Reference

`#include <cqueue.h>`

Inheritance diagram for cQueue::

List of all members.

## Public Methods

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 cObject* | dup () const
virtual void | info (char *buf)
virtual void | forEach (ForeachFunc f)
virtual int | netPack ()
virtual int | netUnpack ()
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

## 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.

Ownership of contained objects (responsibility of deletion) can be specified per-object basis (see cObject::takeOwnership()). Default is that cQueue takes the ownership of each object inserted (that is, takeOwnership(true)).

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

## 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).

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

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

## Member Function Documentation

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

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

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

| Returns true if the queue contains the passed object.

cObject * 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.

void cQueue::forEach ( | ForeachFunc f )`[virtual]`

| Calls the given function for each contained object. Reimplemented from cObject.

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

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

void cQueue::info ( | char * buf )`[virtual]`

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

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 cException).

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, cException is thrown.

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, cException is thrown.

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

| Returns the number of objects contained in the queue.

int cQueue::netPack ( | )`[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.

int cQueue::netUnpack ( | )`[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.

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

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

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::setup ( | CompareFunc cmp,
| bool a = false )`[virtual]`

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

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

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

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

- cqueue.h