source: git/factory/include/factory/templates/ftmpl_matrix.h

spielwiese
Last change on this file was 3edea1, checked in by Hans Schoenemann <hannes@…>, 3 years ago
cygwin port: shared lib libfactory
  • 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
[175e355]6#ifndef NOSTREAMIO
[1dc616]7#ifdef HAVE_IOSTREAM
8#include <iostream>
[181148]9#define OSTREAM std::ostream
[1dc616]10#elif defined(HAVE_IOSTREAM_H)
[c5f2101]11#include <iostream.h>
[181148]12#define OSTREAM ostream
[1dc616]13#endif
[175e355]14#endif /* NOSTREAMIO */
[c5f2101]15
16template <class T>
17class SubMatrix;
18
[22347b6]19template <class T>
20class Matrix;
21
22#ifndef NOSTREAMIO
23template <class T>
[181148]24OSTREAM& operator<< (OSTREAM &, const Matrix<T> &);
[22347b6]25#endif
26
[c5f2101]27template <class T>
[3edea1]28class FACTORY_PUBLIC Matrix
[c5f2101]29{
30private:
31    int NR, NC;
32    T ** elems;
[175e355]33#ifndef NOSTREAMIO
[181148]34    void printrow ( OSTREAM & s, int i ) const;
[175e355]35#endif /* NOSTREAMIO */
[8840725]36    typedef T* T_ptr;
[c5f2101]37public:
38    Matrix() : NR(0), NC(0), elems(0) {}
39    Matrix( int nr, int nc );
40    Matrix( const Matrix<T>& M );
41    ~Matrix();
42    Matrix<T>& operator= ( const Matrix<T>& M );
43    int rows() const { return NR; }
44    int columns() const { return NC; }
45    SubMatrix<T> operator[] ( int i );
46    const SubMatrix<T> operator[] ( int i ) const;
47    T& operator() ( int row, int col );
48    T operator() ( int row, int col ) const;
49    SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax );
50    const SubMatrix<T> operator() ( int rmin, int rmax, int cmin, int cmax ) const;
51    void swapRow( int i, int j );
52    void swapColumn( int i, int j );
[175e355]53#ifndef NOSTREAMIO
[181148]54    void print( OSTREAM& s ) const;
55    friend OSTREAM & operator<< <T>( OSTREAM & s, const Matrix<T>& M );
[175e355]56#endif /* NOSTREAMIO */
[c5f2101]57    friend class SubMatrix<T>;
58};
[ccda50]59    /*template <class T>
[2457a8]60    Matrix<T> operator+ ( const Matrix<T>& lhs, const Matrix<T>& rhs );
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 T& rhs );
67    template <class T>
[ccda50]68    Matrix<T> operator* ( const T& lhs, const Matrix<T>& rhs );*/
[c5f2101]69
70template <class T>
71class SubMatrix
72{
73private:
74    int r_min, r_max, c_min, c_max;
75    Matrix<T>& M;
76    // we do not provide a default ctor, so nobody can declare an empty SubMatrix
77    SubMatrix( int rmin, int rmax, int cmin, int cmax, const Matrix<T> & m );
78public:
79    SubMatrix( const SubMatrix<T> & S );
80    SubMatrix<T>& operator= ( const SubMatrix<T>& S );
81    SubMatrix<T>& operator= ( const Matrix<T>& S );
82    operator Matrix<T>() const;
83    T operator[] ( int i ) const;
84    T& operator[] ( int i );
85    friend class Matrix<T>;
86};
87
[5bb462]88#ifndef NOSTREAMIO
89template <class T>
[181148]90OSTREAM & operator<< ( OSTREAM & s, const Matrix<T>& M );
[5bb462]91#endif /* NOSTREAMIO */
92
[6ab5981]93#endif /* ! INCL_MATRIX_H */
Note: See TracBrowser for help on using the repository browser.