Public Types | Public Member Functions | Protected Member Functions

CjMatrix< T > Class Template Reference

A template representing a 2D matrix. More...

#include <CjMatrix.hh>

List of all members.

Public Types

typedef CjMatrixSubVector< T,
false > 
row_t
 a subvector describing a row in a matrix
typedef CjMatrixSubVector< T,
true > 
column_t
 a subvector describing a column in a matrix
typedef CjMatrixSubVectorC< T,
false > 
const_row_t
 a const subvector describing a row in a matrix
typedef CjMatrixSubVectorC< T,
true > 
const_column_t
 a const subvector describing a column in a matrix

Public Member Functions

 CjMatrix (const unsigned int width, const unsigned int height, const T *const defaultValue=0)
 Creates a matrix filled with the default value if one is specified.
 CjMatrix (CjMatrixImpl< T > *impl) throw ()
 Creates a matrix initialised by an externally provided CjMatrixImpl.
 CjMatrix (const CjMatrix &cjm, const unsigned int width, const unsigned int height, const T *const defaultValue=0)
 Creates a matrix which is a copy of the specified matrix but with a given size.
 CjMatrix (const CjMatrix &cjm)
 Creates a matrix which is a copy of another CjMatrix.
 ~CjMatrix ()
 Deletes the CjMatrix.
CjMatrix< T > & operator= (const CjMatrix< T > &cjm)
 Copies the values of the cells of the specified CjMatrix.
void resize_with_copy (unsigned int width, unsigned int height, const CjMatrix< T > *cjm=(CjMatrix< T > *) 0)
 Resizes the current matrix to the given size and optionally copies values from another matrix.
CjMatrix< T > & setColumnValues (unsigned int col, const T &val)
 Sets all the values in a given column to the specified value.
CjMatrix< T > & setRowValues (unsigned int row, const T &val)
 Sets all the values in a given row to the specified value.
CjMatrix< T > & setAllValues (const T val)
 Sets all the values in matrix to the specified value.
CjMatrix< T > & setDiagonal (const T &val)
 Sets all the values in top-left to bottom-right diagonal of the matrix to the specified value.
CjMatrix< T > & setDefaultValue (const T &val)
 Sets the default default value to use in new cells when resizing/copying the matrix.
getDefaultValue () const
 Gets the default default value used in new cells when resizing/copying the matrix.
bool getDefaultValueSet () const
 Returns true if a default has been set, false if the cell type's default will be used.
bool operator== (const CjMatrix< T > &cjm) const
 Compare another CjMatrix for equality.
bool operator!= (const CjMatrix< T > &cjm) const
 Compare another CjMatrix for inequality.
CjMatrix< T > & transpose (void)
 Transpose the matrix.
bool isSymmetric () const
 Tests for matrix symmetry.
unsigned int getWidth () const
 Returns the width of the matrix.
unsigned int getHeight () const
 Returns the height of the matrix.
T & at (const unsigned int row, const unsigned int col)
 Returns a reference to the cell at a given row and column.
const T & at (const unsigned int row, const unsigned int col) const
 Returns a const reference to the cell at a given row and column.
T & operator() (const unsigned int row, const unsigned int col)
 Returns a reference to the cell at a given row and column (no bounds checking).
const T & operator() (const unsigned int row, const unsigned int col) const
 Returns a const reference to the cell at a given row and column (no bounds checking).
row_t row (const int r)
 Returns a row subvector into the matrix (no bounds checking is done on r).
column_t column (const int c)
 Returns a column subvector into the matrix (no bounds checking is done on c).
const_row_t row (const int r) const
 Returns a row const subvector into the matrix (no bounds checking is done on r).
const_column_t column (const int c) const
 Returns a column const subvector into the matrix (no bounds checking is done on c).
column_t::iterator rows_begin ()
 Returns the begin column iterator of the first column. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each row.
column_t::iterator rows_end ()
 Returns the end column iterator of the first column. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each row.
const_column_t::const_iterator rows_cbegin ()
 Returns the const begin column iterator of the first column. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each row.
