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

An array-based list class with a static element capacity. More...

#include <omStaticArrayList.h>

Classes

class  ConstIterator
 An iterator class for a static array list which can't modify it. More...
 
class  Iterator
 Iterator class for an static array list. More...
 

Public Member Functions

 StaticArrayList ()
 Create a new empty static array list. More...
 
 StaticArrayList (const T *elements, SizeType newNumElements)
 Create a new static array list with its internal array initialized with element from an external array. More...
 
 StaticArrayList (const StaticArrayList &other)
 Create a copy of another static array list, performing a deep copy. More...
 
 ~StaticArrayList ()
 Destroy this static array list, releasing all internal state. More...
 
StaticArrayListoperator= (const StaticArrayList &other)
 Assign the contents from another static array list to this one. More...
 
Bool operator== (const StaticArrayList &other) const
 Return whether or not whether every entry in this list is equal to another list's entries. More...
 
Bool operator!= (const StaticArrayList &other) const
 Return whether or not whether any entry in this list is not equal to another list's entries. More...
 
Bool add (const T &newElement)
 Add an element to the end of the static list. More...
 
Bool addNew ()
 Construct a new element at the end of the list. More...
 
template<typename P1 >
Bool addNew (const P1 &p1)
 Construct a new element at the end of the list. More...
 
template<typename P1 , typename P2 >
Bool addNew (const P1 &p1, const P2 &p2)
 Construct a new element at the end of the list. More...
 
template<typename P1 , typename P2 , typename P3 >
Bool addNew (const P1 &p1, const P2 &p2, const P3 &p3)
 Construct a new element at the end of the list. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 >
Bool addNew (const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4)
 Construct a new element at the end of the list. More...
 
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
Bool addNew (const P1 &p1, const P2 &p2, const P3 &p3, const P4 &p4, const P5 &p5)
 Construct a new element at the end of the list. More...
 
template<Size otherCapacity>
Bool addAll (const StaticArrayList< T, otherCapacity, SizeType > &list)
 Add the contents of one static array list to another. More...
 
Bool insert (SizeType index, const T &newElement)
 Insert an element at the specified index of the static array list. More...
 
Bool set (SizeType index, const T &newElement)
 Set an element at the specified index of the static array list to a new value. More...
 
Bool removeAtIndex (SizeType index)
 Remove the element at the specified index, ordered version. More...
 
Bool removeAtIndexUnordered (SizeType index)
 Remove the element at the specified index, unordered version. More...
 
Bool remove (const T &object)
 Remove the first element equal to the parameter object, ordered version. More...
 
Bool removeUnordered (const T &object)
 Remove the first element equal to the parameter object, unordered version. More...
 
Bool removeLast ()
 Remove the last element in the static array list. More...
 
SizeType removeLast (SizeType number)
 Remove the last N elements from the static array list. More...
 
void clear ()
 Clear the contents of this static array list. More...
 
Bool contains (const T &object) const
 Return whether or not the specified object is in this static array list. More...
 
Bool getIndex (const T &object, SizeType &index) const
 Return the index of the array element equal to the parameter element. More...
 
const T & get (SizeType index) const
 Return the element at the specified index. More...
 
T & get (SizeType index)
 Return the element at the specified index. More...
 
T & getFirst ()
 Return a reference to the first element in the static array list. More...
 
const T & getFirst () const
 Return a const reference to the first element in the static array list. More...
 
T & getLast ()
 Return a reference to the last element in the static array list. More...
 
const T & getLast () const
 Return a const reference to the last element in the static array list. More...
 
const T & operator() (SizeType index) const
 Return the element at the specified index. More...
 
T & operator() (SizeType index)
 Return the element at the specified index. More...
 
 operator const T * () const
 Get a const pointer to the first element in the static array list. More...
 
 operator T * ()
 Get a pointer to the first element in the static array list. More...
 
const T * getPointer () const
 Return a const pointer to the beginning of the internal array. More...
 
T * getPointer ()
 Return a pointer to the beginning of the internal array. More...
 
Bool isEmpty () const
 Return whether or not the static array list has any elements. More...
 
SizeType getSize () const
 Get the number of elements in the static array list. More...
 
SizeType getCapacity () const
 Get the capacity of the static array list. More...
 
Iterator getIterator ()
 Return an iterator for the static array list. More...
 
ConstIterator getIterator () const
 Return a const iterator for the static array list. More...
 

Detailed Description

