Loading...
Searching...
No Matches
Matrix< T > Class Template Reference

`#include <ftmpl_matrix.h>`

## Public Member Functions

| Matrix ()
| Matrix (int nr, int nc)
| Matrix (const Matrix< T > &M)
| ~Matrix ()
Matrix< T > & | operator= (const Matrix< T > &M)
int | rows () const
int | columns () const
SubMatrix< T > | operator[] (int i)
const SubMatrix< T > | operator[] (int i) const
T & | operator() (int row, int col)
T | operator() (int row, int col) const
SubMatrix< T > | operator() (int rmin, int rmax, int cmin, int cmax)
const SubMatrix< T > | operator() (int rmin, int rmax, int cmin, int cmax) const
void | swapRow (int i, int j)
void | swapColumn (int i, int j)
void | print (OSTREAM &s) const

## Private Types

typedef T * | T_ptr

## Private Member Functions

void | printrow (OSTREAM &s, int i) const

## Private Attributes

int | NR
int | NC
T ** | elems

## Friends

class | SubMatrix< T >
OSTREAM & | operator<< (OSTREAM &s, const Matrix< T > &M)

## Detailed Description

template<class T>
class Matrix< T >

Definition at line 28 of file ftmpl_matrix.h.

## Member Typedef Documentation

## T_ptr

template<class T>

typedef T* Matrix< T >::T_ptr

private

Definition at line 36 of file ftmpl_matrix.h.

## Constructor & Destructor Documentation

## Matrix() [1/3]

template<class T>

Matrix< T >::Matrix | ( |  | ) |

inline

Definition at line 38 of file ftmpl_matrix.h.

: NR(0), NC(0), elems(0) {}
Matrix::NR
int NR
Definition ftmpl_matrix.h:31
Matrix::elems
T ** elems
Definition ftmpl_matrix.h:32
Matrix::NC
int NC
Definition ftmpl_matrix.h:31

## Matrix() [2/3]

template<class T>

Matrix< T >::Matrix | ( | int | nr,
|  | int | nc )

Definition at line 6 of file ftmpl_matrix.cc.

: NR(nr), NC(nc)
{
ASSERT( (nr > 0 && nc > 0) || (nr == 0 && nc == 0), "illegal index" );
if ( nr == 0 )
elems = 0;
else {
int i;
elems = new T_ptr[nr];
for ( i = 0; i < nr; i++ )
elems[i] = new T[nc];
}
}
ASSERT
#define ASSERT(expression, message)
Definition cf_assert.h:99
Matrix
Definition ftmpl_matrix.h:29
Matrix::T_ptr
T * T_ptr
Definition ftmpl_matrix.h:36

## Matrix() [3/3]

template<class T>

Matrix< T >::Matrix | ( | const Matrix< T > & | M | ) |

Definition at line 20 of file ftmpl_matrix.cc.

: NR(M.NR), NC(M.NC)
{
if ( NR == 0 )
elems = 0;
else {
int i, j;
elems = new T_ptr[NR];
for ( i = 0; i < NR; i++ ) {
elems[i] = new T[NC];
for ( j = 0; j < NC; j++ )
elems[i][j] = M.elems[i][j];
}
}
}

## ~Matrix()

template<class T>

Matrix< T >::~Matrix | ( |  | ) |

Definition at line 36 of file ftmpl_matrix.cc.

{
if ( elems != 0 ) {
int i;
for ( i = 0; i < NR; i++ )
delete [] elems[i];
delete [] elems;
}
}

## Member Function Documentation

## columns()

template<class T>

int Matrix< T >::columns | ( |  | ) | const

inline

Definition at line 44 of file ftmpl_matrix.h.

{ return NC; }

## operator()() [1/4]

template<class T>

SubMatrix< T > Matrix< T >::operator() | ( | int | rmin,
|  | int | rmax,
|  | int | cmin,
|  | int | cmax )

Definition at line 96 of file ftmpl_matrix.cc.

{
ASSERT( rmin > 0 && rmax <= NR && rmin <= rmax && cmin > 0 && cmax <= NC && cmin <= cmax , "illegal index" );
return SubMatrix<T>( rmin, rmax, cmin, cmax, *this );
}

## operator()() [2/4]

template<class T>

const SubMatrix< T > Matrix< T >::operator() | ( | int | rmin,
|  | int | rmax,
|  | int | cmin,
|  | int | cmax ) const

Definition at line 103 of file ftmpl_matrix.cc.

{
ASSERT( rmin > 0 && rmax <= NR && rmin <= rmax && cmin > 0 && cmax <= NC && cmin <= cmax , "illegal index" );
return SubMatrix<T>( rmin, rmax, cmin, cmax, *this );
}

## operator()() [3/4]

template<class T>

T & Matrix< T >::operator() | ( | int | row,
|  | int | col )

Definition at line 82 of file ftmpl_matrix.cc.

