ArrayList< T > Class Template Reference

An array-based list class. More...

#include <rimPhysicsArrayList.h>

List of all members.

Public Member Functions

 ArrayList ()
 Create a new empty array list with the default capacity of 8 elements.
 ArrayList (int newCapacity)
 Create a new empty array list with the specified initial capacity.
 ArrayList (const ArrayList< T > &arrayList)
 Create a copy of an existing array list. This is a deep copy.
ArrayList< T > & operator= (const ArrayList< T > &arrayList)
 Assign this array list with the contents of another. This is a deep copy.
 ~ArrayList ()
 Destroy an array list.
void add (T newElement)
 Add an element to the end of the list.
void insert (int index, T newElement)
 Insert an element at the specified index of the list.
set (int index, T anElement)
 Set an element at the specified index of the list to a new value.
removeAtIndex (int index)
 Remove the element at the specified index.
removeAtIndexUnordered (int index)
 Remove the element at the specified index.
bool remove (const T &anElement)
 Remove the first element equal to the parameter element.
bool removeUnordered (const T &anElement)
 Remove the first element equal to the parameter element.
removeLast ()
 Remove the last element in the array list.
bool contains (const T &anElement) const
void clear ()
bool isEmpty () const
 Return whether or not the array list has any elements.
int getSize () const
 Get the number of elements in the array list.
const T & get (int index) const
 Return the element at the specified index.
T & get (int index)
 Return the element at the specified index.
int getIndex (const T &element) const
 Return the index of the specified element.
getSimilar (const T &element, bool(*areSimilar)(const T &, const T &)) const
 Return an element of the list similar to the parameter.
int getSimilarIndex (const T &element, bool(*areSimilar)(T, T)) const
 Return an the index of an element of the list similar to the parameter.
const T & operator() (int index) const
 Return the element at the specified index.
T & operator() (int index)
 Return the element at the specified index.
const T & operator[] (int index) const
 Return the element at the specified index.
T & operator[] (int index)
 Return the element at the specified index.
Iterator getIterator ()
 Return a new iterator for the array list.

Private Member Functions

void resize ()
 double the size of the element array to increase the capacity of the list
void intializeArray ()
 initialize the size of the element array to the specified size
bool checkBounds (int index) const
 return whether or not the specified index is within the bounds of the list

Private Attributes

T * array
 The array for the array list containing all elements.
int numElements
 The number of elements in the array list.
int capacity
 The size of the array in this array list.

Static Private Attributes

static const int DEFAULT_INITIAL_CAPACITY = 8
 The default initial capacity of an array list.

Classes

class  Iterator
 Iterator class for an array list. More...


Detailed Description

template<typename T>
class ArrayList< T >

An array-based list class.

