Array< T > Class Template Reference

Template data structure of type array. More...

#include <Array.hpp>

Inheritance diagram for Array< T >:

Inheritance graph
[legend]
List of all members.

Public Member Functions

long Length () const
 Returns the current length of the array.
T * Entries ()
 Returns the pointer to the raw array used to store the elements.
void Release ()
 Releases the allocated memory.
void Reset (long new_length, T *mem=NULL)
 Sets a new length.
void ReSize (long new_length)
 Resizes the array but copies its first elements.
const T & operator[] (long i) const
 The const indexation.
T & operator[] (long i)
 The indexation.
Array< T > & operator= (const Array< T > &src)
 Standard assignment.
Array< T > & operator= (const T &value)
 Sets constant values to all the elements.
bool operator== (const Array< T > &array)
 Compares two arrays.
void SetZero ()
 Sets all the elements to zero.
Min () const
 Find the minimum element.
Max () const
 Find the maximum element.
 Array ()
 Creates a zero length array (allocates no memory).
 Array (long the_length, T *mem=NULL)
 Creates array of a given length.
 Array (const Array< T > &array)
 Duplicates an existing object.
 ~Array ()
 Destructor: Releases the memory if it was allocated.

Protected Attributes

T * elements
long length
bool alloced

Detailed Description

template<typename T>
class Array< T >

Template data structure of type array.

Array<T> is an variable size array of elements of type <T>. The class Array<T> provides the main indexing tools, assignment operators etc. T may be any type. Depending on what member functions of Array<T> are really used and instantiated, further assumptions may be imposed on T (like the defined operators < and > for Array<T>Min and Array<T>Max etc.).

Note:
Define CHECK_ARRAY_RANGE to switch on the range checking in operator[]. While it helps at debugging it also consumes a lot of computation time.

It is possible to use this class with a separately allocated array of memory. Then alloced is set to zero and the memory is not released by the functions or the destructor. Note however that '=' and 'Resize' would nevertheless allocate a new memory array unless the new size is not equal to the old one.


Constructor & Destructor Documentation

template<typename T>
Array< T >::Array (  )  [inline]

Creates a zero length array (allocates no memory).

template<typename T>
Array< T >::Array ( long  the_length,
T *  mem = NULL 
) [inline]

Creates array of a given length.

Parameters:
[in] the_length The new length.
[in] mem The memory to place the elements (optional).

template<typename T>
Array< T >::Array ( const Array< T > &  array  )  [inline]

Duplicates an existing object.

Parameters:
[in] array The source array.

template<typename T>
Array< T >::~Array (  )  [inline]

Destructor: Releases the memory if it was allocated.


Member Function Documentation

template<typename T>
long Array< T >::Length (  )  const [inline]

Returns the current length of the array.

template<typename T>
T* Array< T >::Entries (  )  [inline]

Returns the pointer to the raw array used to store the elements.

template<typename T>
void Array< T >::Release (  )  [inline]

Releases the allocated memory.

template<typename T>
void Array< T >::Reset ( long  new_length,
T *  mem = NULL 
) [inline]

Sets a new length.

Parameters:
[in] new_length The new length.
[in] mem The memory to place the elements (optional).

template<typename T>
void Array< T >::ReSize ( long  new_length  )  [inline]

Resizes the array but copies its first elements.

Parameters:
[in] new_length The new length.

template<typename T>
const T & Array< T >::operator[] ( long  i  )  const [inline]

The const indexation.

Parameters:
[in] i The index starting from 0.
Note:
If CHECK_ARRAY_RANGE is defined this function checks if the index is less than the length.

template<typename T>
T & Array< T >::operator[] ( long  i  )  [inline]

The indexation.

Parameters:
[in] i The index starting from 0.
Note:
If CHECK_ARRAY_RANGE is defined this function checks if the index is less than the length.

template<typename T>
Array< T > & Array< T >::operator= ( const Array< T > &  src  )  [inline]

Standard assignment.

Duplicates an existing Array<T>.

Parameters:
[in] src the existing array to duplicate
Returns:
Reference to the target object.

template<typename T>
Array<T>& Array< T >::operator= ( const T &  value  )  [inline]

Sets constant values to all the elements.

Parameters:
[in] value The new value for the elements.

template<typename T>
bool Array< T >::operator== ( const Array< T > &  array  )  [inline]

Compares two arrays.

The equality relation for the arrays.

Parameters:
[in] array The other array.
Returns:
true if all elements of both arrays are identical, false otherwise.

template<typename T>
void Array< T >::SetZero (  )  [inline]

Sets all the elements to zero.

template<typename T>
T Array< T >::Min (  )  const [inline]

Find the minimum element.

Returns:
The smallest element of the array.
Note:
Min requires relation < between elements of T.

template<typename T>
T Array< T >::Max (  )  const [inline]

Find the maximum element.

Returns:
The largest element of the array.
Note:
Max requires relation > between elements of T.


Member Data Documentation

template<typename T>
T* Array< T >::elements [protected]

the memory for the elements (or NULL)

template<typename T>
long Array< T >::length [protected]

the length of 'elements' in sizeof(T) units; may be 0

template<typename T>
bool Array< T >::alloced [protected]

true if 'elements' have been allocated using 'new'


The documentation for this class was generated from the following file:
Generated on Fri Sep 21 12:34:05 2007 for SG2 by  doxygen 1.5.2