GVectors::Matrix Class Reference

The base matrix class. More...

#include <matrix.h>

Inheritance diagram for GVectors::Matrix:

GVectors::Matrix4x1 GVectors::Matrix4x4 List of all members.

Public Member Functions

 Matrix (matindex_t r, matindex_t c)
 Constructor.
 Matrix (const Matrix &m)
 Copy constructor.
const Matrixoperator= (const Matrix &m)
 Assignment operator.
virtual ~Matrix ()
 Destructor.
void set (matindex_t r, matindex_t c, double v)
 Set a value at the given position.
double get (matindex_t r, matindex_t c) const
 Get a value from the given position.
void fill (double v)
 Fill the matrix with the given value.

Public Attributes

const matindex_t rows
 The number of rows.
const matindex_t columns
 The number of columns.

Protected Member Functions

void alloc ()
 Allocates memory for the matrix.
void free ()
 Frees the memory occupied by the matrix.
void copy (double **const src)
 Copies the matrix to another memory location.
bool valid_index (matindex_t r, matindex_t c) const
 Indicates whether or not the given index is valid.

Protected Attributes

double ** matrix
 The pointer to the matrix in memory.

Detailed Description

This is the base matrix class which others are derived from. It provides all functionalities used to setup a matrix, but does not provide any operators.


Constructor & Destructor Documentation

Matrix::Matrix ( matindex_t  r,
matindex_t  c 
)

Constructor. Initializes a 'r-by-c' matrix and fills it with zeros.

Parameters:
r The number of rows.
c The number of columns.

Matrix::Matrix ( const Matrix m  ) 

Copy constructor.

Parameters:
m A const reference to a Matrix.

Matrix::~Matrix (  )  [virtual]

Destructor. Frees all memory occupied by the matrix.


Member Function Documentation

void Matrix::alloc (  )  [protected]

Allocates memory for the matrix to hold a matrix of the dimension specified when creating the object.

It uses the C function malloc() for this purpose.

void Matrix::free (  )  [protected]

Frees the memory occupied by the matrix.

It uses the C function free() for this purpose.

void Matrix::copy ( double **const   src  )  [protected]

Copies the memory content of one matrix to the matrix of this object.

Parameters:
src Pointer to an array of doubleS holding the source matrix.

bool GVectors::Matrix::valid_index ( matindex_t  r,
matindex_t  c 
) const [inline, protected]

Indicates whether or not the given matrix index is valid.

Parameters:
r Row index.
c Column index.
Returns:
Whether or not the given matrix index is valid.
Return values:
true The index provided is valid.
false The index provided is not valid.

const Matrix & Matrix::operator= ( const Matrix m  ) 

Assigns one matrix to another. The dimensions have to be identical, else an exception is thrown. In other words, you cannot assign a 4x1 matrix to a 4x4 matrix and vice versa.

Parameters:
m A const reference to a Matrix object.
Exceptions:
GVEInvalidMDimension if the dimensions of the matrices are not identical.

void Matrix::set ( matindex_t  r,
matindex_t  c,
double  v 
)

Sets a value v at the given position r, c. If the position is not within the dimension of the matrix, an exception is thrown.

Parameters:
r Row index.
c Column index.
v Value to set at the position specified.
Exceptions:
GVEInvalidMatrixIndex if the indices specified are not within the bounds of the matrix dimension.

double Matrix::get ( matindex_t  r,
matindex_t  c 
) const

Get the value at the specified position. If the position is not within the dimension of the matrix, an exception is thrown.

Parameters:
r Row index.
c Column index.
Returns:
The value at the given position.
Exceptions:
GVEInvalidMatrixIndex if the indices specified are not within the bounds of the matrix dimension.

void Matrix::fill ( double  v  ) 

Fills the entire matrix with the value given.

Parameters:
v The value used to fill the matrix.


Member Data Documentation

double** GVectors::Matrix::matrix [protected]

This is the pointer to the matrix in memory. Use this together with the Matrix::alloc_matrix(), Matrix::free_matrix(), and Matrix::copy_matrix() methods.

const matindex_t GVectors::Matrix::rows

The number of rows of the matrix.

const matindex_t GVectors::Matrix::columns

The number of columns of the matrix.


The documentation for this class was generated from the following files:
Generated on Sat Sep 8 19:37:30 2007 for libgvectors by  doxygen 1.4.7