00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 namespace TooN {
00034
00035
00127 template<int Size=Dynamic, typename Precision=DefaultPrecision, typename Base=Internal::VBase>
00128 struct Vector : public Base::template VLayout<Size, Precision> {
00129 protected:
00130 public:
00131 typedef typename Base::template VLayout<Size, Precision>::PointerType PointerType;
00132
00133
00134
00135
00137
00138
00144 inline Vector(){}
00145
00149 explicit inline Vector(int size_in) : Base::template VLayout<Size, Precision>(size_in) {}
00150
00157 explicit inline Vector(PointerType data) : Base::template VLayout<Size, Precision> (data) {}
00158
00159
00166 inline Vector(PointerType data, int size_in) : Base::template VLayout<Size, Precision> (data, size_in) {}
00167
00169 inline Vector(PointerType data_in, int size_in, int stride_in, Internal::Slicing)
00170 : Base::template VLayout<Size, Precision>(data_in, size_in, stride_in) {}
00171
00172 using Base::template VLayout<Size, Precision>::size;
00173
00179 template <class Op>
00180 inline Vector(const Operator<Op>& op)
00181 : Base::template VLayout<Size, Precision> (op)
00182 {
00183 op.eval(*this);
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00196 template<int Size2, typename Precision2, typename Base2>
00197 inline Vector(const Vector<Size2,Precision2,Base2>& from):
00198 Base::template VLayout<Size, Precision>(from.size()) {
00199 operator=(from);
00200 }
00201
00203
00204 #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
00205
00208
00219 Precision& operator[] (int i);
00220
00224 const Precision& operator[] (int i) const;
00225
00227
00228 #endif
00229
00232
00236 inline Vector& operator= (const Vector& from){
00237 try_destructive_resize(from.size());
00238 SizeMismatch<Size,Size>::test(size(), from.size());
00239 const int s=size();
00240 for(int i=0; i<s; i++){
00241 (*this)[i]=from[i];
00242 }
00243 return *this;
00244 }
00245
00249 template<int Size2, typename Precision2, typename Base2>
00250 Vector<Size,Precision,Base >& operator= (const Vector<Size2, Precision2, Base2>& from){
00251 try_destructive_resize(from.size());
00252 SizeMismatch<Size,Size2>::test(size(), from.size());
00253 const int s=size();
00254 for(int i=0; i<s; i++){
00255 (*this)[i]=from[i];
00256 }
00257 return *this;
00258 }
00259
00264 template <class Op>
00265 inline Vector & operator=(const Operator<Op>& op){
00266 try_destructive_resize(op);
00267 op.eval(*this);
00268 return *this;
00269 }
00271
00274
00276 Vector& operator/=(const Precision& rhs) {
00277 for(int i=0; i<size(); i++)
00278 (*this)[i]/=rhs;
00279 return *this;
00280 }
00281
00283 Vector& operator*=(const Precision& rhs) {
00284 for(int i=0; i<size(); i++)
00285 (*this)[i]*=rhs;
00286 return *this;
00287 }
00288
00290 template<int Size2, class Precision2, class Base2>
00291 Vector& operator+=(const Vector<Size2, Precision2, Base2>& rhs) {
00292 SizeMismatch<Size,Size2>::test(size(),rhs.size());
00293 for(int i=0; i<size(); i++)
00294 (*this)[i]+=rhs[i];
00295 return *this;
00296 }
00297
00305 template<class Op>
00306 Vector& operator+=(const Operator<Op>& op)
00307 {
00308 op.plusequals(*this);
00309 return *this;
00310 }
00311
00312 template<class Op>
00313 Vector& operator-=(const Operator<Op>& op)
00314 {
00315 op.minusequals(*this);
00316 return *this;
00317 }
00318
00320 template<int Size2, class Precision2, class Base2>
00321 Vector& operator-=(const Vector<Size2, Precision2, Base2>& rhs) {
00322 SizeMismatch<Size,Size2>::test(size(),rhs.size());
00323 for(int i=0; i<size(); i++)
00324 (*this)[i]-=rhs[i];
00325 return *this;
00326 }
00327
00329
00332
00334 template<int Size2, class Precision2, class Base2>
00335 bool operator==(const Vector<Size2, Precision2, Base2>& rhs) {
00336 SizeMismatch<Size,Size2>::test(size(),rhs.size());
00337 for(int i=0; i<size(); i++)
00338 if((*this)[i]!=rhs[i])
00339 return 0;
00340 return 1;
00341 }
00342
00344 template<int Size2, class Precision2, class Base2>
00345 bool operator!=(const Vector<Size2, Precision2, Base2>& rhs) {
00346 SizeMismatch<Size,Size2>::test(size(),rhs.size());
00347 for(int i=0; i<size(); i++)
00348 if((*this)[i]!=rhs[i])
00349 return 1;
00350 return 0;
00351 }
00352
00354
00357
00359 Vector& ref()
00360 {
00361 return *this;
00362 }
00363
00364 #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
00365
00367 int size() const;
00368
00377 void resize(int s);
00378
00385 Precision* get_data_ptr();
00386
00387
00388
00390
00392
00393
00403 Matrix<1, Size, Precision> as_row();
00404
00415 Matrix<Size, 1, Precision> as_col();
00416
00428 DiagonalMatrix<Size,Precision> as_diagonal();
00429
00441 template<Start, Length>
00442 const Vector<Length,Precision>& slice() const;
00443
00457 template<Start, Length>
00458 Vector<Length,Precision>& slice();
00459
00472 template<Start, Length>
00473 const Vector<Length,Precision>& slice() const;
00474
00488 template<Start, Length>
00489 Vector<Length,Precision>& slice();
00491
00492 #endif
00493
00494 };
00495
00496 }