All Classes Namespaces Functions Variables Typedefs Enumerations Pages
fixed_row_vector.h
1 /* Copyright (C) 2003-2005 Martin Förg
2 
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact:
18  * martin.o.foerg@googlemail.com
19  *
20  */
21 
22 #ifndef fixed_row_vector_h
23 #define fixed_row_vector_h
24 
25 #include "fixed_general_matrix.h"
26 #include <stdexcept>
27 
28 namespace fmatvec {
29 
38  template <int N, class AT> class RowVector<Fixed<N>,AT> : public Matrix<General,Fixed<1>,Fixed<N>,AT> {
39 
40  using Matrix<General,Fixed<1>,Fixed<N>,AT>::ele;
41 
42  public:
43 
44  typedef AT* iterator;
45  typedef const AT* const_iterator;
46 
47  typedef AT value_type;
48 
50 
51  protected:
52 
53  template<class Col> inline void deepCopy(const RowVector<Col,AT> &x);
54 
56 
57  public:
58 
59 // template<class Ini=All<AT> >
60 // RowVector(Ini ini=All<AT>()) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
61 // template<class Ini=All<AT> >
62 // RowVector(int n, Ini ini=All<AT>()) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
63 
65  RowVector(Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini,a) { }
66  RowVector(int n, Noinit ini) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini) { }
67  RowVector(int n, Init ini=INIT, const AT &a=0) : Matrix<General,Fixed<1>,Fixed<N>,AT>(ini,a) { }
68 
81  RowVector(const char *str) : Matrix<General,Fixed<1>,Fixed<N>,AT>(str) {
82  }
83 
88  template<class Col>
89  RowVector(const RowVector<Col,AT> &A) : Matrix<General,Fixed<1>,Fixed<N>,AT>(A) {
90  }
91 
96  template<class Type, class Row, class Col>
97  explicit RowVector(const Matrix<Type,Row,Col,AT> &A) : Matrix<General,Fixed<1>,Fixed<N>,AT>(A) {
98  }
99 
110  AT& operator()(int i) {
111 #ifndef FMATVEC_NO_BOUNDS_CHECK
112  assert(i>=0);
113  assert(i<N);
114 #endif
115  return e(i);
116  };
117 
122  const AT& operator()(int i) const {
123 #ifndef FMATVEC_NO_BOUNDS_CHECK
124  assert(i>=0);
125  assert(i<N);
126 #endif
127  return e(i);
128  };
129 
130  iterator begin() { return &ele[0][0]; }
131  iterator end() { return &ele[0][N]; }
132  const_iterator begin() const { return &ele[0][0]; }
133  const_iterator end() const { return &ele[0][N]; }
134  const_iterator cbegin() const noexcept { return &ele[0][0]; }
135  const_iterator cend() const noexcept { return &ele[0][N]; }
136 
137  AT& e(int i) {
138  return ele[0][i];
139  };
140 
145  const AT& e(int i) const {
146  return ele[0][i];
147  };
148 
156  inline RowVector<Fixed<N>,AT>& init(const AT &val=0);
157  inline RowVector<Fixed<N>,AT>& init(Init, const AT &a=0) { return init(a); }
158  inline RowVector<Fixed<N>,AT>& init(Noinit, const AT &a=0) { return *this; }
159 
164  int size() const {return N;};
165 
168  void resize(int n) {
169  if(n!=N)
170  throw std::runtime_error("A fixed row vector cannot be resized.");
171  }
172 
179  int inc() const {return 1;};
180 
181  using Matrix<General,Fixed<1>,Fixed<N>,AT>::operator();
182 
183  inline const Vector<Fixed<N>,AT> T() const;
184  };
185 
186  template <int N, class AT>
187  inline RowVector<Fixed<N>,AT>& RowVector<Fixed<N>,AT>::init(const AT &val) {
188  for(int i=0; i<N; i++)
189  e(i) = val;
190  return *this;
191  }
192 
193  template <int N, class AT>
194  inline const Vector<Fixed<N>,AT> RowVector<Fixed<N>,AT>::T() const {
195  Vector<Fixed<N>,AT> x(NONINIT);
196  for(int i=0; i<N; i++)
197  x.e(i) = e(i);
198  return x;
199  }
200 
202 
203  template <int N, class AT> template <class Col>
204  inline void RowVector<Fixed<N>,AT>::deepCopy(const RowVector<Col,AT> &x) {
205  for(int i=0; i<N; i++)
206  e(i) = x.e(i);
207  }
208 
210 
211 }
212 #endif
Definition: fmatvec.h:38
This is the basic matrix class for arbitrary matrices.
Definition: fmatvec.h:41
Definition: matrix.h:43
Definition: fmatvec.h:50
RowVector(const RowVector< Col, AT > &A)
Copy Constructor.
Definition: fixed_row_vector.h:89
Definition: fmatvec.h:47
int size() const
Size.
Definition: fixed_row_vector.h:164
RowVector(const Matrix< Type, Row, Col, AT > &A)
Copy Constructor.
Definition: fixed_row_vector.h:97
void resize(int n)
Definition: fixed_row_vector.h:168
Definition: matrix.h:42
int inc() const
Increment.
Definition: fixed_row_vector.h:179
Basic shape class for matrices.
Definition: types.h:100
AT & operator()(int i)
Element operator.
Definition: fixed_row_vector.h:110
const AT & operator()(int i) const
Element operator.
Definition: fixed_row_vector.h:122
const AT & e(int i) const
Element operator.
Definition: fixed_row_vector.h:145
RowVector(const char *str)
String Constructor.
Definition: fixed_row_vector.h:81

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Home