1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ftmpl_matrix.h,v 1.5 1997-04-30 13:08:28 schmidt Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_MATRIX_H |
---|
5 | #define INCL_MATRIX_H |
---|
6 | |
---|
7 | /* |
---|
8 | * $Log: not supported by cvs2svn $ |
---|
9 | * Revision 1.4 1997/04/18 16:42:01 schmidt |
---|
10 | * o class Matrix: typedef T* T_ptr; added |
---|
11 | * |
---|
12 | * Revision 1.3 1997/04/15 10:13:42 schmidt |
---|
13 | * #include <config.h> added |
---|
14 | * the header config.h will be included be makeheader |
---|
15 | * |
---|
16 | * Revision 1.2 1997/03/27 10:34:15 schmidt |
---|
17 | * stream-io wrapped by NOSTREAMIO |
---|
18 | * |
---|
19 | * Revision 1.1 1996/12/18 15:04:42 schmidt |
---|
20 | * Initial revision |
---|
21 | * |
---|
22 | */ |
---|
23 | |
---|
24 | #include <factoryconf.h> |
---|
25 | |
---|
26 | #ifndef NOSTREAMIO |
---|
27 | #include <iostream.h> |
---|
28 | #endif /* NOSTREAMIO */ |
---|
29 | |
---|
30 | template <class T> |
---|
31 | class SubMatrix; |
---|
32 | |
---|
33 | template <class T> |
---|
34 | class Matrix |
---|
35 | { |
---|
36 | private: |
---|
37 | int NR, NC; |
---|
38 | T ** elems; |
---|
39 | #ifndef NOSTREAMIO |
---|
40 | void printrow ( ostream & s, int i ) const; |
---|
41 | #endif /* NOSTREAMIO */ |
---|
42 | typedef T* T_ptr; |
---|
43 | public: |
---|
44 | Matrix() : NR(0), NC(0), elems(0) {} |
---|
45 | Matrix( int nr, int nc ); |
---|
46 | Matrix( const Matrix<T>& M ); |
---|
47 | ~Matrix(); |
---|
48 | Matrix<T>& operator= ( const Matrix<T>& M ); |
---|
49 | int rows() const { return NR; } |
---|
50 | int columns() const { return NC; } |
---|
51 | SubMatrix<T> operator[] ( int i ); |
---|
52 | const SubMatrix<T> operator[] ( int i ) const; |
---|
53 | T& operator() ( int row, int col ); |
---|
54 | T operator() ( int row, int col ) const; |
---|
55 | SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ); |
---|
56 | const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const; |
---|
57 | void swapRow( int i, int j ); |
---|
58 | void swapColumn( int i, int j ); |
---|
59 | friend Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
60 | friend Matrix<T> operator- ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
61 | friend Matrix<T> operator* ( const Matrix<T>& lhs, const Matrix<T>& rhs ); |
---|
62 | friend Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs ); |
---|
63 | friend Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs ); |
---|
64 | #ifndef NOSTREAMIO |
---|
65 | void print( ostream& s ) const; |
---|
66 | friend ostream & operator<< ( ostream & s, const Matrix<T>& M ) |
---|
67 | { |
---|
68 | M.print( s ); |
---|
69 | return s; |
---|
70 | } |
---|
71 | #endif /* NOSTREAMIO */ |
---|
72 | friend class SubMatrix<T>; |
---|
73 | }; |
---|
74 | |
---|
75 | template <class T> |
---|
76 | class SubMatrix |
---|
77 | { |
---|
78 | private: |
---|
79 | int r_min, r_max, c_min, c_max; |
---|
80 | Matrix<T>& M; |
---|
81 | // we do not provide a default ctor, so nobody can declare an empty SubMatrix |
---|
82 | SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m ); |
---|
83 | public: |
---|
84 | SubMatrix( const SubMatrix<T> & S ); |
---|
85 | SubMatrix<T>& operator= ( const SubMatrix<T>& S ); |
---|
86 | SubMatrix<T>& operator= ( const Matrix<T>& S ); |
---|
87 | operator Matrix<T>() const; |
---|
88 | T operator[] ( int i ) const; |
---|
89 | T& operator[] ( int i ); |
---|
90 | friend class Matrix<T>; |
---|
91 | }; |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | #endif /* INCL_MATRIX_H */ |
---|