![]() | ||||||
#include <Array2D.h>
C and C++ 2-dimensional arrays must be dimensioned at compile-time. We need a 2-D array that is allocated dynamically. We could just use double**, but then there are a lot of potential memory leaks, so we've wrapped up the functionality in a small class that gives us nice initialization, constructor/destructor memory management, and the ability to change implementation later.
It is designed to be a simple, lightweight implementation that gives us just the functionality we need, which is basically construction and destruction for memory-management and initialization, plus square-bracket[][] indexing.
Generic code created by Michael and adapted by Andre both on 19/12/02 after phone and e-mail communication. * Thank you Michael :) *
Author : Michael Eldridge and Andre Oboler
Definition at line 77 of file Array2D.h.
Public Member Functions | |
| Array2D (const int p_rows, const int p_columns) | |
| Construct an empty 2D array of size p_rows x p_columns. | |
| Array2D (const int p_rows, const int p_columns, const valarray< double > p_array1D) | |
| Construct an array of size p_rows x p_columns, filled with passed values. | |
| Array2D (const Array2D &p_array2D) | |
| The Array2D copy constructor. | |
| Array2D (const Array2D &p_base, const Array2D &p_extension, const joinType p_joinTo) | |
| The constructor for appending one Array2D to another. | |
| virtual | ~Array2D () |
| Reclaims all memory in the 2D array. | |
| void | print (void) const |
| Prints an Array2D. | |
| double *const & | operator[] (int index) |
| The mutable version of the [] operator. | |
| double *const & | operator[] (int index) const |
| The const version of the [] operator. | |
| double | operator= (int index) |
| const int | getNumColumns () const |
| const int | getNumRows () const |
Private Attributes | |
| double ** | value |
| The values of the matrix. Access as array2D[row][column]. | |
| const int | numRows |
| The number of rows in the matrix. | |
| const int | numColumns |
| The number of columns in the matrix. | |
|
||||||||||||
|
Construct an empty 2D array of size p_rows x p_columns. Constructor takes the dimensions of the matrix and constructs a matrix with all values initialized to 0. Definition at line 69 of file Array2D.cpp. References value. |
|
||||||||||||||||
|
Construct an array of size p_rows x p_columns, filled with passed values. Creates a new array of size row x column, filled with the values in the supplied built-in array array1D. array1D must be of size [rows*columns]. It is converted to the 2D array as: value[i][j] = array1D[i*columns + j] At the moment, it allocates a new double** and then fills it value by value. That may change if we change our underlying implementation to valarrays rather than double**.
Definition at line 98 of file Array2D.cpp. References value. |
|
|
The Array2D copy constructor. Author: ASO Definition at line 207 of file Array2D.cpp. References numColumns, numRows, and value. |
|
||||||||||||||||
|
The constructor for appending one Array2D to another. This constructor makes a new Array2D out of 2 old ones. The second Array2D is appended either below or to the right of the first, depending on the value of p_joinTo. p_joinTo can take values ROW or COLUMN. When ROW, the second array is appended below the first. When COLUMN, the second array is appended to the right of the first. If the arrays do not share an edge of the same size, an exception should be thrown (not yet implemented).
Definition at line 130 of file Array2D.cpp. References getNumColumns(), getNumRows(), and value. |
|
|
Reclaims all memory in the 2D array. This destructor reclaims memory from any allocated pointers. If we switch to valarrays, this will be unnecessary. Definition at line 228 of file Array2D.cpp. |
|
|
The const version of the [] operator. Return the 1D array of all column values for the row provided.
As per the mutable version of this operator, but this version is invoked on const Array2D objects. On such objects you won't be able to do an assignment like Definition at line 282 of file Array2D.cpp. References value. |
|
|
The mutable version of the [] operator. Return the 1D array of all column values for the row provided. This is not meant to be used alone. It is here to provide [][] indexing into the array, by returning a 1D array which provides its own [] operator.
This version is invoked on non-const Array2D objects. On such objects, you can assign directly to the indexed value. Thus If you use this alone to get a 1D slice, be aware that we may change the return type if we change implementations. We only guarantee that the return type will provide its own operator[]. It might be a valarray, a vector, an int[] array.... To avoid copying an entire 1D array every time someone uses [][], the current implementation hands you a reference. Obviously that reference is valid only so long as the Array2D still exists. There's no reason for you to hang on to the references from [] or [][] anyway. Since you've got the Array2D object, just [][] again. Definition at line 265 of file Array2D.cpp. References value. |
|
|
Prints an Array2D. Loops through the Array2D giving a reasonably nice printout. Definition at line 292 of file Array2D.cpp. References numColumns, and numRows. |
| (SARBayes) | Main | Related Pages | Class List | Hierarchy | Methods | Files |
|---|