{
ASSERT( row > 0 && col > 0 && row <= NR && col <= NC, "illegal index" );
return elems[row-1][col-1];
}

## operator()() [4/4]

template<class T>

T Matrix< T >::operator() | ( | int | row,
|  | int | col ) const

Definition at line 89 of file ftmpl_matrix.cc.

{
ASSERT( row > 0 && col > 0 && row <= NR && col <= NC, "illegal index" );
return elems[row-1][col-1];
}

## operator=()

template<class T>

Matrix< T > & Matrix< T >::operator= | ( | const Matrix< T > & | M | ) |

Definition at line 47 of file ftmpl_matrix.cc.

{
if ( this != &M ) {
int i, j;
if ( NR != M.NR || NC != M.NC ) {
for ( i = 0; i < NR; i++ )
delete [] elems[i];
delete [] elems;
NR = M.NR; NC = M.NC;
elems = new T_ptr[NR];
for ( i = 0; i < NR; i++ )
elems[i] = new T[NC];
}
for ( i = 0; i < NR; i++ )
for ( j = 0; j < NC; j++ )
elems[i][j] = M.elems[i][j];
}
return *this;
}

## operator[]() [1/2]

template<class T>

SubMatrix< T > Matrix< T >::operator[] | ( | int | i | ) |

Definition at line 68 of file ftmpl_matrix.cc.

{
ASSERT( i > 0 && i <= NR, "illegal index" );
return SubMatrix<T>( i, i, 1, NC, *this );
}

## operator[]() [2/2]

template<class T>

const SubMatrix< T > Matrix< T >::operator[] | ( | int | i | ) | const

Definition at line 75 of file ftmpl_matrix.cc.

{
ASSERT( i > 0 && i <= NR, "illegal index" );
return SubMatrix<T>( i, i, 1, NC, *this );
}

## print()

template<class T>

void Matrix< T >::print | ( | OSTREAM & | s | ) | const

Definition at line 147 of file ftmpl_matrix.cc.

{
if ( NR == 0 )
s << "( )";
else if ( NR == 1 ) {
s << "( ";
printrow( s, 0 );
s << " )";
}
else {
int i;
s << "(\n";
printrow( s, 0 );
for ( i = 1; i < NR; i++ ) {
s << ",\n";
printrow( s, i );
}
s << "\n)";
}
}
Matrix::printrow
void printrow(OSTREAM &s, int i) const
Definition ftmpl_matrix.cc:138

## printrow()

template<class T>

void Matrix< T >::printrow | ( | OSTREAM & | s,
|  | int | i ) const

private

Definition at line 138 of file ftmpl_matrix.cc.

{
s << "( " << elems[i][0];
for ( int j = 1; j < NC; j++ )
s << ", " << elems[i][j];
s << " )";
}

## rows()

template<class T>

int Matrix< T >::rows | ( |  | ) | const

inline

Definition at line 43 of file ftmpl_matrix.h.

{ return NR; }

## swapColumn()

template<class T>

void Matrix< T >::swapColumn | ( | int | i,
|  | int | j )

Definition at line 122 of file ftmpl_matrix.cc.

{
ASSERT( i > 0 && i <= NC && j > 0 && j <= NC, "illegal index" );
if ( i != j ) {
int k;
i--; j--;
for ( k = 0; k < NR; k++ ) {
T h = elems[k][i];
elems[k][i] = elems[k][j];
elems[k][j] = h;
}
}
}

## swapRow()

template<class T>

void Matrix< T >::swapRow | ( | int | i,
|  | int | j )

Definition at line 110 of file ftmpl_matrix.cc.

{
ASSERT( i > 0 && i <= NR && j > 0 && j <= NR, "illegal index" );
if ( i != j ) {
i--; j--;
T * h = elems[i];
elems[i] = elems[j];
elems[j] = h;
}
}

## Friends And Related Symbol Documentation

## operator<<

template<class T>

OSTREAM & operator<< | ( | OSTREAM & | s,
|  | const Matrix< T > & | M )

friend

Definition at line 314 of file ftmpl_matrix.cc.

{
M.print( s );
return s;
}
Matrix::print
void print(OSTREAM &s) const
Definition ftmpl_matrix.cc:147

## SubMatrix< T >

template<class T>

friend class SubMatrix< T >

friend

Definition at line 55 of file ftmpl_matrix.h.

## Field Documentation

## elems

template<class T>

T** Matrix< T >::elems

private

Definition at line 32 of file ftmpl_matrix.h.

## NC

template<class T>

int Matrix< T >::NC

private

Definition at line 31 of file ftmpl_matrix.h.

## NR

template<class T>

int Matrix< T >::NR

private

Definition at line 31 of file ftmpl_matrix.h.

The documentation for this class was generated from the following files:

- factory/include/factory/templates/ftmpl_matrix.h
- factory/templates/ftmpl_matrix.cc