source: git/factory/include/factory/templates/ftmpl_matrix.h @ 4e654a2

spielwiese
Last change on this file since 4e654a2 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 2.6 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2
3#ifndef INCL_MATRIX_H
4#define INCL_MATRIX_H
5
6// #include <factory/factoryconf.h>
7
8#ifndef NOSTREAMIO
9#ifdef HAVE_IOSTREAM
10#include <iostream>
11#define OSTREAM std::ostream
12#elif defined(HAVE_IOSTREAM_H)
13#include <iostream.h>
14#define OSTREAM ostream
15#endif
16#endif /* NOSTREAMIO */
17
18template <class T>
19class SubMatrix;
20
21template <class T>
22class Matrix;
23
24#ifndef NOSTREAMIO
25template <class T>
26OSTREAM& operator<< (OSTREAM &, const Matrix<T> &);
27#endif
28
29template <class T>
30class Matrix
31{
32private:
33    int NR, NC;
34    T ** elems;
35#ifndef NOSTREAMIO
36    void printrow ( OSTREAM & s, int i ) const;
37#endif /* NOSTREAMIO */
38    typedef T* T_ptr;
39public:
40    Matrix() : NR(0), NC(0), elems(0) {}
41    Matrix( int nr, int nc );
42    Matrix( const Matrix<T>& M );
43    ~Matrix();
44    Matrix<T>& operator= ( const Matrix<T>& M );
45    int rows() const { return NR; }
46    int columns() const { return NC; }
47    SubMatrix<T> operator[] ( int i );
48    const SubMatrix<T> operator[] ( int i ) const;
49    T& operator() ( int row, int col );
50    T operator() ( int row, int col ) const;
51    SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax );
52    const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const;
53    void swapRow( int i, int j );
54    void swapColumn( int i, int j );
55#ifndef NOSTREAMIO
56    void print( OSTREAM& s ) const;
57    friend OSTREAM & operator<< <T>( OSTREAM & s, const Matrix<T>& M );
58#endif /* NOSTREAMIO */
59    friend class SubMatrix<T>;
60};
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 Matrix<T>& rhs );
67    template <class T>
68    Matrix<T> operator* ( const Matrix<T>& lhs, const T& rhs );
69    template <class T>
70    Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs );
71
72template <class T>
73class SubMatrix
74{
75private:
76    int r_min, r_max, c_min, c_max;
77    Matrix<T>& M;
78    // we do not provide a default ctor, so nobody can declare an empty SubMatrix
79    SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m );
80public:
81    SubMatrix( const SubMatrix<T> & S );
82    SubMatrix<T>& operator= ( const SubMatrix<T>& S );
83    SubMatrix<T>& operator= ( const Matrix<T>& S );
84    operator Matrix<T>() const;
85    T operator[] ( int i ) const;
86    T& operator[] ( int i );
87    friend class Matrix<T>;
88};
89
90#ifndef NOSTREAMIO
91template <class T>
92OSTREAM & operator<< ( OSTREAM & s, const Matrix<T>& M );
93#endif /* NOSTREAMIO */
94
95#endif /* ! INCL_MATRIX_H */
Note: See TracBrowser for help on using the repository browser.