#include <stack.h>
Public Member Functions | |
virtual | ~Stack () |
void | push (Entity *entity) |
Add an Entity onto the top of the Stack. | |
Entity * | pop () |
Remove the top Entity from the Stack 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("Stack") |
Protected Member Functions | |
Stack () | |
Stack (const Stack &orig) | |
virtual void | push_impl (Entity *entity)=0 |
Called by a template method. | |
virtual Entity * | pop_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.
container::Stack::Stack | ( | const Stack & | orig | ) | [protected] |
virtual Object* container::Stack::clone | ( | bool | deepCopy = false |
) | const [pure virtual] |
A polymorphic copy constructor.
Implements container::Container.
Implemented in container::StackImpl.
void container::Stack::decCount | ( | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00147 { 00148 Container::decCount(); 00149 }
void container::Stack::incCount | ( | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00140 { 00141 Container::incCount(); 00142 }
Entity * container::Stack::pop | ( | ) |
Remove the top Entity from the Stack and return a pointer to the Entity.
A template method that calls the pop_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 Stack had 2 or more items, then the formerly 2nd Entity is the top item
00063 { 00064 if (getCount() == 0) { 00065 return NULL; 00066 } 00067 Entity * e = pop_impl(); 00068 decCount(); 00069 return e; 00070 }
virtual Entity* container::Stack::pop_impl | ( | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::StackImpl.
int container::Stack::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 = pop(); e != NULL; e = pop()) { 00077 delete e; 00078 n++; 00079 } 00080 return n; 00081 }
void container::Stack::push | ( | Entity * | entity | ) |
Add an Entity onto the top of the Stack.
A template method that calls the push_impl method of the the derived class.
The Container's count is greater by one
00055 { 00056 if (entity == NULL) { 00057 return; 00058 } 00059 push_impl(entity); 00060 incCount(); 00061 }
virtual void container::Stack::push_impl | ( | Entity * | entity | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::StackImpl.
ostream & container::Stack::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::StackImpl.
00085 { 00086 return this->Container::renderState(os); 00087 }
void container::Stack::setCount | ( | int | c | ) | [inline, private] |
Hide from sub-classes.
Reimplemented from container::Container.
00133 { 00134 Container::setCount(c); 00135 }
const Object::Info * container::Stack::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::StackImpl.
00089 { 00090 return TYPE_INFO; 00091 }
const Object::Info *const container::Stack::TYPE_INFO = Object::typeInfoFactory("Stack") [static] |