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