qaf::Container< T > Class Template Reference

#include <qafContainer.h>

Inheritance diagram for qaf::Container< T >:

qaf::CollisionStruct::Composite List of all members.

Detailed Description

template<typename T>
class qaf::Container< T >

A generic container to store data in a linear arrangement, similar to Java's Vector.

Elements are stored in an internal array; its size is increased automatically to accomodate new elements.

Warning:
The Container class may only work properly if the template's type argument (i.e., the stuff between <angle brackets>) meets the following criteria:
Whether or not these items are necessary will depend on what kind of resources the class stores internally. Failing to provide the methods above may result in compiler errors, access violations or memory leaks.

You can safely use primitive types (char, float, any kind of pointer, etc.) with this class.


Public Member Functions

 Container ()
 Creates an empty container.
 Container (const T *elems, int _count)
 Copies all elements from the array into the container.
 Container (const Container &orig)
 Copy constructor: All the elements will be copied from the other container.
Containeroperator= (const Container &other)
 Assignment operator: Copies all elements from the other container.
void add (const T &elem)
 Appends an element to the end of the container.
void add (int index, const T &elem)
 Inserts an element at position index in the container, "pushing" all elements after it towards the end.
int indexOf (const T &elem) const
 Searches the container for the specified element.
void remove (int index)
 Removes the element at the specified index, shifting all the elements after it towards the beginning.
bool removeFirst (const T &elem)
 Searches the container for the first occurrence of the element, and removes it if it was found.
bool removeAll (const T &elem)
 Searches the container for all occurrences of the element, removing them as they are found.
void removeAll ()
 Removes all elements from the container.
int getCount () const
 
Returns:
The number of elements in this container.

const T & operator[] (int index) const
 Used to access the elements in the container.
T & operator[] (int index)
 Used to access the elements in the container.
const T & elem (int index) const
 An alias for the subscript operator.
T & elem (int index)
 An alias for the subscript operator.
const T & tail () const
 
Returns:
A reference to the last element in this container.

T & tail ()
 
Returns:
A reference to the last element in this container.

const T * getData () const
 Returns a pointer to the container's internal buffer.
void toBeginning (int index)
 Moves an element to the beginning of the container, shifting the necessary elements to higher indices.
void toEnd (int index)
 Moves an element to the end of the container, shifting the necessary elements to lower indices.
void swap (int i, int j)
 Swaps the position of two objects in the container.
virtual ~Container ()
 Destructor: Frees the allocated memory.


Member Function Documentation

template<typename T>
void qaf::Container< T >::add ( const T &  elem  )  [inline]

Appends an element to the end of the container.

The internal array's size will be increased automatically.

template<typename T>
void qaf::Container< T >::add ( int  index,
const T &  elem 
) [inline]

Inserts an element at position index in the container, "pushing" all elements after it towards the end.

A valid index is defined as

0 <= index <= count

Exceptions:
std::out_of_range if the index is not valid.

template<typename T>
int qaf::Container< T >::indexOf ( const T &  elem  )  const [inline]

Searches the container for the specified element.

Returns:
The index of the first occurrence found, or -1 if the element was not found.

template<typename T>
void qaf::Container< T >::remove ( int  index  )  [inline]

Removes the element at the specified index, shifting all the elements after it towards the beginning.

A valid index is defined as

0 <= index < count

Exceptions:
std::out_of_range if an invalid index is supplied.

template<typename T>
bool qaf::Container< T >::removeFirst ( const T &  elem  )  [inline]

Searches the container for the first occurrence of the element, and removes it if it was found.

Returns:
true if the element was found and removed.

template<typename T>
bool qaf::Container< T >::removeAll ( const T &  elem  )  [inline]

Searches the container for all occurrences of the element, removing them as they are found.

Returns:
true if at least one element was found and removed.

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

Used to access the elements in the container.

A valid index is defined as

0 <= index < count

Returns:
A reference to the element at the specified index. It is possible to either set or get the elements with this operator.
Exceptions:
std::out_of_range if an invalid index is supplied.

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

Used to access the elements in the container.

A valid index is defined as

0 <= index < count

Returns:
A reference to the element at the specified index. It is possible to either set or get the elements with this operator.
Exceptions:
std::out_of_range if an invalid index is supplied.

template<typename T>
const T& qaf::Container< T >::elem ( int  index  )  const [inline]

An alias for the subscript operator.

See also:
operator[]()

template<typename T>
T& qaf::Container< T >::elem ( int  index  )  [inline]

An alias for the subscript operator.

See also:
operator[]()

template<typename T>
const T& qaf::Container< T >::tail (  )  const [inline]

Returns:
A reference to the last element in this container.

Exceptions:
std::out_of_range if the container is empty.

template<typename T>
T& qaf::Container< T >::tail (  )  [inline]

Returns:
A reference to the last element in this container.

Exceptions:
std::out_of_range if the container is empty.

template<typename T>
const T* qaf::Container< T >::getData (  )  const [inline]

Returns a pointer to the container's internal buffer.

This pointer must not be deleted or modified in any way -- use other methods for those purposes. This is useful for functions requiring an array as a parameter.

template<typename T>
void qaf::Container< T >::toBeginning ( int  index  )  [inline]

Moves an element to the beginning of the container, shifting the necessary elements to higher indices.

A valid index is defined as

0 <= index < count

Exceptions:
std::out_of_range if an invalid index is supplied.

template<typename T>
void qaf::Container< T >::toEnd ( int  index  )  [inline]

Moves an element to the end of the container, shifting the necessary elements to lower indices.

A valid index is defined as

0 <= index < count

Exceptions:
std::out_of_range if an invalid index is supplied.

template<typename T>
void qaf::Container< T >::swap ( int  i,
int  j 
) [inline]

Swaps the position of two objects in the container.

Exceptions:
std::out_of_range if an invalid index is supplied.


The documentation for this class was generated from the following file:
Generated on Sun Mar 25 12:32:14 2007 for Qaf Framework by  doxygen 1.5.1-p1