| 1 | // This may look like C code, but it is really -*- C++ -*-
|
|---|
| 2 | // C.Magneville 05/99
|
|---|
| 3 | #ifndef TVector_SEEN
|
|---|
| 4 | #define TVector_SEEN
|
|---|
| 5 |
|
|---|
| 6 | #include "tmatrix.h"
|
|---|
| 7 |
|
|---|
| 8 | namespace SOPHYA {
|
|---|
| 9 |
|
|---|
| 10 | template <class T>
|
|---|
| 11 | class TVector : public TMatrix<T> {
|
|---|
| 12 | public:
|
|---|
| 13 | enum {SameTypeVector=0, ColumnVector=1, LineVector=2};
|
|---|
| 14 | // Creation / destruction
|
|---|
| 15 | TVector();
|
|---|
| 16 | TVector(uint_4 n, short lcv=ColumnVector, short mm=AutoMemoryMapping);
|
|---|
| 17 | TVector(const TVector<T>& v);
|
|---|
| 18 | TVector(const TVector<T>& v, bool share);
|
|---|
| 19 | TVector(const TArray<T>& a);
|
|---|
| 20 | TVector(const TArray<T>& a, bool share, short lcv=ColumnVector, short mm=CMemoryMapping);
|
|---|
| 21 |
|
|---|
| 22 | virtual ~TVector();
|
|---|
| 23 |
|
|---|
| 24 | inline TVector<T>& operator = (const TVector<T>& a)
|
|---|
| 25 | { Set(a); return(*this); }
|
|---|
| 26 |
|
|---|
| 27 | // Vector type Line or Column vector
|
|---|
| 28 | inline short GetVectorType() const
|
|---|
| 29 | { return((marowi_ == veceli_) ? ColumnVector : LineVector); }
|
|---|
| 30 |
|
|---|
| 31 | // Gestion taille/Remplissage
|
|---|
| 32 | void ReSize(uint_4 n, short lcv=SameTypeVector );
|
|---|
| 33 | void Realloc(uint_4 n, short lcv=SameTypeVector, bool force=false);
|
|---|
| 34 |
|
|---|
| 35 | // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
|---|
| 36 | TVector<T> operator () (Range relt) const ;
|
|---|
| 37 |
|
|---|
| 38 | // Informations pointeur/data
|
|---|
| 39 | inline uint_4 NElts() const {return Size(); }
|
|---|
| 40 |
|
|---|
| 41 | // Inline element acces methods
|
|---|
| 42 | inline T const& operator()(uint_4 n) const;
|
|---|
| 43 | inline T& operator()(uint_4 n);
|
|---|
| 44 |
|
|---|
| 45 | // Operations diverses avec une constante
|
|---|
| 46 | inline TVector<T>& operator = (T x) { Set(x); return(*this); }
|
|---|
| 47 | inline TVector<T>& operator += (T x) { Add(x); return(*this); }
|
|---|
| 48 | inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
|
|---|
| 49 | inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
|
|---|
| 50 | inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
|
|---|
| 51 |
|
|---|
| 52 | // operations avec matrices
|
|---|
| 53 | inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
|
|---|
| 54 | inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
|
|---|
| 55 |
|
|---|
| 56 | // Norme(^2)
|
|---|
| 57 | T Norm2() const ;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | // ---- inline acces methods ------
|
|---|
| 61 | template <class T>
|
|---|
| 62 | inline T const& TVector<T>::operator()(uint_4 n) const
|
|---|
| 63 | {
|
|---|
| 64 | #ifdef SO_BOUNDCHECKING
|
|---|
| 65 | if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
|---|
| 66 | else CheckBound(0, n, 0, 0, 0, 4);
|
|---|
| 67 | #endif
|
|---|
| 68 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | template <class T>
|
|---|
| 72 | inline T & TVector<T>::operator()(uint_4 n)
|
|---|
| 73 | {
|
|---|
| 74 | #ifdef SO_BOUNDCHECKING
|
|---|
| 75 | if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
|---|
| 76 | else CheckBound(0, n, 0, 0, 0, 4);
|
|---|
| 77 | #endif
|
|---|
| 78 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | // Typedef pour simplifier et compatibilite Peida
|
|---|
| 82 | typedef TVector<r_8> Vector;
|
|---|
| 83 |
|
|---|
| 84 | } // Fin du namespace
|
|---|
| 85 |
|
|---|
| 86 | #endif
|
|---|