const_column_t::const_iterator rows_cend ()
 Returns the const end column iterator of the first column. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each row.
row_t::iterator columns_begin ()
 Returns the begin row iterator of the first row. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each column.
row_t::iterator columns_end ()
 Returns the end row iterator of the first row. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each column.
const_row_t::const_iterator columns_cbegin ()
 Returns the const begin row iterator of the first row. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each column.
const_row_t::const_iterator columns_cend ()
 Returns the const end row iterator of the first row. Use along with CjMatrixSubVector_iterator::convertType() to the traverse each column.
void swap (CjMatrix< T > &other)

Protected Member Functions

CjMatrixImpl< T > * get_impl ()

Detailed Description

template<typename T>
class CjMatrix< T >

A template representing a 2D matrix.

Iterators are provided to simplify access to the rows and columns. There are also methods for bulk assignment.
CjMatrix is implemented as an NVI pattern with CjMatrixImpl specifying the internal representation of the matrix - by default this is CjMatrixImpl_1D

Template Parameters:
<T> { The type stored at each cells in the matrix - this must be default constructable and copyable }

Constructor & Destructor Documentation

template<typename T>
CjMatrix< T >::CjMatrix ( const unsigned int  width,
const unsigned int  height,
const T *const   defaultValue = 0 
) [inline]

Creates a matrix filled with the default value if one is specified.

Creates an empty matrix of the given size. The cells are optionally set to a default value.

Parameters:
width the width of the new matrix
height the height of the new matrix
defaultValue a pointer to the default value which is it be copied into each newly initialised cell. If this is 0 then no cell initialisation is performed
Exceptions:
E_CjMatrix_MemoryAllocFail when memory cannot be allocated to store the matrix
E_CjMatrix_SizeError in case the size parameters supplied are invalid
template<typename T>
CjMatrix< T >::CjMatrix ( CjMatrixImpl< T > *  impl  )  throw () [inline]

Creates a matrix initialised by an externally provided CjMatrixImpl.

The CjMatrix object will take over ownership of the supplied CjMatrixImpl and delete it when necessary

Parameters:
impl A pointer to the CjMatrixImpl object (CjMatrix assumes ownership).
template<typename T>
CjMatrix< T >::CjMatrix ( const CjMatrix< T > &  cjm,
const unsigned int  width,
const unsigned int  height,
const T *const   defaultValue = 0 
) [inline, explicit]

Creates a matrix which is a copy of the specified matrix but with a given size.

The resulting matrix has a size specified by parameters width and height. If these are smaller than the source matrix then only the overlapping region is copied. If these are larger then the additional cells are optionally set to a default value.

Parameters:
cjm The CjMatrix to copy values from
width the width of the new matrix
height the height of the new matrix
defaultValue a pointer to the default value which is it be copied into each newly initialised cell. If this is 0 then no cell initialisation is performed
Exceptions:
E_CjMatrix_MemoryAllocFail when memory cannot be allocated to store the matrix
E_CjMatrix_SizeError in case the size parameters supplied are invalid
template<typename T>
CjMatrix< T >::CjMatrix ( const CjMatrix< T > &  cjm  )  [inline, explicit]

Creates a matrix which is a copy of another CjMatrix.

The supplied matrix is copied and the new matrix has the same CjMatrixImpl type

Parameters:
cjm The CjMatrix to copy
Exceptions:
E_CjMatrix_MemoryAllocFail when memory cannot be allocated to store the matrix

Member Function Documentation

template<typename T>
T& CjMatrix< T >::at ( const unsigned int  row,
const unsigned int  col 
) [inline]

Returns a reference to the cell at a given row and column.

Exceptions:
E_CjMatrix_BoundsError if the row or column is outside the bounds of width and height
template<typename T>
const T& CjMatrix< T >::at ( const unsigned int  row,
const unsigned int  col 
) const [inline]

Returns a const reference to the cell at a given row and column.

Exceptions:
E_CjMatrix_BoundsError if the row or column is outside the bounds of width and height
template<typename T>
bool CjMatrix< T >::isSymmetric (  )  const [inline]

Tests for matrix symmetry.

