source: git/factory/include/factory/templates/ftmpl_matrix.h @ 0df59c8

spielwiese
Last change on this file since 0df59c8 was 362fc67, checked in by Martin Lee <martinlee84@…>, 12 years ago
chg: remove $Id$
  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[6ab5981]1/* emacs edit mode for this file is -*- C++ -*- */
[c5f2101]2
3#ifndef INCL_MATRIX_H
4#define INCL_MATRIX_H
5
[e4fe2b]6// #include <factory/factoryconf.h>
[8c0163]7
[175e355]8#ifndef NOSTREAMIO
[1dc616]9#ifdef HAVE_IOSTREAM
10#include <iostream>
[181148]11#define OSTREAM std::ostream
[1dc616]12#elif defined(HAVE_IOSTREAM_H)
[c5f2101]13#include <iostream.h>
[181148]14#define OSTREAM ostream
[1dc616]15#endif
[175e355]16#endif /* NOSTREAMIO */
[c5f2101]17
18template <class T>
19class SubMatrix;
20
[22347b6]21template <class T>
22class Matrix;
23
24#ifndef NOSTREAMIO
25template <class T>
[181148]26OSTREAM& operator<< (OSTREAM &, const Matrix<T> &);
[22347b6]27#endif
28
[c5f2101]29template <class T>
30class Matrix
31{
32private:
33    int NR, NC;
34    T ** elems;
[175e355]35#ifndef NOSTREAMIO
[181148]36    void printrow ( OSTREAM & s, int i ) const;
[175e355]37#endif /* NOSTREAMIO */
[8840725]38    typedef T* T_ptr;
[c5f2101]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 );
[175e355]55#ifndef NOSTREAMIO
[181148]56    void print( OSTREAM& s ) const;
57    friend OSTREAM & operator<< <T>( OSTREAM & s, const Matrix<T>& M );
[175e355]58#endif /* NOSTREAMIO */
[c5f2101]59    friend class SubMatrix<T>;
60};
[2457a8]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 );
[c5f2101]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
[5bb462]90#ifndef NOSTREAMIO
91template <class T>
[181148]92OSTREAM & operator<< ( OSTREAM & s, const Matrix<T>& M );
[5bb462]93#endif /* NOSTREAMIO */
94
[6ab5981]95#endif /* ! INCL_MATRIX_H */
Note: See TracBrowser for help on using the repository browser.