diff --git a/Foundation_Classes/List.cpp b/Foundation_Classes/List.cpp index 5b52f90..7bb5387 100644 --- a/Foundation_Classes/List.cpp +++ b/Foundation_Classes/List.cpp @@ -7,6 +7,8 @@ #include #include "ListIterator.h" +// Initializes the list. +// The size parameter is a hint for the initial number of elements. template List::List(long size) : _size(size), _count(0) { _items = new Item[size]; @@ -25,6 +27,8 @@ List::List(List& other) { } } +// Frees the list's internal data structures but not the elements in the list. The class is +// not designed for subclassing; therefore the destructor isn't virtual. template List::~List() { delete[] _items; @@ -50,11 +54,13 @@ List& List::operator=(const List& other) { return *this; } +// Returns the number of objects in the list. template long List::Count() const { return _count; } +// Returns the object at the given index. // TODO: // * solve warning 'control reaches end of non-void function'. // * shouldn't the test be if (index < _count) ??? @@ -67,11 +73,13 @@ Item& List::Get(long index) const { } } +// Returns the first object in the list. template Item& List::First() const { return Get(0); } +// Returns the last object in the list. template Item& List::Last() const { return Get(Count()-1); @@ -87,7 +95,7 @@ bool List::Includes(const Item& anItem) const { return false; } - +// Adds the argument to the list, making it the last element. template void List::Append(const Item& anItem) { if (_count <= _size) { @@ -96,6 +104,7 @@ void List::Append(const Item& anItem) { } } +// Adds the argument to the list, making it the first element. template void List::Prepend(const Item& anItem) { if (_count <= _size) { @@ -106,6 +115,8 @@ void List::Prepend(const Item& anItem) { } } +// Removes the given element from the list. This operation requires that the type of +// elements in the list supports the == operator for comparison. template void List::Remove(const Item& anItem) { for (long i = 0; i < Count(); i++) { @@ -115,32 +126,37 @@ void List::Remove(const Item& anItem) { } } +// Removes the last element from the list. template void List::RemoveLast() { RemoveAt(Count()-1); } +// Removes the first element from the list. template void List::RemoveFirst() { RemoveAt(0); } +// Removes all elements from the list. template void List::RemoveAll() { _count = 0; } - +// Returns the top element (when the List is viewed as a stack). template Item& List::Top() const { return Last(); } +// Pushes the element onto the stack. template void List::Push(const Item& anItem) { Append(anItem); } +// Pops the top element from the stack. template Item& List::Pop() {