#include <list.h>
Public Member Functions | |
virtual | ~List () |
bool | add (Entity *entity) |
Add an Entity to the list. | |
bool | deleteCurrent () |
Remove the current Entity from the list and delete it from memory. | |
Entity * | extractCurrentEntity () |
Remove the current Entity from the list and return a pointer to it. | |
virtual bool | isFirst () const =0 |
Return true if the cursor is pointing to first real node, false otherwise. | |
virtual bool | isLast () const =0 |
Determine whether the list cursor is pointing to the last Entity. | |
virtual bool | isTail () const =0 |
Return true if the cursor is pointing to the list tail, false otherwise. | |
virtual bool | toFirst ()=0 |
Point the cursor to the first Entity in the list. | |
virtual bool | toLast ()=0 |
Point the cursor to the last Entity in the list. | |
virtual void | toTail ()=0 |
Point the cursor to the tail of the list. | |
virtual bool | toNext ()=0 |
Point the cursor to the next Entity in the list. | |
virtual bool | toPrev ()=0 |
Point the cursor to the previous Entity in the list. | |
virtual Entity * | currentEntity ()=0 |
Return a pointer to the current Entity. | |
virtual void | locateEntity (const Entity &key, int &index, Entity *&entity)=0 |
Locate the first Entity that matches the specified key. | |
virtual Entity * | entityAt (int index)=0 |
Return a pointer to the Entity found at the specified, zero-based index. | |
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("List") |
static const int | NO_MATCHING_ENTITY_INDEX_FLAG = -1 |
Returned as an index value by method locateEntity() when a matching entity was not found in the list. | |
Protected Member Functions | |
List () | |
List (const List &orig) | |
virtual bool | deleteCurrent_impl ()=0 |
Called by a template method. | |
virtual Entity * | extractCurrentEntity_impl ()=0 |
Called by a template method. | |
virtual bool | add_impl (Entity *entity)=0 |
Called by a template method. |
May allow duplicates. Derived classes may choose to disallow duplicates.
container::List::List | ( | const List & | orig | ) | [protected] |
bool container::List::add | ( | Entity * | entity | ) |
Add an Entity to the list.
This is the default method for adding an Entity object to a List. Derived classes determine the exact behavior: where in the list it will be added, whether duplicates are allowed, etc. As with all methods that add items to a Container, no copy of the Entity is made. The Container takes responsibility to delete the Entity.
If false is returned then the List's state is unchanged
In either case (a return value of true or false) the list cursor will remain unchanged. It will not be pointing to the new Entity.
00057 { 00058 int oldCount = getCount(); 00059 if (add_impl(entity)) { 00060 if (oldCount == getCount()) { 00061 incCount(); 00062 } 00063 return true; 00064 } 00065 00066 return false; 00067 }
virtual bool container::List::add_impl | ( | Entity * | entity | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::OrderedArrayList, container::OrderedLinkedList, container::SortedArrayList, and container::SortedLinkedList.
virtual Object* container::List::clone | ( | bool | deepCopy = false |
) | const [pure virtual] |
A polymorphic copy constructor.
Implements container::Container.
Implemented in container::ArrayList, container::OrderedArrayList, container::OrderedLinkedList, container::OrderedList, container::SortedArrayList, container::SortedLinkedList, and container::SortedList.
virtual Entity* container::List::currentEntity | ( | ) | [pure virtual] |
Return a pointer to the current Entity.
Implemented in container::ArrayList, and container::LinkedList.
bool container::List::deleteCurrent | ( | ) |
Remove the current Entity from the list and delete it from memory.
The list cursor points an Entity
The Entity indicated by the cursor is deleted from memory
The cursor points to the next Entity in the list or to the tail of the list if the deleted Entity was last
00069 { 00070 if (deleteCurrent_impl()) { 00071 decCount(); 00072 return true; 00073 } 00074 00075 return false; 00076 }
virtual bool container::List::deleteCurrent_impl | ( | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::ArrayList, and container::LinkedList.
virtual Entity* container::List::entityAt | ( | int | index | ) | [pure virtual] |
Return a pointer to the Entity found at the specified, zero-based index.
A valid index must be specified. For example, if count is 1 then the only valid index is 0.
Implemented in container::ArrayList, and container::LinkedList.
Entity * container::List::extractCurrentEntity | ( | ) |
Remove the current Entity from the list and return a pointer to it.
The caller becomes responsible for disposing of the Entity. If successful, the list cursor ends up pointing the next Entity in the list.
The caller is responsible for deleting the extracted Entity
The list cursor points to the next Entity in the list or to the tail of the list if the extracted Entity was last
00078 { 00079 Entity * e = extractCurrentEntity_impl(); 00080 decCount(); 00081 return e; 00082 }
virtual Entity* container::List::extractCurrentEntity_impl | ( | ) | [protected, pure virtual] |
Called by a template method.
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::isFirst | ( | ) | const [pure virtual] |
Return true if the cursor is pointing to first real node, false otherwise.
TRUE is only possible if the list is not empty.
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::isLast | ( | ) | const [pure virtual] |
Determine whether the list cursor is pointing to the last Entity.
true is only possible if the list is not empty.
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::isTail | ( | ) | const [pure virtual] |
Return true if the cursor is pointing to the list tail, false otherwise.
false is only possible if the list is not empty.
Implemented in container::ArrayList, and container::LinkedList.
virtual void container::List::locateEntity | ( | const Entity & | key, | |
int & | index, | |||
Entity *& | entity | |||
) | [pure virtual] |
Locate the first Entity that matches the specified key.
The position is returned as a zero based index. The first Entity that matches is returned. No further checking of the list is performed.
entity will point to the matching Entity. If a matching Entity is not found, NULL is returned in entity instead.
Implemented in container::ArrayList, container::LinkedList, and container::SortedArrayList.
int container::List::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.
00084 { 00085 if (!toFirst()) return 0; 00086 int i = 0; 00087 while (deleteCurrent()) { 00088 i++; 00089 } 00090 return i; 00091 }
ostream & container::List::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::ArrayList, container::LinkedList, container::OrderedArrayList, container::OrderedLinkedList, container::OrderedList, container::SortedArrayList, container::SortedLinkedList, and container::SortedList.
00095 { 00096 return this->Container::renderState(os); 00097 }
virtual bool container::List::toFirst | ( | ) | [pure virtual] |
Point the cursor to the first Entity in the list.
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::toLast | ( | ) | [pure virtual] |
Point the cursor to the last Entity in the list.
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::toNext | ( | ) | [pure virtual] |
Point the cursor to the next Entity in the list.
false if the cursor was moved to the tail of list
false if the cursor was already pointing to the tail
The list cursor is not pointing to the tail
Implemented in container::ArrayList, and container::LinkedList.
virtual bool container::List::toPrev | ( | ) | [pure virtual] |
Point the cursor to the previous Entity in the list.
Calling toPrev() never leaves the cursor pointing to the head of the list.
false if the cursor is already pointing the first Entity in the list
false if the list is empty
The list cursor is not pointing to the first Entity in the list
Implemented in container::ArrayList, and container::LinkedList.
virtual void container::List::toTail | ( | ) | [pure virtual] |
Point the cursor to the tail of the list.
This method should always succeed. A List should always have the concept a tail, i.e., the node or element just beyond the end of the list. No Entity is available at the tail cursor position.
Implemented in container::ArrayList, and container::LinkedList.
const Object::Info * container::List::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::ArrayList, container::LinkedList, container::OrderedArrayList, container::OrderedLinkedList, container::OrderedList, container::SortedArrayList, container::SortedLinkedList, and container::SortedList.
00099 { 00100 return TYPE_INFO; 00101 }
const int container::List::NO_MATCHING_ENTITY_INDEX_FLAG = -1 [static] |
Returned as an index value by method locateEntity() when a matching entity was not found in the list.
const Object::Info *const container::List::TYPE_INFO = Object::typeInfoFactory("List") [static] |
Reimplemented from container::Container.
Reimplemented in container::ArrayList, container::LinkedList, container::OrderedArrayList, container::OrderedLinkedList, container::OrderedList, container::SortedArrayList, container::SortedLinkedList, and container::SortedList.