MoSync 3.3
MAUtil::Vector< Type > Class Template Reference

A generic, dynamic, random-access container. More...

#include <MAUtil/Vector.h>

List of all members.

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 (const Type *array, int _size)
 Vector (const Vector &other)
 ~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 remove (int index, int number)
 Removes several elements, starting 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

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().

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:
initialCapacityThe initial capacity of the Vector.
template<typename Type>
MAUtil::Vector< Type >::Vector ( const Type *  array,
int  _size 
) [inline]
template<typename Type>
MAUtil::Vector< Type >::Vector ( const Vector< Type > &  other) [inline]

Copies the other 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:
valThe element to be added.

Referenced by MAUtil::ListenerSet< ConnListener >::add(), NativeUI::addListenerToVector(), MAUtil::Stack< T >::push(), and MAUtil::Vector< IMapCacheListener * >::Vector().

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

Adds several elements to the end of the Vector.

Parameters:
ptrA pointer to the elements.
numThe number of elements.
template<typename Type>
void MAUtil::Vector< Type >::remove ( iterator  i) [inline]

Removes the element pointed to by iterator i.

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

Referenced by MAUtil::ListenerSet< ConnListener >::remove(), and NativeUI::removeListenerFromVector().

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

Removes the element at index.

Parameters:
indexThe index of the element that should be removed.
template<typename Type>
void MAUtil::Vector< Type >::remove ( int  index,
int  number 
) [inline]

Removes several elements, starting at index.

Parameters:
indexThe index of the element that should be removed.
numberThe number of elements to remove.
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:
indexThe index of the newly inserted element.
tThe element itself.
template<typename Type>
void MAUtil::Vector< Type >::resize ( int  newSize) [inline]
template<typename Type>
void MAUtil::Vector< Type >::reserve ( int  newCapacity) [inline]

Reserves space in the Vector.

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

Referenced by MAUtil::Vector< IMapCacheListener * >::add(), and MAUtil::Vector< IMapCacheListener * >::resize().

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

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

Referenced by MAUtil::Stack< T >::clear().

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.

Referenced by MAUtil::Vector< IMapCacheListener * >::insert(), and MAUtil::Vector< IMapCacheListener * >::remove().

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

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

Referenced by MAUtil::Vector< IMapCacheListener * >::insert(), and MAUtil::Vector< IMapCacheListener * >::remove().

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:
indexThe 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:
indexThe 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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines