MAUtil::Vector< Type > Class Template Reference

#include <MAUtil/Vector.h>

List of all members.


Detailed Description

template<typename Type>
class MAUtil::Vector< Type >

A generic, dynamic, random-access container.

Performance characteristics are as follows:

Access to any element by index is very fast (constant time).

add(), insert() and remove() at the end of the vector are fast (constant time amortized over linear time).

insert() and remove() anywhere else are slow, (linear time).

Note:
All operations that modify the vector invalidates all iterators and references to its elements. Never keep references, iterators or pointers to elements. Indices may sometimes be used instead, but even indices are invalidated by insert() and remove(), as well as shrinking resize().


Public Types

typedef Type * iterator
 Defines a typesafe iterator for the template instance.
typedef const Type * const_iterator

Public Member Functions

 Vector (int initialCapacity=4)
 Constructs the Vector and sets its capacity to initialCapacity.
 ~Vector ()
 Destructor.
Vectoroperator= (const Vector &other)
void add (const Type &val)
 Adds an element to the end of the Vector.
void add (const Type *ptr, int num)
 Adds several elements to the end of the Vector.
void remove (iterator i)
 Removes the element pointed to by iterator i.
void remove (int index)
 Removes the element at index.
void insert (int index, Type t)
 Inserts the element at index, moving all existing elements beginning at 'index' one step forward.
int size () const
 Returns the number of elements.
void resize (int newSize)
 Resizes the Vector to contain size elements.
void reserve (int newCapacity)
 Reserves space in the Vector.
void clear ()
 Clears the Vector, setting its size to 0 but not altering its capacity.
bool empty () const
 Returns true iff the Vector is empty().
int capacity () const
 Returns the Vector's current capacity.
iterator begin ()
 Returns an iterator pointing to the first element of the Vector.
iterator end ()
 Returns an iterator pointing beyond the last element of the Vector.
const_iterator begin () const
 Returns an iterator pointing to the first element of the Vector.
const_iterator end () const
 Returns an iterator pointing beyond the last element of the Vector.
Type & operator[] (int index)
 Returns a reference to the element at index. No range-checking is done.
const Type & operator[] (int index) const
 Returns a const reference to the element at index. No range-checking is done.
const Type * pointer () const
 Returns a const pointer to the Vector's storage array.
Type * pointer ()
 Returns a pointer to the Vector's storage array.

Protected Attributes

int mSize
int mCapacity
Type * mData


Member Typedef Documentation

template<typename Type>
typedef Type* MAUtil::Vector< Type >::iterator
 

Defines a typesafe iterator for the template instance.

template<typename Type>
typedef const Type* MAUtil::Vector< Type >::const_iterator
 


Constructor & Destructor Documentation

template<typename Type>
MAUtil::Vector< Type >::Vector int  initialCapacity = 4  )  [inline]
 

Constructs the Vector and sets its capacity to initialCapacity.

Parameters:
initialCapacity The initial capacity of the Vector.

template<typename Type>
MAUtil::Vector< Type >::~Vector  )  [inline]
 

Destructor.


Member Function Documentation

template<typename Type>
Vector& MAUtil::Vector< Type >::operator= const Vector< Type > &  other  )  [inline]
 

Copies the other vector.

Returns:
A reference to this vector.

template<typename Type>
void MAUtil::Vector< Type >::add const Type &  val  )  [inline]
 

Adds an element to the end of the Vector.

Parameters:
val The element to be added.

template<typename Type>
void MAUtil::Vector< Type >::add const Type *  ptr,
int  num
[inline]
 

Adds several elements to the end of the Vector.

Parameters:
ptr A pointer to the elements.
num The number of elements.

template<typename Type>
void MAUtil::Vector< Type >::remove iterator  i  )  [inline]
 

Removes the element pointed to by iterator i.

Parameters:
i An iterator pointing to the element that should be removed.

template<typename Type>
void MAUtil::Vector< Type >::remove int  index  )  [inline]
 

Removes the element at index.

Parameters:
index The index of the element that should be removed.

template<typename Type>
void MAUtil::Vector< Type >::insert int  index,
Type  t
[inline]
 

Inserts the element at index, moving all existing elements beginning at 'index' one step forward.

Parameters:
index The index of the newly inserted element.
t The element itself.

template<typename Type>
int MAUtil::Vector< Type >::size  )  const [inline]
 

Returns the number of elements.

Returns:
Returns the number of elements currently in the Vector.
See also:
capacity

template<typename Type>
void MAUtil::Vector< Type >::resize int  newSize  )  [inline]
 

Resizes the Vector to contain size elements.

Parameters:
newSize The desired size of the Vector.

template<typename Type>
void MAUtil::Vector< Type >::reserve int  newCapacity  )  [inline]
 

Reserves space in the Vector.

Parameters:
newCapacity The desired capacity of the Vector.
Note:
If newCapacity is less than the current capacity of the Vector, nothing will happen.

template<typename Type>
void MAUtil::Vector< Type >::clear  )  [inline]
 

Clears the Vector, setting its size to 0 but not altering its capacity.

template<typename Type>
bool MAUtil::Vector< Type >::empty  )  const [inline]
 

Returns true iff the Vector is empty().

template<typename Type>
int MAUtil::Vector< Type >::capacity  )  const [inline]
 

Returns the Vector's current capacity.

See also:
size

template<typename Type>
iterator MAUtil::Vector< Type >::begin  )  [inline]
 

Returns an iterator pointing to the first element of the Vector.

template<typename Type>
iterator MAUtil::Vector< Type >::end  )  [inline]
 

Returns an iterator pointing beyond the last element of the Vector.

template<typename Type>
const_iterator MAUtil::Vector< Type >::begin  )  const [inline]
 

Returns an iterator pointing to the first element of the Vector.

template<typename Type>
const_iterator MAUtil::Vector< Type >::end  )  const [inline]
 

Returns an iterator pointing beyond the last element of the Vector.

template<typename Type>
Type& MAUtil::Vector< Type >::operator[] int  index  )  [inline]
 

Returns a reference to the element at index. No range-checking is done.

Parameters:
index The index of the element to be returned.

template<typename Type>
const Type& MAUtil::Vector< Type >::operator[] int  index  )  const [inline]
 

Returns a const reference to the element at index. No range-checking is done.

Parameters:
index The index of the element to be returned.

template<typename Type>
const Type* MAUtil::Vector< Type >::pointer  )  const [inline]
 

Returns a const pointer to the Vector's storage array.

Note:
The pointer becomes invalid when the Vector is changed.

template<typename Type>
Type* MAUtil::Vector< Type >::pointer  )  [inline]
 

Returns a pointer to the Vector's storage array.

Note:
The pointer becomes invalid when the Vector is changed.


Member Data Documentation

template<typename Type>
int MAUtil::Vector< Type >::mSize [protected]
 

template<typename Type>
int MAUtil::Vector< Type >::mCapacity [protected]
 

template<typename Type>
Type* MAUtil::Vector< Type >::mData [protected]
 


Generated on Sat Feb 13 00:15:40 2010 for MoSync 2 beta 1 by  doxygen 1.4.6-NO