/* $Id: matrix.c,v 1.1 1996/10/10 10:01:19 roitzsch Exp $ (C)opyright 1996 by Konrad-Zuse-Center, Berlin All rights reserved. Part of the Kaskade distribution */ #include "matrix.h" template void Matrix:: allocate (int rl1, int rh1, int cl1, int ch1) { rl=rl1; rh=rh1; cl=cl1; ch=ch1; row = new T*[rh-rl+1]; if (!row) { cout << "\n*** class Matrix: allocation failure\n"; cout.flush(); abort(); } row -= rl; row[rl] = new T[(rh-rl+1)*(ch-cl+1)]; if (!row[rl]) { cout << "\n*** class Matrix: allocation failure\n" ;cout.flush(); abort();} row[rl] -= cl; for (int i=rl+1; i<=rh; ++i) row[i] = row[i-1]+ch-cl+1; } template Matrix:: ~Matrix() { delete [] (row[rl]+cl); delete (row+rl); } template void Matrix:: resize (int newrh, int newch) { resize (1, newrh, 1, newch); } template void Matrix:: resize (int newrl, int newrh, int newcl, int newch) { delete (row[rl]+cl); delete (row+rl); allocate(newrl, newrh, newcl, newch); } /* template Matrix& Matrix:: operator= (Matrix& m) { int i,j; for(i=rl; i<=rh; ++i) for(j=cl; j<=ch; ++j) (*this)(i,j) = m(i,j); return *this; } template Matrix& Matrix::operator= (T a) { int i,j; for(i=rl; i<=rh; ++i) for(j=cl; j<=ch; ++j) (*this)(i,j) = a; return *this; } */ template int Matrix:: size() { return (rh-rl+1)*(ch-cl+1); } template int Matrix:: memSize() { return (rh-rl+1)*(ch-cl+1)* sizeof(T); } template void Matrix:: checkBounds(int i, int j) const { if (irh || jch) { cout << "\n*** matrix index ("< void Matrix:: checkBounds(int i) const { if (irh) { cout << "\n*** matrix row index ("< void Matrix:: print() const { int i, j; for (i=rl; i<=rh; ++i) { cout << "\n"; for (j=cl; j<=ch; ++j) cout << row[i][j] << " "; } cout << "\n"; } //------------------------------------------------------------------------- template Matrix:: Matrix(Matrix& /*vec*/) { notImplemented("Matrix:: copy constructor! Check function arguments"); } template Matrix& Matrix:: operator= (Matrix& /*vec*/) { notImplemented("Matrix:: operator=(Matrix& vec)"); return *this; // int i; for(i=l; i<=h; ++i) v[i]= vec.v[i]; return *this; } template Matrix& Matrix:: operator= (T /*a*/) { notImplemented("Matrix:: operator=(T a)"); return *this; //int i; for(i=l; i<=h; ++i) v[i]= a; return *this; } template void Matrix:: notImplemented(const char* s) const { cout << "\n*** Class Matrix: called function " << s << " not implemented\n"; cout.flush(); abort(); }