template<typename T, Size capacity, typename SizeType = Size>
class om::util::StaticArrayList< T, capacity, SizeType >

An array-based list class with a static element capacity.

The StaticArrayList class allows basic list operations: add(), remove(), insert(), clear() and getSize(). Once the static capacity of the list is reached, no more elements can be added to the list.

Constructor & Destructor Documentation

template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::StaticArrayList ( )
inline

Create a new empty static array list.

template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::StaticArrayList ( const T *  elements,
SizeType  newNumElements 
)
inline

Create a new static array list with its internal array initialized with element from an external array.

The initial size of the static array list is set to the number of elements that are to be copied from the given array. If the number of elements to be copied is larger than the static capacity of the list, the maximum possible number of elements are copied.

Parameters
elements- an array of contiguous element objects from which to initialize this static array list.
newNumElements- the number of elements to copy from the element array.
template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::StaticArrayList ( const StaticArrayList< T, capacity, SizeType > &  other)
inline

Create a copy of another static array list, performing a deep copy.

template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::~StaticArrayList ( )
inline

Destroy this static array list, releasing all internal state.

Member Function Documentation

template<typename T, Size capacity, typename SizeType = Size>
StaticArrayList& om::util::StaticArrayList< T, capacity, SizeType >::operator= ( const StaticArrayList< T, capacity, SizeType > &  other)
inline

Assign the contents from another static array list to this one.

template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::operator== ( const StaticArrayList< T, capacity, SizeType > &  other) const
inline

Return whether or not whether every entry in this list is equal to another list's entries.

template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::operator!= ( const StaticArrayList< T, capacity, SizeType > &  other) const
inline

Return whether or not whether any entry in this list is not equal to another list's entries.

template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::add ( const T &  newElement)
inline

Add an element to the end of the static list.

If the capacity of the static array list is not great enough to hold the new element, then FALSE is returned and the static array list is unaffected. Otherwise, the element is successfully added and TRUE is returned.

Parameters
newElement- the new element to add to the end of the static array list.
Returns
whether or not the element was successfully added.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( )
inline

Construct a new element at the end of the list.

If the capacity of the array list is not great enough to hold the new element, then the internal array is reallocated to be double the size and all elements are copied to the new array.

template<typename T, Size capacity, typename SizeType = Size>
template<typename P1 >
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( const P1 &  p1)
inline

Construct a new element at the end of the list.

template<typename T, Size capacity, typename SizeType = Size>
template<typename P1 , typename P2 >
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( const P1 &  p1,
const P2 &  p2 
)
inline

Construct a new element at the end of the list.

template<typename T, Size capacity, typename SizeType = Size>
template<typename P1 , typename P2 , typename P3 >
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3 
)
inline

Construct a new element at the end of the list.

template<typename T, Size capacity, typename SizeType = Size>
template<typename P1 , typename P2 , typename P3 , typename P4 >
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3,
const P4 &  p4 
)
inline

Construct a new element at the end of the list.

template<typename T, Size capacity, typename SizeType = Size>
template<typename P1 , typename P2 , typename P3 , typename P4 , typename P5 >
Bool om::util::StaticArrayList< T, capacity, SizeType >::addNew ( const P1 &  p1,
const P2 &  p2,
const P3 &  p3,
const P4 &  p4,
const P5 &  p5 
)
inline

Construct a new element at the end of the list.

template<typename T, Size capacity, typename SizeType = Size>
template<Size otherCapacity>
Bool om::util::StaticArrayList< T, capacity, SizeType >::addAll ( const StaticArrayList< T, otherCapacity, SizeType > &  list)
inline

Add the contents of one static array list to another.

This method has the effect of adding each element of the given list to the end of this array list in order.

Parameters
list- the list to be added to the end of this list
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::insert ( SizeType  index,
const T &  newElement 
)
inline

Insert an element at the specified index of the static array list.

The method returns TRUE if the element was successfully inserted into the static array list. If the index is outside of the bounds of the static array list, then FALSE is returned, indicating that the element was not inserted. FALSE will also be returned if there is no more room in the static array list. This method has an average case time complexity of O(n/2) because all subsequent elements in the static array list have to be moved towards the end of the array by one index.

Parameters
newElement- the new element to insert into the static array list.
index- the index at which to insert the new element.
Returns
whether or not the element was successfully inserted into the static array list.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::set ( SizeType  index,
const T &  newElement 
)
inline

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

