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