Created by the British Broadcasting Corporation.
A template class for two-dimensional arrays. More...
#include <arrays.h>
Public Member Functions | |
TwoDArray () | |
Default constructor. | |
TwoDArray (const int height, const int width) | |
Constructor. | |
TwoDArray (const int height, const int width, T val) | |
Constructor. | |
virtual | ~TwoDArray () |
Destructor. | |
TwoDArray (const TwoDArray< T > &Cpy) | |
Copy constructor. | |
TwoDArray< T > & | operator= (const TwoDArray< T > &rhs) |
Assignment =. | |
bool | CopyContents (TwoDArray< T > &out) const |
Copy Contents. | |
void | Fill (T val) |
Fill contents. | |
void | Resize (const int height, const int width) |
Resizes the array, deleting the current data. | |
element_type & | operator[] (const int pos) |
Element access. | |
const element_type & | operator[] (const int pos) const |
Element access. | |
int | LengthX () const |
Returns the width. | |
int | LengthY () const |
Returns the height. | |
int | FirstX () const |
Returns the index of the first element of a row. | |
int | FirstY () const |
Returns the index of the first element of a column. | |
int | LastX () const |
Returns the index of the last element of a row. | |
int | LastY () const |
Returns the index of the first element of a column. |
Private Types | |
typedef T * | element_type |
Private Member Functions | |
void | Init (const int height, const int width) |
Initialise the array. | |
void | FreeData () |
Free all the allocated data. |
Private Attributes | |
int | m_first_x |
int | m_first_y |
int | m_last_x |
int | m_last_y |
int | m_length_x |
int | m_length_y |
element_type * | m_array_of_rows |
A template class to do two-d arrays, so that explicit memory (de-)allocation is not required. Only zero-based arrays are currently supported so that access is fast. Accessing elements along a row is therefore much faster than accessing them along a column. Rows are contiguous in memory, so array[y][x] is equivalent to array[0][x+y*LengthX()].
|
private |
|
inline |
Default constructor creates an empty array.
Referenced by CopyContents(), operator=(), and TwoDArray().
|
inline |
The constructor creates an array of given width height.
dirac::TwoDArray< T >::TwoDArray | ( | const int | height, |
const int | width, | ||
T | val ) |
The constructor creates an array of given width and length height and initialises it to a value
References Init(), m_array_of_rows, m_length_x, and m_length_y.
|
inlinevirtual |
Destructor frees the data allocated in the constructor.
dirac::TwoDArray< T >::TwoDArray | ( | const TwoDArray< T > & | Cpy | ) |
Copy constructor copies data and metadata.
References Init(), m_array_of_rows, m_first_x, m_first_y, m_last_x, m_last_y, m_length_x, m_length_y, and TwoDArray().
bool dirac::TwoDArray< T >::CopyContents | ( | TwoDArray< T > & | out | ) | const |
Copy contents of array into output array retaining the dimensions of the output array. If output array is larger that array then pad with last true value. Return true is copy was successful
References m_array_of_rows, m_length_x, m_length_y, and TwoDArray().
void dirac::TwoDArray< T >::Fill | ( | T | val | ) |
Initialise the array with the val provided.
References m_array_of_rows, m_length_x, and m_length_y.
|
inline |
|
inline |
|
private |
References m_array_of_rows, m_length_x, and m_length_y.
Referenced by operator=(), Resize(), and dirac::TwoDArray< MVector >::~TwoDArray().
|
private |
References m_array_of_rows, m_first_x, m_first_y, m_last_x, m_last_y, m_length_x, and m_length_y.
Referenced by operator=(), Resize(), TwoDArray(), TwoDArray(), dirac::TwoDArray< MVector >::TwoDArray(), and dirac::TwoDArray< MVector >::TwoDArray().
|
inline |
|
inline |
|
inline |
|
inline |
TwoDArray< T > & dirac::TwoDArray< T >::operator= | ( | const TwoDArray< T > & | rhs | ) |
Assignement = assigns both data and metadata.
References FreeData(), Init(), m_array_of_rows, m_first_x, m_first_y, m_last_x, m_last_y, m_length_x, m_length_y, and TwoDArray().
|
inline |
Accesses the rows of the arrays, which are returned in the form of pointers to the row data NOT OneDArray objects.
|
inline |
Accesses the rows of the arrays, which are returned in the form of pointers to the row data NOT OneDArray objects.
void dirac::TwoDArray< T >::Resize | ( | const int | height, |
const int | width ) |
References FreeData(), Init(), m_length_x, and m_length_y.
|
private |
Referenced by CopyContents(), Fill(), FreeData(), Init(), operator=(), TwoDArray(), and TwoDArray().
|
private |
Referenced by Init(), operator=(), and TwoDArray().
|
private |
Referenced by Init(), operator=(), and TwoDArray().
|
private |
Referenced by Init(), operator=(), and TwoDArray().
|
private |
Referenced by Init(), operator=(), and TwoDArray().
|
private |
Referenced by CopyContents(), Fill(), FreeData(), Init(), operator=(), Resize(), TwoDArray(), and TwoDArray().
|
private |
Referenced by CopyContents(), Fill(), FreeData(), Init(), operator=(), Resize(), TwoDArray(), and TwoDArray().
© 2004 British Broadcasting Corporation.
Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's
excellent Doxygen tool.