Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tvector.h
Go to the documentation of this file.
1 /*
2  * tvector.h - simple vector 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$
22  *
23  */
24 
25 #ifndef __TVECTOR_H__
26 #define __TVECTOR_H__
27 
28 #include <assert.h>
29 #include "precision.h"
30 
31 namespace qucs {
32 
33 template <class nr_type_t>
34 class tvector;
35 
36 // Forward declarations of friend functions.
37 template <class nr_type_t>
39 template <class nr_type_t>
40 nr_double_t maxnorm (tvector<nr_type_t>);
41 template <class nr_type_t>
42 nr_double_t norm (tvector<nr_type_t>);
43 template <class nr_type_t>
44 nr_type_t sum (tvector<nr_type_t>);
45 template <class nr_type_t>
47 template <class nr_type_t>
49 template <class nr_type_t>
51 template <class nr_type_t>
53 template <class nr_type_t>
55 template <class nr_type_t>
57 template <class nr_type_t>
59 template <class nr_type_t>
61 template <class nr_type_t>
63 template <class nr_type_t>
64 bool operator < (tvector<nr_type_t>, tvector<nr_type_t>);
65 template <class nr_type_t>
67 
68 template <class nr_type_t>
69 class tvector
70 {
71  public:
72  tvector ();
73  tvector (int);
74  tvector (const tvector &);
75  const tvector& operator = (const tvector &);
76  ~tvector ();
77  nr_type_t get (int);
78  void set (int, nr_type_t);
79  void set (nr_type_t);
80  void set (nr_type_t, int, int);
81  void set (tvector, int, int);
82  int getSize (void) { return size; }
83  nr_type_t * getData (void) { return data; }
84  void setData (nr_type_t *, int);
85  void add (nr_type_t);
86  void clear (void);
87  void drop (int);
88  void truncate (int);
89  void exchangeRows (int, int);
90  int isFinite (void);
91  void print (void);
92  void reorder (int *);
93  int contains (nr_type_t, nr_double_t eps = NR_EPSI);
94 
95  // some basic vector operations
96 #ifndef _MSC_VER
97  friend tvector operator +<> (tvector, tvector);
98  friend tvector operator -<> (tvector, tvector);
99  friend tvector operator *<> (tvector, nr_double_t);
100  friend tvector operator *<> (nr_double_t, tvector);
101  friend tvector operator *<> (tvector, tvector);
102  friend tvector operator -<> (tvector);
103  friend tvector operator +<> (tvector, nr_type_t);
104  friend tvector operator +<> (nr_type_t, tvector);
105 #endif
106 
107  // other operations
108 #ifndef _MSC_VER
109  friend nr_double_t norm<> (tvector);
110  friend nr_double_t maxnorm<> (tvector);
111  friend nr_type_t sum<> (tvector);
112  friend nr_type_t scalar<> (tvector, tvector);
113  friend tvector conj<> (tvector);
114 #endif
115 
116  // comparisons
117 #ifndef _MSC_VER
118  friend bool operator < <> (tvector, tvector);
119  friend bool operator > <> (tvector, tvector);
120 #endif
121 
122  // intrinsic operators
125  tvector operator *= (nr_double_t);
126  tvector operator /= (nr_double_t);
127 
128  // assignment operators
129  tvector operator = (const nr_type_t);
130 
131  // easy accessor operators
132  nr_type_t operator () (int i) const {
133  assert (i >= 0 && i < size); return data[i]; }
134  nr_type_t& operator () (int i) {
135  assert (i >= 0 && i < size); return data[i]; }
136 
137  private:
138  int external;
139  int size;
140  int capacity;
141  nr_type_t * data;
142 };
143 
144 } // namespace qucs
145 
146 #include "tvector.cpp"
147 
148 #endif /* __TVECTOR_H__ */
void truncate(int)
Definition: tvector.cpp:155
int isFinite(void)
Definition: tvector.cpp:407
void setData(nr_type_t *, int)
Definition: tvector.cpp:185
tvector operator-=(tvector)
Definition: tvector.cpp:233
void set(int, nr_type_t)
Definition: tvector.cpp:108
nr_type_t scalar(tvector< nr_type_t > a, tvector< nr_type_t > b)
Definition: tvector.cpp:283
matrix operator*(matrix a, nr_complex_t z)
Matrix scaling complex version.
Definition: matrix.cpp:298
nr_complex_t sum(vector)
Definition: vector.cpp:251
tvector operator*=(nr_double_t)
Definition: tvector.cpp:243
void exchangeRows(int, int)
Definition: tvector.cpp:194
bool operator>(const nr_complex_t z1, const nr_complex_t z2)
Superior.
Definition: complex.cpp:889
nr_double_t maxnorm(tvector< nr_type_t > a)
Definition: tvector.cpp:387
i
Definition: parse_mdl.y:516
matrix operator-(matrix a, matrix b)
Matrix subtraction.
Definition: matrix.cpp:259
void add(nr_type_t)
Definition: tvector.cpp:127
tvector operator+=(tvector)
Definition: tvector.cpp:213
void drop(int)
Definition: tvector.cpp:145
const tvector & operator=(const tvector &)
Definition: tvector.cpp:79
matrix operator+(matrix a, matrix b)
Matrix addition.
Definition: matrix.cpp:228
nr_type_t * data
Definition: tvector.h:141
nr_type_t operator()(int i) const
Definition: tvector.h:132
tvector operator/=(nr_double_t)
Definition: tvector.cpp:251
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
Definition: complex.cpp:283
List int
Definition: parse_citi.y:183
void print(void)
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
void clear(void)
Definition: tvector.cpp:164
int getSize(void)
Definition: tvector.h:82
int external
Definition: tvector.h:138
void reorder(int *)
Definition: tvector.cpp:415
int capacity
Definition: tvector.h:140
int contains(nr_type_t, nr_double_t eps=NR_EPSI)
Definition: tvector.cpp:171
nr_type_t * getData(void)
Definition: tvector.h:83