This method returns TRUE if the specified index is within the bounds of the static array list, indicating that the element was successfully set at that position in the static array list. Otherwise, FALSE is returned, indicating that the index was out of bounds of the static array list. This method has worst-case time complexity of O(1).

Parameters
newElement- the new element to set in the static array list.
index- the index at which to set the new element.
Returns
whether or not the element was successfully set to the new value.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::removeAtIndex ( SizeType  index)
inline

Remove the element at the specified index, ordered version.

If the index is within the bounds of the static array list ( >= 0 && < getSize() ), then the static array list element at that index is removed and TRUE is returned, indicating that the remove operation was successful. Otherwise, FALSE is returned and the static array list is unaffected. The order of the static array list is unaffected, meaning that all of the elements after the removed element must be copied one index towards the beginning of the static array list. This gives the method an average case performance of O(n/2) where n is the number of elements in the static array list.

Parameters
index- the index of the static array list element to remove.
Returns
whether or not the element was successfully removed.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::removeAtIndexUnordered ( SizeType  index)
inline

Remove the element at the specified index, unordered version.

If the index is within the bounds of the static array list ( >= 0 && < getSize() ), then the static array list element at that index is removed and TRUE is returned, indicating that the remove operation was successful. Otherwise, FALSE is returned and the static array list is unaffected. The order of the static array list is affected when this method successfully removes the element. It works by replacing the element at the index to be removed with the last element in the static array list. This gives the method a worst case time complexity of O(1), that is much faster than the ordered remove methods.

Parameters
index- the index of the static array list element to remove.
Returns
whether or not the element was successfully removed.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::remove ( const T &  object)
inline

Remove the first element equal to the parameter object, ordered version.

If this element is found, then it is removed and TRUE is returned. Otherwise, FALSE is returned and the static array list is unaffected. The order of the static array list is unaffected, meaning that all of the elements after the removed element must be copied one index towards the beginning of the static array list. This gives the method an average case performance of O(n) where n is the number of elements in the static array list. This method's complexity is worse than the ordered index remove method because it must search through the static array list for the element and then copy all subsequent elements one position nearer to the start of the list.

Parameters
object- the element to remove the first instance of.
Returns
whether or not the element was successfully removed.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::removeUnordered ( const T &  object)
inline

Remove the first element equal to the parameter object, unordered version.

If this element is found, then it is removed and TRUE is returned. Otherwise, FALSE is returned and the static array list is unaffected. The order of the static array list is affected when this method successfully removes the element. It works by replacing the element at the index to be removed with the last element in the static array list. This gives the method a worst case time complexity of O(1), that is much faster than the ordered remove methods.

Parameters
object- the static array list element to remove the first instance of.
Returns
whether or not the element was successfully removed.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::removeLast ( )
inline

Remove the last element in the static array list.

If the static array list has elements remaining in it, then the last element in the array list is removed and TRUE is returned. If the static array list has no remaining elements, then FALSE is returned, indicating that the static array list was unaffected. This method has worst case O(1) time complexity.

Returns
whether or not the last element was successfully removed.
template<typename T, Size capacity, typename SizeType = Size>
SizeType om::util::StaticArrayList< T, capacity, SizeType >::removeLast ( SizeType  number)
inline

Remove the last N elements from the static array list.

If the static array list has at least N elements remaining in it, then the last N elements in the array list are removed and N is returned. If the array list has less than N elements, then the list will be completely cleared, resulting in an empty list. The method returns the number of elements successfully removed.

Returns
the number of elements removed from the end of the list.
template<typename T, Size capacity, typename SizeType = Size>
void om::util::StaticArrayList< T, capacity, SizeType >::clear ( )
inline

Clear the contents of this static array list.

This method calls the destructors of all elements in the static array and sets the number of elements to zero while maintaining the array's capacity.

template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::contains ( const T &  object) const
inline

Return whether or not the specified object is in this static array list.

The method has average case O(n/2) time complexity, where n is the number of elements in the static array list. This method is here for convenience. It just calls the static array list's getIndex() method, and tests to see if the return value is not equal to -1. It is recommended that if one wants the index of the element as well as whether or not it is contained in the static array list, they should use the getIndex() method exclusively, and check the return value to make sure that the element is in the static array list. This avoids the double O(n/2) lookup that would be performed one naively called this method and then that method.

Parameters
object- the element to check to see if it is contained in the static array list.
Returns
whether or not the specified element is in the static array list.
template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::getIndex ( const T &  object,
SizeType &  index 
) const
inline

