matrix< contents > Class Template Reference

Represents a two-dimensional array of objects. More...

#include <matrix.h>

Inheritance diagram for matrix< contents >:

Inheritance graph
[legend]
Collaboration diagram for matrix< contents >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 matrix (int rows=0, int cols=0, contents *data=NIL)
 the "data" array must have at least "rows" * "cols" contents in it.
 matrix (const matrix &to_copy)
 ~matrix ()
int rows () const
int columns () const
matrixoperator= (const matrix &to_copy)
contents & get (int row, int column)
const contents & get (int row, int column) const
 retrieves the contents from the specified "row" and "column".
bool put (int row, int column, const contents &to_put)
 stores "to_put" into the matrix at "row" and "column".
contents * operator[] (int row)
 dangerous: indexes by "row" into the underlying contents.
const contents * operator[] (int row) const
 dangerous: constant peek into data for "row" in underlying contents.
matrix submatrix (int row, int column, int rows, int columns) const
 returns a submatrix of this one starting at "row" and "column".
void submatrix (matrix &sub, int row, int column, int rows, int cols) const
 like submatrix() above, but stores into the "sub" parameter.
matrix transpose () const
 provides the transposed form of this matrix.
void transpose (matrix &resultant) const
 stores the transpose of this matrix in "resultant".
array< contents > get_row (int row)
 return the vector at the "row", or an empty array if "row" is invalid.
array< contents > get_column (int column)
 return the vector at the "column", or an empty array if it's invalid.
bool insert_row (int before_row)
 inserts a row before the "before_" parameter.
bool insert_column (int before_column)
 inserts a column before the "before_" parameter.
void reset (int rows=0, int columns=0)
 empties the matrix and changes its size.
void redimension (int new_rows, int new_columns)
 changes the size to contain "new_rows" by "new_columns" elements.
bool zap_row (int row_to_zap)
bool zap_column (int column_to_zap)
 removes a row or column from the matrix.

Detailed Description

template<class contents>
class matrix< contents >

Represents a two-dimensional array of objects.

The indices range from zero to (maximum_value - 1) for rows and columns.

Definition at line 26 of file matrix.h.


Constructor & Destructor Documentation

template<class contents>
matrix< contents >::matrix ( int  rows = 0,
int  cols = 0,
contents *  data = NIL 
)

the "data" array must have at least "rows" * "cols" contents in it.

Definition at line 32 of file matrix.cpp.

template<class contents>
matrix< contents >::matrix ( const matrix< contents > &  to_copy  ) 

Definition at line 36 of file matrix.cpp.

template<class contents>
matrix< contents >::~matrix (  )  [inline]

Definition at line 33 of file matrix.h.


Member Function Documentation

template<class contents>
int matrix< contents >::rows (  )  const [inline]

Definition at line 35 of file matrix.h.

Referenced by column_headers::format(), matrix< contents >::get_column(), matrix< contents >::get_row(), matrix< contents >::insert_column(), matrix< contents >::insert_row(), matrix< contents >::put(), matrix< contents >::redimension(), matrix< contents >::submatrix(), matrix< contents >::transpose(), matrix< contents >::zap_column(), and matrix< contents >::zap_row().

template<class contents>
int matrix< contents >::columns (  )  const [inline]

Definition at line 36 of file matrix.h.

Referenced by matrix< contents >::get_column(), matrix< contents >::get_row(), matrix< contents >::insert_column(), matrix< contents >::insert_row(), matrix< contents >::put(), matrix< contents >::redimension(), matrix< contents >::submatrix(), matrix< contents >::transpose(), matrix< contents >::zap_column(), and matrix< contents >::zap_row().

template<class contents>
matrix< contents > & matrix< contents >::operator= ( const matrix< contents > &  to_copy  ) 

Definition at line 41 of file matrix.cpp.

References matrix< contents >::_cols, matrix< contents >::_rows, and array< contents >::operator=().

template<class contents>
contents & matrix< contents >::get ( int  row,
int  column 
)

Definition at line 63 of file matrix.cpp.

References array< contents >::operator[]().

Referenced by matrix< contents >::get_column(), and matrix< contents >::get_row().

template<class contents>
const contents & matrix< contents >::get ( int  row,
int  column 
) const

retrieves the contents from the specified "row" and "column".

Definition at line 59 of file matrix.cpp.

References array< contents >::get().

template<class contents>
bool matrix< contents >::put ( int  row,
int  column,
const contents &  to_put 
)

stores "to_put" into the matrix at "row" and "column".

Definition at line 101 of file matrix.cpp.

References matrix< contents >::columns(), matrix< contents >::operator[](), and matrix< contents >::rows().

Referenced by matrix< contents >::insert_column(), and matrix< contents >::insert_row().

