[6ab5981] | 1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
[ed97c1] | 2 | /* $Id: ftmpl_matrix.h,v 1.10 2005-01-13 15:11:36 Singular Exp $ */ |
---|
[c5f2101] | 3 | |
---|
| 4 | #ifndef INCL_MATRIX_H |
---|
| 5 | #define INCL_MATRIX_H |
---|
| 6 | |
---|
[6881f9b] | 7 | #include <factoryconf.h> |
---|
[8c0163] | 8 | |
---|
[175e355] | 9 | #ifndef NOSTREAMIO |
---|
[c5f2101] | 10 | #include <iostream.h> |
---|
[175e355] | 11 | #endif /* NOSTREAMIO */ |
---|
[c5f2101] | 12 | |
---|
| 13 | template <class T> |
---|
| 14 | class SubMatrix; |
---|
| 15 | |
---|
[22347b6] | 16 | template <class T> |
---|
| 17 | class Matrix; |
---|
| 18 | |
---|
| 19 | #ifndef NOSTREAMIO |
---|
| 20 | template <class T> |
---|
| 21 | std::ostream& operator<< (std::ostream &, const Matrix<T> &); |
---|
| 22 | #endif |
---|
| 23 | |
---|
[c5f2101] | 24 | template <class T> |
---|
| 25 | class Matrix |
---|
| 26 | { |
---|
| 27 | private: |
---|
| 28 | int NR, NC; |
---|
| 29 | T ** elems; |
---|
[175e355] | 30 | #ifndef NOSTREAMIO |
---|
[c5f2101] | 31 | void printrow ( ostream & s, int i ) const; |
---|
[175e355] | 32 | #endif /* NOSTREAMIO */ |
---|
[8840725] | 33 | typedef T* T_ptr; |
---|
[c5f2101] | 34 | public: |
---|
| 35 | Matrix() : NR(0), NC(0), elems(0) {} |
---|
| 36 | Matrix( int nr, int nc ); |
---|
| 37 | Matrix( const Matrix<T>& M ); |
---|
| 38 | ~Matrix(); |
---|
| 39 | Matrix<T>& operator= ( const Matrix<T>& M ); |
---|
| 40 | int rows() const { return NR; } |
---|
| 41 | int columns() const { return NC; } |
---|
| 42 | SubMatrix<T> operator[] ( int i ); |
---|
| 43 | const SubMatrix<T> operator[] ( int i ) const; |
---|
| 44 | T& operator() ( int row, int col ); |
---|
| 45 | T operator() ( int row, int col ) const; |
---|
| 46 | SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ); |
---|
| 47 | const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const; |
---|
| 48 | void swapRow( int i, int j ); |
---|
| 49 | void swapColumn( int i, int j ); |
---|
[175e355] | 50 | #ifndef NOSTREAMIO |
---|
| 51 | void print( ostream& s ) const; |
---|
[ed97c1] | 52 | friend ostream & operator<< <T>( ostream & s, const Matrix<T>& M ); |
---|
[175e355] | 53 | #endif /* NOSTREAMIO */ |
---|
[c5f2101] | 54 | friend class SubMatrix<T>; |
---|
| 55 | }; |
---|
[2457a8] | 56 | template <class T> |
---|
| 57 | Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
| 58 | template <class T> |
---|
| 59 | Matrix<T> operator- ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
| 60 | template <class T> |
---|
| 61 | Matrix<T> operator* ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
| 62 | template <class T> |
---|
| 63 | Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs ); |
---|
| 64 | template <class T> |
---|
| 65 | Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs ); |
---|
[c5f2101] | 66 | |
---|
| 67 | template <class T> |
---|
| 68 | class SubMatrix |
---|
| 69 | { |
---|
| 70 | private: |
---|
| 71 | int r_min, r_max, c_min, c_max; |
---|
| 72 | Matrix<T>& M; |
---|
| 73 | // we do not provide a default ctor, so nobody can declare an empty SubMatrix |
---|
| 74 | SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m ); |
---|
| 75 | public: |
---|
| 76 | SubMatrix( const SubMatrix<T> & S ); |
---|
| 77 | SubMatrix<T>& operator= ( const SubMatrix<T>& S ); |
---|
| 78 | SubMatrix<T>& operator= ( const Matrix<T>& S ); |
---|
| 79 | operator Matrix<T>() const; |
---|
| 80 | T operator[] ( int i ) const; |
---|
| 81 | T& operator[] ( int i ); |
---|
| 82 | friend class Matrix<T>; |
---|
| 83 | }; |
---|
| 84 | |
---|
[5bb462] | 85 | #ifndef NOSTREAMIO |
---|
| 86 | template <class T> |
---|
| 87 | ostream & operator<< ( ostream & s, const Matrix<T>& M ); |
---|
| 88 | #endif /* NOSTREAMIO */ |
---|
| 89 | |
---|
[6ab5981] | 90 | #endif /* ! INCL_MATRIX_H */ |
---|