#include <cqueue.h>
Inheritance diagram for cQueue:
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.
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... |
|
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. |
|
Constructor. It accepts the object name, the address of the comparing function and the sorting order (ascending=true, descending=false). |
|
Destructor. Deletes all contained objects that were owned by it. |
|
As a result, the container will be empty. Contained objects that were owned by the queue will be deleted. |
|
Returns true if the queue contains the passed object.
|
|
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. |
|
Returns true if the queue is empty.
|
|
Calls v->visit(this) for each contained object. See cObject for more details. Reimplemented from cObject. |
|
Returns pointer to the object at the head of the queue. Returns NULL if the queue is empty. |
|
Produces a one-line description of object contents into the buffer passed as argument. See cObject for more details. Reimplemented from cPolymorphic. |
|
Inserts the given object into the queue, maintaining the sorting order. Trying to insert a NULL pointer is an error (throws cRuntimeError). |
|
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. |
|
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. |
|
Returns the number of objects contained in the queue.
|
|
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. |
|
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. |
|
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. |
|
Unlinks and returns the last (tail) object in the queue. If the queue was empty, cRuntimeError is thrown. |
|
Unlinks and returns the object given. If the object is not in the queue, NULL pointer is returned. |
|
Changes the sort function and the sorting order. Doesn't re-sort the contents of the queue! |
|
Returns pointer to the last (tail) object in the queue. Returns NULL if the queue is empty. |
|
Returns the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.
|
|
Sets the flag which determines whether the container object should automatically take ownership of the objects that are inserted into it.
|