returns true if matrix(i,j) == matrix(j,i) for all i,j.

template<typename T>
bool CjMatrix< T >::operator!= ( const CjMatrix< T > &  cjm  )  const [inline]

Compare another CjMatrix for inequality.

Returns true if the matrices are either of different dimensions, or any of the equivalent elements are not equal according to ??TODO??, false otherwise.

Parameters:
cjm The CjMatrix to compare against
template<typename T>
T& CjMatrix< T >::operator() ( const unsigned int  row,
const unsigned int  col 
) [inline]

Returns a reference to the cell at a given row and column (no bounds checking).

No bounds checking is done on row and column - use at your own risk.

template<typename T>
const T& CjMatrix< T >::operator() ( const unsigned int  row,
const unsigned int  col 
) const [inline]

Returns a const reference to the cell at a given row and column (no bounds checking).

No bounds checking is done on row and column - use at your own risk.

template<typename T>
CjMatrix<T>& CjMatrix< T >::operator= ( const CjMatrix< T > &  cjm  )  [inline]

Copies the values of the cells of the specified CjMatrix.

The current object is potentially resized to match the object being copied

Parameters:
cjm The CjMatrix to copy
Exceptions:
E_CjMatrix_MemoryAllocFail when memory cannot be allocated to store the matrix
template<typename T>
bool CjMatrix< T >::operator== ( const CjMatrix< T > &  cjm  )  const [inline]

Compare another CjMatrix for equality.

Returns true if the matrices have the same dimensions and equivalent elements are equal according to ??TODO??, false otherwise.

Parameters:
cjm The CjMatrix to compare against
template<typename T>
void CjMatrix< T >::resize_with_copy ( unsigned int  width,
unsigned int  height,
const CjMatrix< T > *  cjm = (CjMatrix<T> *) 0 
) [inline]

Resizes the current matrix to the given size and optionally copies values from another matrix.

The resulting matrix has a size specified by parameters width and height. If these are smaller than the source matrix then only the overlapping region is copied. If these are larger then the additional cells are optionally set to a default value.

Parameters:
width the width of the new matrix
height the height of the new matrix
cjm The CjMatrix to optionally copy TODO throws??
Exceptions:
E_CjMatrix_MemoryAllocFail when memory cannot be allocated to store the matrix
E_CjMatrix_SizeError in case the size parameters supplied are invalid
template<typename T>
CjMatrix<T>& CjMatrix< T >::setAllValues ( const T  val  )  [inline]

Sets all the values in matrix to the specified value.

Parameters:
val The value to copy to each cell in the matrix.
template<typename T>
CjMatrix<T>& CjMatrix< T >::setColumnValues ( unsigned int  col,
const T &  val 
) [inline]

Sets all the values in a given column to the specified value.

Parameters:
col The index of the column to fill.
val The value to copy to each cell in the column.
Exceptions:
E_CjMatrix_BoundsError when the column index specified is outside the bounds of the size of the matrix
template<typename T>
CjMatrix<T>& CjMatrix< T >::setDefaultValue ( const T &  val  )  [inline]

Sets the default default value to use in new cells when resizing/copying the matrix.

Parameters:
val The value to which to set the default to.
template<typename T>
CjMatrix<T>& CjMatrix< T >::setDiagonal ( const T &  val  )  [inline]

Sets all the values in top-left to bottom-right diagonal of the matrix to the specified value.

Parameters:
val The value to copy to the digaonal cells in the matrix.
template<typename T>
CjMatrix<T>& CjMatrix< T >::setRowValues ( unsigned int  row,
const T &  val 
) [inline]

Sets all the values in a given row to the specified value.

Parameters:
row The index of the row to fill.
val The value to copy to each cell in the row.
Exceptions:
E_CjMatrix_BoundsError when the row index specified is outside the bounds of the size of the matrix
template<typename T>
CjMatrix<T>& CjMatrix< T >::transpose ( void   )  [inline]

Transpose the matrix.

matrix(i,j) = matrix(j,i) for all i,j. Returns a reference to the current matrix.

Exceptions:
TODO?? 

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator