My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: tvector.h 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #ifndef __TVECTOR_H__
26 #define __TVECTOR_H__
27 
28 #include <assert.h>
29 #include "precision.h"
30 
31 template <class nr_type_t>
32 class tvector;
33 
34 // Forward declarations of friend functions.
35 template <class nr_type_t>
37 template <class nr_type_t>
38 nr_double_t maxnorm (tvector<nr_type_t>);
39 template <class nr_type_t>
40 nr_double_t norm (tvector<nr_type_t>);
41 template <class nr_type_t>
42 nr_type_t sum (tvector<nr_type_t>);
43 template <class 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>
62 bool operator < (tvector<nr_type_t>, tvector<nr_type_t>);
63 template <class nr_type_t>
65 
66 template <class nr_type_t>
67 class tvector
68 {
69  public:
70  tvector ();
71  tvector (int);
72  tvector (const tvector &);
73  const tvector& operator = (const tvector &);
74  ~tvector ();
75  nr_type_t get (int);
76  void set (int, nr_type_t);
77  void set (nr_type_t);
78  void set (nr_type_t, int, int);
79  void set (tvector, int, int);
80  int getSize (void) { return size; }
81  nr_type_t * getData (void) { return data; }
82  void setData (nr_type_t *, int);
83  void add (nr_type_t);
84  void clear (void);
85  void drop (int);
86  void exchangeRows (int, int);
87  int isFinite (void);
88  void print (void);
89  void reorder (int *);
90  int contains (nr_type_t, nr_double_t eps = NR_EPSI);
91 
92  // some basic vector operations
93 #ifndef _MSC_VER
94  friend tvector operator +<> (tvector, tvector);
95  friend tvector operator -<> (tvector, tvector);
96  friend tvector operator *<> (tvector, nr_double_t);
97  friend tvector operator *<> (nr_double_t, tvector);
98  friend tvector operator *<> (tvector, tvector);
99  friend tvector operator -<> (tvector);
100  friend tvector operator +<> (tvector, nr_type_t);
101  friend tvector operator +<> (nr_type_t, tvector);
102 #endif
103 
104  // other operations
105 #ifndef _MSC_VER
106  friend nr_double_t norm<> (tvector);
107  friend nr_double_t maxnorm<> (tvector);
108  friend nr_type_t sum<> (tvector);
109  friend nr_type_t scalar<> (tvector, tvector);
110  friend tvector conj<> (tvector);
111 #endif
112 
113  // comparisons
114 #ifndef _MSC_VER
115  friend bool operator < <> (tvector, tvector);
116  friend bool operator > <> (tvector, tvector);
117 #endif
118 
119  // intrinsic operators
122  tvector operator *= (nr_double_t);
123  tvector operator /= (nr_double_t);
124 
125  // assignment operators
126  tvector operator = (const nr_type_t);
127 
128  // easy accessor operators
129  nr_type_t operator () (int i) const {
130  assert (i >= 0 && i < size); return data[i]; }
131  nr_type_t& operator () (int i) {
132  assert (i >= 0 && i < size); return data[i]; }
133 
134  private:
135  int external;
136  int size;
137  int capacity;
138  nr_type_t * data;
139 };
140 
141 #include "tvector.cpp"
142 
143 #endif /* __TVECTOR_H__ */