Om  1.0.0
A universal framework for multimedia simulation
Classes | Public Member Functions | List of all members
om::util::LinkedList< T > Class Template Reference

A doubly-linked list class. More...

#include <omLinkedList.h>

Classes

class  ConstIterator
 Iterator class for a linked list which can't modify it. More...
 
class  Iterator
 Iterator class for a linked list. More...
 
class  Node
 The class for a linked list node. More...
 

Public Member Functions

 LinkedList ()
 Create a new empty linked list with no elements. More...
 
 LinkedList (const LinkedList< T > &linkedList)
 Create a deep copy of an existing linked list. More...
 
LinkedList< T > & operator= (const LinkedList< T > &linkedList)
 Assign this linked list with the contents of another, performing a deep copy. More...
 
 ~LinkedList ()
 Destroy a linked list, deallocating all resourced used. More...
 
void add (const T &newElement)
 Add an element to the end of the list. More...
 
Bool insert (Index index, const T &newElement)
 Insert an element at the specified index of the list. More...
 
Bool set (Index index, const T &newElement)
 Set an element at the specified index of the list to a new value. More...
 
Bool removeAtIndex (Index index)
 Remove the element at the specified index from this list. More...
 
Bool remove (T element)
 Remove the first element equal to the parameter element. More...
 
Bool removeLast ()
 Remove the last element in the linked list. More...
 
Bool removeFirst ()
 Remove the first element in the linked list. More...
 
void clear ()
 Remove all elements from the linked list. More...
 
T & get (Index index)
 Return the element at the specified index. More...
 
const T & get (Index index) const
 Return the element at the specified index. More...
 
T & getFirst ()
 Return a reference to the first element in the array list. More...
 
const T & getFirst () const
 Return a const reference to the first element in the array list. More...
 
T & getLast ()
 Return a reference to the last element in the array list. More...
 
const T & getLast () const
 Return a const reference to the last element in the array list. More...
 
T & operator() (Index index)
 Return the element at the specified index. More...
 
const T & operator() (Index index) const
 Return the element at the specified index. More...
 
Bool contains (const T &anElement) const
 Return whether or not the specified element is in this list. More...
 
Bool isEmpty () const
 Return whether or not the linked list has any elements. More...
 
Size getSize () const
 Get the number of elements in the linked list. More...
 
Iterator getIterator ()
 Return an iterator for the linked list. More...
 
ConstIterator getIterator () const
 Return a const iterator for the linked list. More...
 

Detailed Description

template<typename T>
class om::util::LinkedList< T >

A doubly-linked list class.

This class has an interface much like that of the class ArrayList, but it's implementation differs in that this class stores it's array elements non-contiguously in memory, which allows for faster insertion than an array-based list if the Iterator is used. However, the class is mostly useless other than that because an array-based list outperforms it in almost every other comparison. Essentially, it is not recommended that one uses this class unless it's quick insertion time while using the Iterator will be taken advantage of.

Constructor & Destructor Documentation

template<typename T >
om::util::LinkedList< T >::LinkedList ( )
inline

Create a new empty linked list with no elements.

template<typename T >
om::util::LinkedList< T >::LinkedList ( const LinkedList< T > &  linkedList)
inline

Create a deep copy of an existing linked list.

template<typename T >
om::util::LinkedList< T >::~LinkedList ( )
inline

Destroy a linked list, deallocating all resourced used.

Member Function Documentation

template<typename T >
LinkedList<T>& om::util::LinkedList< T >::operator= ( const LinkedList< T > &  linkedList)
inline

Assign this linked list with the contents of another, performing a deep copy.

template<typename T >
void om::util::LinkedList< T >::add ( const T &  newElement)
inline

Add an element to the end of the list.

Parameters
newElement- the new element to add to the end of the list
template<typename T >
Bool om::util::LinkedList< T >::insert ( Index  index,
const T &  newElement 
)
inline

Insert an element at the specified index of the list.

If the index is out of the valid indices for the linked list, the method fails and FALSE is returned. Otherwise TRUE is returned.

Parameters
newElement- the new element to insert in the list
index- the index at which to insert the new element
template<typename T >
Bool om::util::LinkedList< T >::set ( Index  index,
const T &  newElement 
)
inline

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

If the index is out of then valid indices for the linked list, the method fails and FALSE is returned.. Otherwise, the list element at the specified index is set to a new value, and TRUE is returned.