template<class contents>
contents * matrix< contents >::operator[] ( int  row  ) 

dangerous: indexes by "row" into the underlying contents.

the result can be used as a pointer to the whole row of data, or it can be indexed into by column to find a row/column position. this is dangerous if one is not careful about ensuring that the column used is within bounds. if the "row" parameter is out of bounds, then NIL is returned.

Reimplemented from array< contents >.

Definition at line 51 of file matrix.cpp.

References array< contents >::operator[]().

Referenced by matrix< contents >::put().

template<class contents>
const contents * matrix< contents >::operator[] ( int  row  )  const

dangerous: constant peek into data for "row" in underlying contents.

Reimplemented from array< contents >.

Definition at line 55 of file matrix.cpp.

References array< contents >::operator[]().

template<class contents>
matrix< contents > matrix< contents >::submatrix ( int  row,
int  column,
int  rows,
int  columns 
) const

returns a submatrix of this one starting at "row" and "column".

The returned matrix should contain "rows" rows and "columns" columns. if the size or position are out of bounds, an empty matrix is returned.

Definition at line 110 of file matrix.cpp.

template<class contents>
void matrix< contents >::submatrix ( matrix< contents > &  sub,
int  row,
int  column,
int  rows,
int  cols 
) const

like submatrix() above, but stores into the "sub" parameter.

Definition at line 119 of file matrix.cpp.

References matrix< contents >::columns(), matrix< contents >::reset(), and matrix< contents >::rows().

template<class contents>
matrix< contents > matrix< contents >::transpose (  )  const

provides the transposed form of this matrix.

Definition at line 132 of file matrix.cpp.

template<class contents>
void matrix< contents >::transpose ( matrix< contents > &  resultant  )  const

stores the transpose of this matrix in "resultant".

Definition at line 140 of file matrix.cpp.

References matrix< contents >::columns(), matrix< contents >::reset(), and matrix< contents >::rows().

template<class contents>
array< contents > matrix< contents >::get_row ( int  row  ) 

return the vector at the "row", or an empty array if "row" is invalid.

Definition at line 149 of file matrix.cpp.

References matrix< contents >::columns(), matrix< contents >::get(), array< contents >::reset(), and matrix< contents >::rows().

template<class contents>
array< contents > matrix< contents >::get_column ( int  column  ) 

return the vector at the "column", or an empty array if it's invalid.

Definition at line 160 of file matrix.cpp.

References matrix< contents >::columns(), matrix< contents >::get(), array< contents >::reset(), and matrix< contents >::rows().

template<class contents>
bool matrix< contents >::insert_row ( int  before_row  ) 

inserts a row before the "before_" parameter.

all existing data is preserved in the matrix, although it may get moved over depending on where it's located with respect to "before_row".

Definition at line 202 of file matrix.cpp.

References bounds_halt, matrix< contents >::columns(), FUNCDEF, array< contents >::insert(), matrix< contents >::put(), and matrix< contents >::rows().

template<class contents>
bool matrix< contents >::insert_column ( int  before_column  ) 

inserts a column before the "before_" parameter.

Definition at line 216 of file matrix.cpp.

References bounds_halt, matrix< contents >::columns(), FUNCDEF, matrix< contents >::put(), and matrix< contents >::rows().

template<class contents>
void matrix< contents >::reset ( int  rows = 0,
int  columns = 0 
)

empties the matrix and changes its size.

Definition at line 71 of file matrix.cpp.

References array< contents >::insert(), and array< contents >::reset().

Referenced by matrix< contents >::submatrix(), and matrix< contents >::transpose().

template<class contents>
void matrix< contents >::redimension ( int  new_rows,
int  new_columns 
)

changes the size to contain "new_rows" by "new_columns" elements.

data that was held previously stays in the array as long as its row and column indices are still valid.

Definition at line 90 of file matrix.cpp.

References matrix< contents >::columns(), minimum(), and matrix< contents >::rows().

template<class contents>
bool matrix< contents >::zap_row ( int  row_to_zap  ) 

Definition at line 171 of file matrix.cpp.

References bounds_halt, matrix< contents >::columns(), FUNCDEF, matrix< contents >::rows(), and array< contents >::zap().

template<class contents>
bool matrix< contents >::zap_column ( int  column_to_zap  ) 

removes a row or column from the matrix.

the matrix becomes one row or column less than before and all data from the deleted vector is lost.

Definition at line 187 of file matrix.cpp.

References bounds_halt, matrix< contents >::columns(), FUNCDEF, matrix< contents >::rows(), and array< contents >::zap().


The documentation for this class was generated from the following files:
Generated on Fri Oct 10 04:30:22 2008 for HOOPLE Libraries by  doxygen 1.5.1