1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id$ */ |
---|
3 | |
---|
4 | #ifndef INCL_MATRIX_H |
---|
5 | #define INCL_MATRIX_H |
---|
6 | |
---|
7 | #include <factory/factoryconf.h> |
---|
8 | |
---|
9 | #ifndef NOSTREAMIO |
---|
10 | #ifdef HAVE_IOSTREAM |
---|
11 | #include <iostream> |
---|
12 | #define OSTREAM std::ostream |
---|
13 | #elif defined(HAVE_IOSTREAM_H) |
---|
14 | #include <iostream.h> |
---|
15 | #define OSTREAM ostream |
---|
16 | #endif |
---|
17 | #endif /* NOSTREAMIO */ |
---|
18 | |
---|
19 | template <class T> |
---|
20 | class SubMatrix; |
---|
21 | |
---|
22 | template <class T> |
---|
23 | class Matrix; |
---|
24 | |
---|
25 | #ifndef NOSTREAMIO |
---|
26 | template <class T> |
---|
27 | OSTREAM& operator<< (OSTREAM &, const Matrix<T> &); |
---|
28 | #endif |
---|
29 | |
---|
30 | template <class T> |
---|
31 | class Matrix |
---|
32 | { |
---|
33 | private: |
---|
34 | int NR, NC; |
---|
35 | T ** elems; |
---|
36 | #ifndef NOSTREAMIO |
---|
37 | void printrow ( OSTREAM & s, int i ) const; |
---|
38 | #endif /* NOSTREAMIO */ |
---|
39 | typedef T* T_ptr; |
---|
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 ); |
---|
56 | #ifndef NOSTREAMIO |
---|
57 | void print( OSTREAM& s ) const; |
---|
58 | friend OSTREAM & operator<< <T>( OSTREAM & s, const Matrix<T>& M ); |
---|
59 | #endif /* NOSTREAMIO */ |
---|
60 | friend class SubMatrix<T>; |
---|
61 | }; |
---|
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 ); |
---|
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 | |
---|
91 | #ifndef NOSTREAMIO |
---|
92 | template <class T> |
---|
93 | OSTREAM & operator<< ( OSTREAM & s, const Matrix<T>& M ); |
---|
94 | #endif /* NOSTREAMIO */ |
---|
95 | |
---|
96 | #endif /* ! INCL_MATRIX_H */ |
---|