#include <queue.h>
Public Member Functions | |
virtual | ~Queue () |
void | enqueue (Entity *entity) |
Add an Entity onto the end of the Queue. | |
Entity * | dequeue () |
Remove the first Entity from the Queue and return a pointer to the Entity. | |
int | purgeContents () |
Empty the contents of the container, deleting all Entities. | |
virtual ostream & | renderState (ostream &os) const |
Write the state of an Object for debugging and demonstration. | |
virtual const Info * | typeInfo () const |
Return the instance of Object::Info that describes the class of this object. | |
virtual Object * | clone (bool deepCopy=false) const =0 |
A polymorphic copy constructor. | |
Static Public Attributes | |
static const Info *const | TYPE_INFO = Object::typeInfoFactory("Queue") |
Protected Member Functions | |
Queue () | |
Queue (const Queue &orig) | |
virtual void | enqueue_impl (Entity *entity)=0 |
Called by a template method. | |
virtual Entity * | dequeue_impl ()=0 |
Called by a template method. | |
Private Member Functions | |
void | setCount (int c) |
Hide from sub-classes. | |
void | incCount () |
Hide from sub-classes. | |
void | decCount () |
Hide from sub-classes. |
Allows duplicates. Is unbounded.
virtual Object* container::Queue::clone | ( | bool | deepCopy = false |
) | const [pure virtual] |
A polymorphic copy constructor.
Implements container::Container.
Implemented in container::QueueImpl.
void container::Queue::decCount | ( | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00151 { 00152 Container::decCount(); 00153 }
Entity * container::Queue::dequeue | ( | ) |
Remove the first Entity from the Queue and return a pointer to the Entity.
A template method that calls the dequeue_impl method of the the derived class.
The caller is responsible for deleting the extracted Entity
The Container's count is lesser by one
If the Queue had 2 or more items, then the formerly 2nd Entity is the first item
00063 { 00064 if (getCount() == 0) { 00065 return NULL; 00066 } 00067 Entity * e = dequeue_impl(); 00068 decCount(); 00069 return e; 00070 }
virtual Entity* container::Queue::dequeue_impl | ( | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::QueueImpl.
void container::Queue::enqueue | ( | Entity * | entity | ) |
Add an Entity onto the end of the Queue.
A template method that calls the enqueue_impl method of the the derived class.
If the queue was empty, the specified entity can be considered to be both the first and last item in the queue
The Container's count is greater by one
00055 { 00056 if (entity == NULL) { 00057 return; 00058 } 00059 enqueue_impl(entity); 00060 incCount(); 00061 }
virtual void container::Queue::enqueue_impl | ( | Entity * | entity | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::QueueImpl.
void container::Queue::incCount | ( | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00144 { 00145 Container::incCount(); 00146 }
int container::Queue::purgeContents | ( | ) | [virtual] |
Empty the contents of the container, deleting all Entities.
This method is used by the destructor.
The memory for all Entities is freed
Implements container::Container.
00074 { 00075 int n = 0; 00076 for (Entity* e = dequeue(); e != NULL; e = dequeue()) { 00077 delete e; 00078 n++; 00079 } 00080 return n; 00081 }
ostream & container::Queue::renderState | ( | ostream & | os | ) | const [virtual] |
Write the state of an Object for debugging and demonstration.
This method must not change the state of an Object; adding or removing debug statements should not change the behavior of a class. The implementation must be robust, e.g., NULL safe, etc. and work without an unrecoverable error for any state, excluding an Object's time of construction and destruction. It is not required for the implementation to be thread safe.
Reimplemented from container::Container.
Reimplemented in container::QueueImpl.
00085 { 00086 return this->Container::renderState(os); 00087 }
void container::Queue::setCount | ( | int | c | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00137 { 00138 Container::setCount(c); 00139 }
const Object::Info * container::Queue::typeInfo | ( | ) | const [virtual] |
Return the instance of Object::Info that describes the class of this object.
Instantiation of Object::Info is controlled by the protected method Object::typeInfoFactory(const string&). Each sub-class of Object should create one and only one instance of Object::Info.
Reimplemented from container::Container.
Reimplemented in container::QueueImpl.
00089 { 00090 return TYPE_INFO; 00091 }
const Object::Info *const container::Queue::TYPE_INFO = Object::typeInfoFactory("Queue") [static] |