Parameters
index- the index at which to set the new element
newElement- the new element to set in the list
template<typename T >
Bool om::util::LinkedList< T >::removeAtIndex ( Index  index)
inline

Remove the element at the specified index from this list.

If the index is within the bounds of the list, then the list element at that index is removed and the method succeeds, returning TRUE. Otherwise, the method fails and FALSE is returned.

Parameters
index- the index of the list element to remove
Returns
whether or not the element was removed
template<typename T >
Bool om::util::LinkedList< T >::remove ( element)
inline

Remove the first element equal to the parameter element.

If this element is found, then it is removed and TRUE is returned. Otherwise, FALSE is returned and the list is unaffected.

Parameters
element- the list element to remove the first instance of
Returns
whether or not the element was removed
template<typename T >
Bool om::util::LinkedList< T >::removeLast ( )
inline

Remove the last element in the linked list.

If the linked list has elements remaining in it, then the last element in the linked list is removed and TRUE is returned. Otherwise the list is unmodified and FALSE is returned.

Returns
whether or not the remove operation was successful.
template<typename T >
Bool om::util::LinkedList< T >::removeFirst ( )
inline

Remove the first element in the linked list.

If the linked list has elements remaining in it, then the first element in the linked list is removed and TRUE is returned. Otherwise the list is unmodified and FALSE is returned.

Returns
whether or not the remove operation was successful.
template<typename T >
void om::util::LinkedList< T >::clear ( )
inline

Remove all elements from the linked list.

template<typename T >
T& om::util::LinkedList< T >::get ( Index  index)
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the linked list, then an exception is thrown indicating an index out of bounds error occurred. This is the non-const version of the get() method, allowing modification of the element.

Parameters
index- the index of the desired element.
Returns
a const reference to the element at the index specified by the parameter.
template<typename T >
const T& om::util::LinkedList< T >::get ( Index  index) const
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the array list, then an exception is thrown indicating an index out of bounds error occurred. This is the const version of the get() method, disallowing modification of the element.

Parameters
index- the index of the desired element.
Returns
a const reference to the element at the index specified by the parameter.
template<typename T >
T& om::util::LinkedList< T >::getFirst ( )
inline

Return a reference to the first element in the array list.

template<typename T >
const T& om::util::LinkedList< T >::getFirst ( ) const
inline

Return a const reference to the first element in the array list.

template<typename T >
T& om::util::LinkedList< T >::getLast ( )
inline

Return a reference to the last element in the array list.

template<typename T >
const T& om::util::LinkedList< T >::getLast ( ) const
inline

Return a const reference to the last element in the array list.

template<typename T >
T& om::util::LinkedList< T >::operator() ( Index  index)
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the linked list, then an exception is thrown indicating an index out of bounds error occurred. This is the const version of the operator (), disallowing modification of the element.

Parameters
index- the index of the desired element.
Returns
a const reference to the element at the index specified by the parameter.
template<typename T >
const T& om::util::LinkedList< T >::operator() ( Index  index) const
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the linked list, then an exception is thrown indicating an index out of bounds error occurred. This is the const version of the operator (), disallowing modification of the element.

Parameters
index- the index of the desired element.
Returns
a const reference to the element at the index specified by the parameter.
template<typename T >
Bool om::util::LinkedList< T >::contains ( const T &  anElement) const
inline

Return whether or not the specified element is in this list.

template<typename T >
Bool om::util::LinkedList< T >::isEmpty ( ) const
inline

Return whether or not the linked list has any elements.

Returns
whether or not the linked list has any elements
template<typename T >
Size om::util::LinkedList< T >::getSize ( ) const
inline

Get the number of elements in the linked list.

Returns
the number of elements in the linked list
template<typename T >
Iterator om::util::LinkedList< T >::getIterator ( )
inline

Return an iterator for the linked list.

The iterator serves to provide a way to efficiently iterate over the elements of the linked list and to perform modifications to the structure without incurring O(n) overhead for inserting or removing elements.

Returns
an iterator for the linked list.
template<typename T >
ConstIterator om::util::LinkedList< T >::getIterator ( ) const
inline

Return a const iterator for the linked list.

The iterator serves to provide a way to efficiently iterate over the elements of the linked list without incurring O(n) overhead. The returned iterator cannot modify the linked list.

Returns
an iterator for the linked list.

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