Bimetric 3+1 toolkit for spherical symmetry
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Matrix< T > Class Template Reference

A matrix (a two-dimensional array) of elements. More...

#include <matrix.h>

Public Types

typedef T value_type
 Makes T available externally.

Public Member Functions

 Matrix ()
 ~Matrix ()
 Matrix (Int n, Int m)
 Matrix (Int n, Int m, const T &c)
 Matrix (Int n, Int m, const T *ap)
 Matrix (const Matrix &rhs)
Matrix< T > & operator= (const Matrix< T > &rhs)
 The matrix assignment.
T * operator[] (const Int i)
 Returns the pointer to a row.
const T * operator[] (const Int i) const
Int nrows () const
Int ncols () const
void resize (Int newn, Int newm)
void assign (Int newn, Int newm, const T &c)

Private Attributes

Int nn
 The number of rows.
Int mm
 The number of columns.
T ** v
 The elements of the two-dimensional array.

Detailed Description

template<class T>
class Matrix< T >

A matrix (a two-dimensional array) of elements.

Definition at line 160 of file matrix.h.


Member Typedef Documentation

template<class T>
typedef T Matrix< T >::value_type

Makes T available externally.

Definition at line 167 of file matrix.h.


Constructor & Destructor Documentation

template<class T>
Matrix< T >::Matrix ( ) [inline]

Definition at line 169 of file matrix.h.

        : nn(0), mm(0)
        , v(NULL)
    {}
template<class T>
Matrix< T >::~Matrix ( ) [inline]

Definition at line 174 of file matrix.h.

    {
        if( v != NULL ) {
            delete[] v[0];
            delete[] v;
        }
    }
template<class T>
Matrix< T >::Matrix ( Int  n,
Int  m 
) [inline]

Definition at line 182 of file matrix.h.

        : nn(n), mm(m)
        , v( n > 0 ? new T*[n] : NULL )
    {
        Int nel = m * n;
        if( v ) {
            v[0] = nel > 0 ? new T[nel] : NULL;
        }
        for( Int i = 1; i < n; ++i ) {
            v[i] = v[i-1] + m;
        }
    }
template<class T>
Matrix< T >::Matrix ( Int  n,
Int  m,
const T &  c 
) [inline]

Definition at line 195 of file matrix.h.

        : nn(n), mm(m)
        , v( n > 0 ? new T*[n] : NULL )
    {
        Int nel = m*n;
        if( v ) {
            v[0] = nel > 0 ? new T[nel] : NULL;
        }
        for( Int i = 1; i < n; ++i ) {
            v[i] = v[i-1] + m;
        }
        for( Int i = 0; i < n; ++i ) {
            for( Int j = 0; j < m; ++j ) {
                v[i][j] = c;
            }
        }
    }
template<class T>
Matrix< T >::Matrix ( Int  n,
Int  m,
const T *  ap 
) [inline]

Definition at line 213 of file matrix.h.

        : nn(n), mm(m)
        , v( n > 0 ? new T*[n] : NULL )
    {
        Int nel = m * n;
        if( v ) {
            v[0] = nel > 0 ? new T[nel] : NULL;
        }
        for( Int i = 1; i < n; ++i ) {
            v[i] = v[i-1] + m;
        }
        for( Int i = 0; i < n; ++i ) {
            for( Int j = 0; j < m; ++j ) {
                v[i][j] = *ap++;
            }
        }
    }
template<class T>
Matrix< T >::Matrix ( const Matrix< T > &  rhs) [inline]

Definition at line 231 of file matrix.h.

        : nn(rhs.nn), mm(rhs.mm)
        , v( nn > 0 ? new T*[nn] : NULL )
    {
        Int nel = mm * nn;
        if( v ) {
            v[0] = nel > 0 ? new T[nel] : NULL;
        }
        for( Int i = 1; i< nn; ++i ) {
            v[i] = v[i-1] + mm;
        }
        for( Int i = 0; i< nn; ++i ) {
            for( Int j = 0; j<mm; ++j ) {
                v[i][j] = rhs[i][j];
            }
        }
    }

Member Function Documentation

template<class T>
void Matrix< T >::assign ( Int  newn,
Int  newm,
const T &  c 
) [inline]

Definition at line 323 of file matrix.h.

    {
        Int i,j,nel;
        if( newn != nn || newm != mm ) {
            if( v != NULL ) {
                delete[] v[0];
                delete[] v;
            }
            nn = newn;
            mm = newm;
            v = nn>0 ? new T*[nn] : NULL;
            nel = mm*nn;
            if( v ) v[0] = nel>0 ? new T[nel] : NULL;
            for( i = 1; i < nn; ++i )
                v[i] = v[i-1] + mm;
        }
        for( i = 0; i < nn; ++i )
            for( j = 0; j<mm; ++j )
                v[i][j] = c;
    }
template<class T>
Int Matrix< T >::ncols ( ) const [inline]

Definition at line 297 of file matrix.h.

                       {
        return mm;
    }
template<class T>
Int Matrix< T >::nrows ( ) const [inline]

Definition at line 293 of file matrix.h.

                       {
        return nn;
    }
template<class T>
Matrix<T>& Matrix< T >::operator= ( const Matrix< T > &  rhs) [inline]

The matrix assignment.

Postcondition: normal assignment via copying has been performed; If matrix and rhs were different sizes, matrix has been resized to match the size of rhs

Definition at line 253 of file matrix.h.

    {
        if( this != &rhs ) {
            Int i,j,nel;
            if (nn != rhs.nn || mm != rhs.mm) {
                if (v != NULL) {
                    delete[] v[0];
                    delete[] v;
                }
                nn=rhs.nn;
                mm=rhs.mm;
                v = nn>0 ? new T*[nn] : NULL;
                nel = mm*nn;
                if( v ) {
                    v[0] = nel > 0 ? new T[nel] : NULL;
                }
                for( i = 1; i< nn; ++i )
                    v[i] = v[i-1] + mm;
            }
            for( i = 0; i< nn; ++i )
                for( j = 0; j<mm; ++j )
                    v[i][j] = rhs[i][j];
        }
        return *this;
    }
template<class T>
T* Matrix< T >::operator[] ( const Int  i) [inline]

Returns the pointer to a row.

Definition at line 281 of file matrix.h.

    {
        assertBounds( i >= 0 && i < nn, "Matrix subscript out of bounds" );
        return v[i];
    }
template<class T>
const T* Matrix< T >::operator[] ( const Int  i) const [inline]

Definition at line 287 of file matrix.h.

    {
        assertBounds( i >= 0 && i < nn, "Matrix subscript out of bounds" );
        return v[i];
    }
template<class T>
void Matrix< T >::resize ( Int  newn,
Int  newm 
) [inline]

Definition at line 301 of file matrix.h.

    {
        Int i,nel;
        if( newn != nn || newm != mm ) {
            if( v != NULL ) {
                delete[] v[0];
                delete[] v;
            }
            nn = newn;
            mm = newm;
            v = nn>0 ? new T*[nn] : NULL;
            nel = mm*nn;
            if( v ) {
                v[0] = nel>0 ? new T[nel] : NULL;
            }
            for( i = 1; i < nn; ++i ) {
                v[i] = v[i-1] + mm;
            }
        }
    }

Field Documentation

template<class T>
Int Matrix< T >::mm [private]

The number of columns.

Definition at line 163 of file matrix.h.

template<class T>
Int Matrix< T >::nn [private]

The number of rows.

Definition at line 162 of file matrix.h.

template<class T>
T** Matrix< T >::v [private]

The elements of the two-dimensional array.

Definition at line 164 of file matrix.h.


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