My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tmatrix.h
Go to the documentation of this file.
1 /*
2  * tmatrix.h - simple matrix template class definitions
3  *
4  * Copyright (C) 2004, 2005, 2006 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: tmatrix.h 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #ifndef __TMATRIX_H__
26 #define __TMATRIX_H__
27 
28 #include <assert.h>
29 
30 template <class nr_type_t>
31 class tmatrix;
32 
33 // Forward declarations of friend functions.
34 template <class nr_type_t>
36 template <class nr_type_t>
38 template <class nr_type_t>
40 template <class nr_type_t>
42 template <class nr_type_t>
44 
45 template <class nr_type_t>
46 class tmatrix
47 {
48  public:
49  tmatrix ();
50  tmatrix (int);
51  tmatrix (int, int);
52  tmatrix (const tmatrix &);
53  const tmatrix& operator = (const tmatrix &);
54  ~tmatrix ();
55  nr_type_t get (int, int);
56  void set (int, int, nr_type_t);
57  void set (nr_type_t);
58  int getCols (void) { return cols; }
59  int getRows (void) { return rows; }
60  nr_type_t * getData (void) { return data; }
62  void setRow (int, tvector<nr_type_t>);
64  void setCol (int, tvector<nr_type_t>);
65  void exchangeRows (int, int);
66  void exchangeCols (int, int);
67  void transpose (void);
68  int isFinite (void);
69  void print (bool realonly = false);
70 
71  // some basic matrix operations
72 #ifndef _MSC_VER
73  friend tmatrix inverse<> (tmatrix);
74  friend tmatrix teye<nr_type_t> (int);
75  friend tmatrix operator *<> (tmatrix, tmatrix);
76  friend tvector<nr_type_t> operator *<> (tmatrix, tvector<nr_type_t>);
77  friend tvector<nr_type_t> operator *<> (tvector<nr_type_t>, tmatrix);
78 #endif
79 
80  // intrinsic operators
83 
84  // easy accessor operators
85  nr_type_t operator () (int r, int c) const {
86  assert (r >= 0 && r < rows && c >= 0 && c < cols);
87  return data[r * cols + c]; }
88  nr_type_t& operator () (int r, int c) {
89  assert (r >= 0 && r < rows && c >= 0 && c < cols);
90  return data[r * cols + c]; }
91 
92  private:
93  int cols;
94  int rows;
95  nr_type_t * data;
96 };
97 
98 #include "tmatrix.cpp"
99 
100 #endif /* __TMATRIX_H__ */