1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: ftmpl_matrix.h,v 1.9 2005-01-13 15:10:23 Singular Exp $ */ |
---|
3 | |
---|
4 | #ifndef INCL_MATRIX_H |
---|
5 | #define INCL_MATRIX_H |
---|
6 | |
---|
7 | #include <factoryconf.h> |
---|
8 | |
---|
9 | #ifndef NOSTREAMIO |
---|
10 | #include <iostream.h> |
---|
11 | #endif /* NOSTREAMIO */ |
---|
12 | |
---|
13 | template <class T> |
---|
14 | class SubMatrix; |
---|
15 | |
---|
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 | |
---|
24 | template <class T> |
---|
25 | class Matrix |
---|
26 | { |
---|
27 | private: |
---|
28 | int NR, NC; |
---|
29 | T ** elems; |
---|
30 | #ifndef NOSTREAMIO |
---|
31 | void printrow ( ostream & s, int i ) const; |
---|
32 | #endif /* NOSTREAMIO */ |
---|
33 | typedef T* T_ptr; |
---|
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 ); |
---|
50 | #ifndef NOSTREAMIO |
---|
51 | void print( ostream& s ) const; |
---|
52 | friend ostream & operator<< <>( ostream & s, const Matrix<T>& M ); |
---|
53 | #endif /* NOSTREAMIO */ |
---|
54 | friend class SubMatrix<T>; |
---|
55 | }; |
---|
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 ); |
---|
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 | |
---|
85 | #ifndef NOSTREAMIO |
---|
86 | template <class T> |
---|
87 | ostream & operator<< ( ostream & s, const Matrix<T>& M ); |
---|
88 | #endif /* NOSTREAMIO */ |
---|
89 | |
---|
90 | #endif /* ! INCL_MATRIX_H */ |
---|