Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Array Class Template Reference

Array is a simple growable list container implemented as an array. More...

#include <array.h>

Collaboration diagram for Array:

Collaboration graph
[legend]
List of all members.

Public Methods

 Array ()
unsigned int size ()
void grow ()
void ensure_capacity ()
void append (T element)
operator[] (unsigned int index)
void clear ()

Protected Attributes

T * data
unsigned int used_size
unsigned int capacity

Static Protected Attributes

const unsigned int INITIAL_CAPACITY = 8

Detailed Description

template<class T>
class Array< T >

Array is a simple growable list container implemented as an array.


Constructor & Destructor Documentation

template<class T>
Array< T >::Array   [inline]
 

Initialize a null array of zero elements and zero capacity. grow() should be called before first using the array.


Member Function Documentation

template<class T>
void Array< T >::append   element [inline]
 

Add an element to the end of the array.

template<class T>
void Array< T >::clear   [inline]
 

Clear the array and free its memory.

template<class T>
void Array< T >::ensure_capacity   [inline]
 

Ensure that there's enough capacity for the current used_size.

template<class T>
void Array< T >::grow  
 

Expand the array's total capacity. This would be faster if there was a realloc() implementation.

template<class T>
T Array< T >::operator[] unsigned int    index [inline]
 

Return a particular indexed element. No bounds checking is performed.

template<class T>
unsigned int Array< T >::size   [inline]
 

Return the number of currently used elements.


Member Data Documentation

template<class T>
unsigned int Array::capacity [protected]
 

number of possible elements that can be used before growth is required.

template<class T>
T* Array::data [protected]
 

actual array elements.

template<class T>
const unsigned int Array::INITIAL_CAPACITY = 8 [static, protected]
 

template<class T>
unsigned int Array::used_size [protected]
 

number of elements currently in use.


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

Torsion Operating System, Copyright (C) 2000-2002 Dan Helfman