1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ftmpl_matrix.h,v 1.1 1996-12-18 15:04:42 schmidt Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_MATRIX_H |
---|
5 | #define INCL_MATRIX_H |
---|
6 | |
---|
7 | /* |
---|
8 | * $Log: not supported by cvs2svn $ |
---|
9 | */ |
---|
10 | |
---|
11 | #include <iostream.h> |
---|
12 | |
---|
13 | template <class T> |
---|
14 | class SubMatrix; |
---|
15 | |
---|
16 | template <class T> |
---|
17 | class Matrix |
---|
18 | { |
---|
19 | private: |
---|
20 | int NR, NC; |
---|
21 | T ** elems; |
---|
22 | void printrow ( ostream & s, int i ) const; |
---|
23 | public: |
---|
24 | Matrix() : NR(0), NC(0), elems(0) {} |
---|
25 | Matrix( int nr, int nc ); |
---|
26 | Matrix( const Matrix<T>& M ); |
---|
27 | ~Matrix(); |
---|
28 | Matrix<T>& operator= ( const Matrix<T>& M ); |
---|
29 | int rows() const { return NR; } |
---|
30 | int columns() const { return NC; } |
---|
31 | SubMatrix<T> operator[] ( int i ); |
---|
32 | const SubMatrix<T> operator[] ( int i ) const; |
---|
33 | T& operator() ( int row, int col ); |
---|
34 | T operator() ( int row, int col ) const; |
---|
35 | SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ); |
---|
36 | const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const; |
---|
37 | void swapRow( int i, int j ); |
---|
38 | void swapColumn( int i, int j ); |
---|
39 | void print( ostream& s ) const; |
---|
40 | friend Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
41 | friend Matrix<T> operator- ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
42 | friend Matrix<T> operator* ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
43 | friend Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs ); |
---|
44 | friend Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs ); |
---|
45 | friend ostream & operator<< ( ostream & s, const Matrix<T>& M ) |
---|
46 | { |
---|
47 | M.print( s ); |
---|
48 | return s; |
---|
49 | } |
---|
50 | friend class SubMatrix<T>; |
---|
51 | }; |
---|
52 | |
---|
53 | template <class T> |
---|
54 | class SubMatrix |
---|
55 | { |
---|
56 | private: |
---|
57 | int r_min, r_max, c_min, c_max; |
---|
58 | Matrix<T>& M; |
---|
59 | // we do not provide a default ctor, so nobody can declare an empty SubMatrix |
---|
60 | SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m ); |
---|
61 | public: |
---|
62 | SubMatrix( const SubMatrix<T> & S ); |
---|
63 | SubMatrix<T>& operator= ( const SubMatrix<T>& S ); |
---|
64 | SubMatrix<T>& operator= ( const Matrix<T>& S ); |
---|
65 | operator Matrix<T>() const; |
---|
66 | T operator[] ( int i ) const; |
---|
67 | T& operator[] ( int i ); |
---|
68 | friend class Matrix<T>; |
---|
69 | }; |
---|
70 | |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | #endif /* INCL_MATRIX_H */ |
---|