Return the index of the array element equal to the parameter element.

If the specified element is not found within the static array list, then -1 is returned. Otherwise, the index of the element equal to the parameter is returned.

Parameters
object- the element to find in the static array list.
index- a reference to where the index of the found object is returned.
Returns
whether or not the object was found in the list.
template<typename T, Size capacity, typename SizeType = Size>
const T& om::util::StaticArrayList< T, capacity, SizeType >::get ( SizeType  index) const
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the static 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, Size capacity, typename SizeType = Size>
T& om::util::StaticArrayList< T, capacity, SizeType >::get ( SizeType  index)
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the static array 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 via the returned non-const reference.

Parameters
index- the index of the desired element.
Returns
a reference to the element at the index specified by the parameter.
template<typename T, Size capacity, typename SizeType = Size>
T& om::util::StaticArrayList< T, capacity, SizeType >::getFirst ( )
inline

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

template<typename T, Size capacity, typename SizeType = Size>
const T& om::util::StaticArrayList< T, capacity, SizeType >::getFirst ( ) const
inline

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

template<typename T, Size capacity, typename SizeType = Size>
T& om::util::StaticArrayList< T, capacity, SizeType >::getLast ( )
inline

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

template<typename T, Size capacity, typename SizeType = Size>
const T& om::util::StaticArrayList< T, capacity, SizeType >::getLast ( ) const
inline

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

template<typename T, Size capacity, typename SizeType = Size>
const T& om::util::StaticArrayList< T, capacity, SizeType >::operator() ( SizeType  index) const
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the static array 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, Size capacity, typename SizeType = Size>
T& om::util::StaticArrayList< T, capacity, SizeType >::operator() ( SizeType  index)
inline

Return the element at the specified index.

If the specified index is not within the valid bounds of the static array list, then an exception is thrown indicating an index out of bounds error occurred. This is the non-const version of the operator (), allowing modification of the element via the returned non-const reference.

Parameters
index- the index of the desired element.
Returns
a reference to the element at the index specified by the parameter.
template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::operator const T * ( ) const
inline

Get a const pointer to the first element in the static array list.

template<typename T, Size capacity, typename SizeType = Size>
om::util::StaticArrayList< T, capacity, SizeType >::operator T * ( )
inline

Get a pointer to the first element in the static array list.

template<typename T, Size capacity, typename SizeType = Size>
const T* om::util::StaticArrayList< T, capacity, SizeType >::getPointer ( ) const
inline

Return a const pointer to the beginning of the internal array.

template<typename T, Size capacity, typename SizeType = Size>
T* om::util::StaticArrayList< T, capacity, SizeType >::getPointer ( )
inline

Return a pointer to the beginning of the internal array.

template<typename T, Size capacity, typename SizeType = Size>
Bool om::util::StaticArrayList< T, capacity, SizeType >::isEmpty ( ) const
inline

Return whether or not the static array list has any elements.

This method returns TRUE if the size of the static array list is greater than zero, and FALSE otherwise. This method is here for convenience.

Returns
whether or not the static array list has any elements.
template<typename T, Size capacity, typename SizeType = Size>
SizeType om::util::StaticArrayList< T, capacity, SizeType >::getSize ( ) const
inline

Get the number of elements in the static array list.

Returns
the number of elements in the static array list.
template<typename T, Size capacity, typename SizeType = Size>
SizeType om::util::StaticArrayList< T, capacity, SizeType >::getCapacity ( ) const
inline

Get the capacity of the static array list.

The capacity is the maximum number of elements that the static array list can hold. This value does not change during the lifetime of the static array list, hence the name.

Returns
the current capacity of the static array list.
template<typename T, Size capacity, typename SizeType = Size>
Iterator om::util::StaticArrayList< T, capacity, SizeType >::getIterator ( )
inline

Return an iterator for the static array list.

The iterator serves to provide a way to efficiently iterate over the elements of the static array list. It is more useful for a linked list type of data structure, but it is provided for uniformity among data structures.

Returns
an iterator for the static array list.
template<typename T, Size capacity, typename SizeType = Size>
ConstIterator om::util::StaticArrayList< T, capacity, SizeType >::getIterator ( ) const
inline

Return a const iterator for the static array list.

The iterator serves to provide a way to efficiently iterate over the elements of the static array list. It is more useful for a linked list type of data structure, but it is provided for uniformity among data structures.

Returns
an iterator for the static array list.

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