container::Stack Class Reference

Abstract base class for all stack containers. More...

#include <stack.h>

Inheritance diagram for container::Stack:

Inheritance graph
[legend]
Collaboration diagram for container::Stack:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~Stack ()
void push (Entity *entity)
 Add an Entity onto the top of the Stack.
Entitypop ()
 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 InfotypeInfo () const
 Return the instance of Object::Info that describes the class of this object.
virtual Objectclone (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 Entitypop_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.


Detailed Description

Abstract base class for all stack containers.

Allows duplicates. Is unbounded.


Constructor & Destructor Documentation

container::Stack::Stack (  )  [protected]

00047 { }

container::Stack::Stack ( const Stack orig  )  [protected]

00049 { }

container::Stack::~Stack (  )  [virtual]

00051 { }


Member Function Documentation

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    }

Here is the caller graph for this function:

void container::Stack::incCount (  )  [inline, private]

Hide from sub-classes.

Reimplemented from container::Container.

00140                           {
00141       Container::incCount();
00142    }

Here is the caller graph for this function:

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.

Returns:
A pointer to the Entity that was removed from the top of the stack
Precondition:
There is at least one item in the Stack
Postcondition:
The Entity (formerly the top item) is not in the list

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

If the Stack had only 1 item, then the Stack is empty

00063                     {
00064    if (getCount() == 0) {
00065       return NULL;
00066    }
00067    Entity * e = pop_impl();
00068    decCount();
00069    return e;
00070 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual Entity* container::Stack::pop_impl (  )  [protected, pure virtual]

Called by a template method.

See also:
Details documented in method pop

Implemented in container::StackImpl.

Here is the caller graph for this function:

int container::Stack::purgeContents (  )  [virtual]

Empty the contents of the container, deleting all Entities.

This method is used by the destructor.

Returns:
The number of Entity objects deleted
Postcondition:
isEmpty() is true

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 }

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Precondition:
The specified entity pointer is not null
Postcondition:
The specified entity is the top item on the Stack

The Container's count is greater by one

00055                                {
00056    if (entity == NULL) {
00057       return;
00058    }
00059    push_impl(entity);
00060    incCount();
00061 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void container::Stack::push_impl ( Entity entity  )  [protected, pure virtual]

Called by a template method.

See also:
Details documented in method push

Implemented in container::StackImpl.

Here is the caller graph for this function:

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.

Precondition:
The Object has been fully constructed and is not in the process of destruction
Postcondition:
The state of the Object is unchanged

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 }

Here is the caller graph for this function:


Member Data Documentation

const Object::Info *const container::Stack::TYPE_INFO = Object::typeInfoFactory("Stack") [static]

Reimplemented from container::Container.

Reimplemented in container::StackImpl.


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

Generated on Tue Jun 16 23:13:00 2009 by  doxygen 1.5.9