This class is an unordered collection of an arbitrary number of generic elements. It is array-based, making random access fast. The order of the elements is not perserved when elements are removed (last element is swaped into the removed element's place). It is designed to be as fast a possible. It has an iterator for iterating over the elements of the list in any order. The capacity of the array list defaults to 8 elements, and doubles when more space is needed. The initial capacity of the array list is setable in a constructor.


Constructor & Destructor Documentation

template<typename T>
ArrayList< T >::ArrayList (  )  [inline]

Create a new empty array list with the default capacity of 8 elements.

template<typename T>
ArrayList< T >::ArrayList ( int  newCapacity  )  [inline]

Create a new empty array list with the specified initial capacity.

template<typename T>
ArrayList< T >::ArrayList ( const ArrayList< T > &  arrayList  )  [inline]

Create a copy of an existing array list. This is a deep copy.

template<typename T>
ArrayList< T >::~ArrayList (  )  [inline]

Destroy an array list.


Member Function Documentation

template<typename T>
ArrayList<T>& ArrayList< T >::operator= ( const ArrayList< T > &  arrayList  )  [inline]

Assign this array list with the contents of another. This is a deep copy.

template<typename T>
void ArrayList< T >::add ( newElement  )  [inline]

Add an element to the end of the list.

NULL is accepted as a possible value.

Parameters:
newElement - the new element to add to the end of the list

template<typename T>
void ArrayList< T >::insert ( int  index,
newElement 
) [inline]

Insert an element at the specified index of the list.

NULL is accepted as a possible value. If the index is out of the valid indices for the array list, then the element is added instead to the end of the list.

Parameters:
index - the index at which to insert the new element
newElement - the new element to insert in the list

template<typename T>
T ArrayList< T >::set ( int  index,
anElement 
) [inline]

Set an element at the specified index of the list to a new value.

NULL is accepted as a possible value. If the index is out of the valid indices for the array list, then the list is not modified and NULL is returned. Otherwise, the list element at the specified index is set to a new value, and the old value is returned.

Parameters:
index - the index at which to set the new element
newElement - the new element to set in the list
Returns:
the old list element, or NULL if index is out of bounds

template<typename T>
T ArrayList< T >::removeAtIndex ( int  index  )  [inline]

Remove the element at the specified index.

If the index is within the bounds of the list ( >= 0 && < size() ), then the list element at that index is removed and it's value is returned. Otherwise, NULL is returned and the list is unaffected. The order of the list is unaffected.

Parameters:
index - the index of the list element to remove
Returns:
the removed element of the list, or NULL if out of bounds

template<typename T>
T ArrayList< T >::removeAtIndexUnordered ( int  index  )  [inline]

Remove the element at the specified index.

If the index is within the bounds of the list ( >= 0 && < size() ), then the list element at that index is removed and it's value is returned. Otherwise, NULL is returned and the list is unaffected. This method does not guarantee that the list stays in order. It replaces the removed element with the last element of the list.

Parameters:
index - the index of the list element to remove
Returns:
the removed element of the list, or NULL if out of bounds

template<typename T>
bool ArrayList< T >::remove ( const T &  anElement  )  [inline]

Remove the first element equal to the parameter element.

If this element is found, then it is removed and TRUE is returned. Otherwise, NULL is returned and the list is unaffected. The order of the list is unaffected by this method.

Parameters:
element - the list element to remove the first instance of
Returns:
whether or not the element was removed

template<typename T>
bool ArrayList< T >::removeUnordered ( const T &  anElement  )  [inline]

Remove the first element equal to the parameter element.

If this element is found, then it is removed and TRUE is returned. Otherwise, NULL is returned and the list is unaffected. This method does not guarantee that the list stays in order. It replaces the removed element with the last element of the list.

Parameters:
element - the list element to remove the first instance of
Returns:
whether or not the element was removed

template<typename T>
T ArrayList< T >::removeLast (  )  [inline]

Remove the last element in the array list.

If the array list has elements remaining in it, then the last element in the array list is removed and returned. If the array list has no remaining elements, then a rimNoSuchElementException is thrown.

Returns:
the removed element of the list

template<typename T>
bool ArrayList< T >::contains ( const T &  anElement  )  const [inline]

template<typename T>
void ArrayList< T >::clear (  )  [inline]

template<typename T>
bool ArrayList< T >::isEmpty (  )  const [inline]

Return whether or not the array list has any elements.

Returns:
whether or not the array list has any elements

template<typename T>
int ArrayList< T >::getSize (  )  const [inline]

Get the number of elements in the array list.

Returns:
the number of elements in the array list

template<typename T>
const T& ArrayList< T >::get ( int  index  )  const [inline]

Return the element at the specified index.

If index is outside of the bounds of the list, then NULL is returned. Otherwise, the function returns the element at the specified index and leaves the list unaltered.

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
T& ArrayList< T >::get ( int  index  )  [inline]

Return the element at the specified index.

If index is outside of the bounds of the list, then NULL is returned. Otherwise, the function returns the element at the specified index and leaves the list unaltered. Non-const version which allows element modification.

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
int ArrayList< T >::getIndex ( const T &  element  )  const [inline]

Return the index of the specified element.

If the specified element is not found within the list, then -1 is returned. Otherwise, the index of the specified element is returned.

Parameters:
element - the element to find in the array
Returns:
the index of the specified element

template<typename T>
T ArrayList< T >::getSimilar ( const T &  element,
bool(*)(const T &, const T &)  areSimilar 
) const [inline]

Return an element of the list similar to the parameter.

This function takes as arguments a possible element of the list and a function pointer to a comparison function. It searches sequentially through the list until the comparison function returns true. It then returns this element of the array list. This should be used especially to overload the comparison operator for pointers to types, since the comparison operator is not overridable. If the function is unable to find a similar element in the list, then a rimNoSuchElementException is thrown.

Parameters:
element - the element to find in the array
areSimilar - a pointer to a comparison function
Returns:
the first similar element in the array list

template<typename T>
int ArrayList< T >::getSimilarIndex ( const T &  element,
bool(*)(T, T)  areSimilar 
) const [inline]

Return an the index of an element of the list similar to the parameter.

This function takes as arguments a possible element of the list and a function pointer to a comparison function. It searches sequentially through the list until the comparison function returns true. It then returns the index of this element in the array list. This should be used especially to overload the comparison operator for pointers to types, since the comparison operator is not overridable.

Parameters:
element - the element to find in the array
areSimilar - a pointer to a comparison function
Returns:
the index of the first similar element in the array list

template<typename T>
const T& ArrayList< T >::operator() ( int  index  )  const [inline]

Return the element at the specified index.

If index is outside of the bounds of the list, then a rimIndexOutOfBoundsException is thrown. Otherwise, the function returns the element at the specified index and leaves the list unaltered.

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
T& ArrayList< T >::operator() ( int  index  )  [inline]

Return the element at the specified index.

If index is outside of the bounds of the list, then a rimIndexOutOfBoundsException is thrown. Otherwise, the function returns the element at the specified index. This is the non-const version.

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
const T& ArrayList< T >::operator[] ( int  index  )  const [inline]

Return the element at the specified index.

This operator is does not check whether or not the supplied index is within the bounds of the list, so use this operator at your own risk!

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
T& ArrayList< T >::operator[] ( int  index  )  [inline]

Return the element at the specified index.

This operator is does not check whether or not the supplied index is within the bounds of the list, so use this operator at your own risk! This is the non-const version.

Parameters:
index - the index of the desired element
Returns:
the element at the index specified by the parameter

template<typename T>
Iterator ArrayList< T >::getIterator (  )  [inline]

Return a new iterator for the array list.

Returns:
an iterator for the array list

template<typename T>
void ArrayList< T >::resize (  )  [inline, private]

double the size of the element array to increase the capacity of the list

template<typename T>
void ArrayList< T >::intializeArray (  )  [inline, private]

initialize the size of the element array to the specified size

template<typename T>
bool ArrayList< T >::checkBounds ( int  index  )  const [inline, private]

return whether or not the specified index is within the bounds of the list


Member Data Documentation

template<typename T>
T* ArrayList< T >::array [private]

The array for the array list containing all elements.

template<typename T>
int ArrayList< T >::numElements [private]

The number of elements in the array list.

template<typename T>
int ArrayList< T >::capacity [private]

The size of the array in this array list.

template<typename T>
const int ArrayList< T >::DEFAULT_INITIAL_CAPACITY = 8 [static, private]

The default initial capacity of an array list.


The documentation for this class was generated from the following file:
Generated on Tue Aug 26 00:03:17 2008 for Rim Physics by  doxygen 1.5.4