| 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 | //! Class of vector (line or column) | 
|---|
| 11 | template <class T> | 
|---|
| 12 | class TVector : public TMatrix<T> { | 
|---|
| 13 | public: | 
|---|
| 14 | // Creation / destruction | 
|---|
| 15 | TVector(); | 
|---|
| 16 | TVector(uint_4 n, short lcv=AutoVectorType, 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=AutoVectorType, short mm=AutoMemoryMapping); | 
|---|
| 21 |  | 
|---|
| 22 | virtual ~TVector(); | 
|---|
| 23 |  | 
|---|
| 24 | //! Operator = | 
|---|
| 25 | /*! \sa NDataBlock::operator=(const NDataBlock<T>&) */ | 
|---|
| 26 | inline  TVector<T>& operator = (const TVector<T>& a) | 
|---|
| 27 | { Set(a);  return(*this); } | 
|---|
| 28 |  | 
|---|
| 29 | // Gestion taille/Remplissage | 
|---|
| 30 | void ReSize(uint_4 n, short lcv=SameVectorType ); | 
|---|
| 31 | void Realloc(uint_4 n, short lcv=SameVectorType, bool force=false); | 
|---|
| 32 |  | 
|---|
| 33 | // Sub-Vector extraction $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ? | 
|---|
| 34 | TVector<T> SubVector(Range relt) const ; | 
|---|
| 35 | //! Extract a vector define by Range \b relt | 
|---|
| 36 | inline TVector<T> operator () (Range relt) const | 
|---|
| 37 | { return SubVector(relt); } | 
|---|
| 38 |  | 
|---|
| 39 | // Informations pointeur/data | 
|---|
| 40 | //! return the number of elements | 
|---|
| 41 | inline uint_4 NElts() const {return Size(); } | 
|---|
| 42 |  | 
|---|
| 43 | // Inline element acces methods | 
|---|
| 44 | inline T const& operator()(uint_4 n) const; | 
|---|
| 45 | inline T&       operator()(uint_4 n); | 
|---|
| 46 |  | 
|---|
| 47 | // Operateur d'affectation | 
|---|
| 48 | //! Fill the vector with Sequence \b seq | 
|---|
| 49 | inline  TVector<T>&  operator = (Sequence seq) { SetSeq(seq); return(*this); } | 
|---|
| 50 |  | 
|---|
| 51 | // Operations diverses  avec une constante | 
|---|
| 52 | //! Set vector elements to constant value \b x | 
|---|
| 53 | inline  TVector<T>&  operator = (T x)             { SetT(x); return(*this); } | 
|---|
| 54 | //! Add constant value \b x to vector elements | 
|---|
| 55 | inline  TVector<T>&  operator += (T x)            { Add(x); return(*this); } | 
|---|
| 56 | //! Substract constant value \b x to vector elements | 
|---|
| 57 | inline  TVector<T>&  operator -= (T x)            { Sub(x); return(*this); } | 
|---|
| 58 | //! Multiply vector elements by constant value \b x | 
|---|
| 59 | inline  TVector<T>&  operator *= (T x)            { Mul(x); return(*this); } | 
|---|
| 60 | //! Divide vector elements by constant value \b x | 
|---|
| 61 | inline  TVector<T>&  operator /= (T x)            { Div(x); return(*this); } | 
|---|
| 62 |  | 
|---|
| 63 | //  operations avec matrices | 
|---|
| 64 | //! += : add a vector in place | 
|---|
| 65 | inline  TVector<T>&  operator += (const TVector<T>& a)  { AddElt(a); return(*this); } | 
|---|
| 66 | //! += : substract a vector in place | 
|---|
| 67 | inline  TVector<T>&  operator -= (const TVector<T>& a)  { SubElt(a); return(*this); } | 
|---|
| 68 |  | 
|---|
| 69 | // Norme(^2) | 
|---|
| 70 | T Norm2() const ; | 
|---|
| 71 |  | 
|---|
| 72 | virtual string InfoString() const; | 
|---|
| 73 |  | 
|---|
| 74 | }; | 
|---|
| 75 |  | 
|---|
| 76 | //  ---- inline acces methods ------ | 
|---|
| 77 |  | 
|---|
| 78 | //! Return the value of element \b n | 
|---|
| 79 | template <class T> | 
|---|
| 80 | inline T const& TVector<T>::operator()(uint_4 n) const | 
|---|
| 81 | { | 
|---|
| 82 | #ifdef SO_BOUNDCHECKING | 
|---|
| 83 | if (veceli__ == 0)   CheckBound(n, 0, 0, 0, 0, 4); | 
|---|
| 84 | else   CheckBound(0, n, 0, 0, 0, 4); | 
|---|
| 85 | #endif | 
|---|
| 86 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | //! Return the value of element \b n | 
|---|
| 90 | template <class T> | 
|---|
| 91 | inline T & TVector<T>::operator()(uint_4 n) | 
|---|
| 92 | { | 
|---|
| 93 | #ifdef SO_BOUNDCHECKING | 
|---|
| 94 | if (veceli__ == 0)   CheckBound(n, 0, 0, 0, 0, 4); | 
|---|
| 95 | else   CheckBound(0, n, 0, 0, 0, 4); | 
|---|
| 96 | #endif | 
|---|
| 97 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | // Typedef pour simplifier et compatibilite Peida | 
|---|
| 101 | /*! \ingroup TArray | 
|---|
| 102 | \typedef Vector | 
|---|
| 103 | \brief To simplified TVector<r_8> writing | 
|---|
| 104 | */ | 
|---|
| 105 | typedef TVector<r_8> Vector; | 
|---|
| 106 |  | 
|---|
| 107 | } // Fin du namespace | 
|---|
| 108 |  | 
|---|
| 109 | #endif | 
|---|