/* emacs edit mode for this file is -*- C++ -*- */ #ifndef INCL_MATRIX_H #define INCL_MATRIX_H // #include #ifndef NOSTREAMIO #ifdef HAVE_IOSTREAM #include #define OSTREAM std::ostream #elif defined(HAVE_IOSTREAM_H) #include #define OSTREAM ostream #endif #endif /* NOSTREAMIO */ template class SubMatrix; template class Matrix; #ifndef NOSTREAMIO template OSTREAM& operator<< (OSTREAM &, const Matrix &); #endif template class Matrix { private: int NR, NC; T ** elems; #ifndef NOSTREAMIO void printrow ( OSTREAM & s, int i ) const; #endif /* NOSTREAMIO */ typedef T* T_ptr; public: Matrix() : NR(0), NC(0), elems(0) {} Matrix( int nr, int nc ); Matrix( const Matrix& M ); ~Matrix(); Matrix& operator= ( const Matrix& M ); int rows() const { return NR; } int columns() const { return NC; } SubMatrix operator[] ( int i ); const SubMatrix operator[] ( int i ) const; T& operator() ( int row, int col ); T operator() ( int row, int col ) const; SubMatrix operator() ( int rmin, int rmax, int cmin, int cmax ); const SubMatrix operator() ( int rmin, int rmax, int cmin, int cmax ) const; void swapRow( int i, int j ); void swapColumn( int i, int j ); #ifndef NOSTREAMIO void print( OSTREAM& s ) const; friend OSTREAM & operator<< ( OSTREAM & s, const Matrix& M ); #endif /* NOSTREAMIO */ friend class SubMatrix; }; template Matrix operator+ ( const Matrix& lhs, const Matrix& rhs ); template Matrix operator- ( const Matrix& lhs, const Matrix& rhs ); template Matrix operator* ( const Matrix& lhs, const Matrix& rhs ); template Matrix operator* ( const Matrix& lhs, const T& rhs ); template Matrix operator* ( const T& lhs, const Matrix& rhs ); template class SubMatrix { private: int r_min, r_max, c_min, c_max; Matrix& M; // we do not provide a default ctor, so nobody can declare an empty SubMatrix SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix & m ); public: SubMatrix( const SubMatrix & S ); SubMatrix& operator= ( const SubMatrix& S ); SubMatrix& operator= ( const Matrix& S ); operator Matrix() const; T operator[] ( int i ) const; T& operator[] ( int i ); friend class Matrix; }; #ifndef NOSTREAMIO template OSTREAM & operator<< ( OSTREAM & s, const Matrix& M ); #endif /* NOSTREAMIO */ #endif /* ! INCL_MATRIX_H */