| 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 |  | 
|---|
| 15 | #include "tvector_tsnl.h"  /* For two level name look-up gcc >= 3.4 */ | 
|---|
| 16 |  | 
|---|
| 17 | // Creation / destruction | 
|---|
| 18 | TVector(); | 
|---|
| 19 | TVector(sa_size_t n, short lcv=BaseArray::AutoVectorType, short mm=BaseArray::AutoMemoryMapping, bool fzero=true); | 
|---|
| 20 | TVector(const TVector<T>& v); | 
|---|
| 21 | TVector(const TVector<T>& v, bool share); | 
|---|
| 22 | TVector(const TArray<T>& a,  bool share=true, short lcv=BaseArray::AutoVectorType); | 
|---|
| 23 | TVector(const BaseArray& a); | 
|---|
| 24 | TVector(const vector<T>& v, short lcv=BaseArray::AutoVectorType); | 
|---|
| 25 |  | 
|---|
| 26 | virtual ~TVector(); | 
|---|
| 27 |  | 
|---|
| 28 | //! Operator = | 
|---|
| 29 | /*! \warning Datas are copied (cloned) from \b a. | 
|---|
| 30 | \sa NDataBlock::operator=(const NDataBlock<T>&) */ | 
|---|
| 31 | inline  TVector<T>& operator = (const TVector<T>& a) | 
|---|
| 32 | { Set(a);  return(*this); } | 
|---|
| 33 | //! Operator = between a vector and a matrix | 
|---|
| 34 | inline  TVector<T>& operator = (const TMatrix<T>& a) | 
|---|
| 35 | { Set(a);  return(*this); } | 
|---|
| 36 | //! Operator = between a vector and an array | 
|---|
| 37 | inline  TVector<T>& operator = (const TArray<T>& a) | 
|---|
| 38 | { Set(a);  return(*this); } | 
|---|
| 39 | //! Operator = between Vectors with different types | 
|---|
| 40 | inline  TVector<T>& operator = (const BaseArray& a) | 
|---|
| 41 | { SetBA(a);  return(*this); } | 
|---|
| 42 |  | 
|---|
| 43 | // Gestion taille/Remplissage | 
|---|
| 44 | void ReSize(sa_size_t n, short lcv=BaseArray::SameVectorType, bool fzero=true); | 
|---|
| 45 | //! a synonym (alias) for method ReSize(sa_size_t, short) | 
|---|
| 46 | inline void SetSize(sa_size_t n, short lcv=BaseArray::SameVectorType, bool fzero=true) | 
|---|
| 47 | { ReSize(n, lcv, fzero); } | 
|---|
| 48 | void Realloc(sa_size_t n, short lcv=BaseArray::SameVectorType, bool force=false); | 
|---|
| 49 |  | 
|---|
| 50 | // Remplissage from/to a STL vector | 
|---|
| 51 | sa_size_t FillFr(const vector<T>& v,bool noresize=false); | 
|---|
| 52 | sa_size_t FillTo(vector<T>& v,bool addtoend=false); | 
|---|
| 53 |  | 
|---|
| 54 | // Sub-Vector extraction $CHECK$ Reza 03/2000  Doit-on declarer cette methode const ? | 
|---|
| 55 | TVector<T> SubVector(Range relt) const ; | 
|---|
| 56 | //! Extract a vector define by Range \b relt | 
|---|
| 57 | inline TVector<T> operator () (Range relt) const | 
|---|
| 58 | { return SubVector(relt); } | 
|---|
| 59 |  | 
|---|
| 60 | // Informations pointeur/data | 
|---|
| 61 | //! return the number of elements | 
|---|
| 62 | inline sa_size_t NElts() const {return Size(); } | 
|---|
| 63 |  | 
|---|
| 64 | // Inline element acces methods | 
|---|
| 65 | inline T const& operator()(sa_size_t n) const; | 
|---|
| 66 | inline T&       operator()(sa_size_t n); | 
|---|
| 67 |  | 
|---|
| 68 | // Operateur d'affectation | 
|---|
| 69 | //! Fill the vector with Sequence \b seq | 
|---|
| 70 | inline  TVector<T>&  operator = (Sequence const & seq) { SetSeq(seq); return(*this); } | 
|---|
| 71 |  | 
|---|
| 72 | // Operations diverses  avec une constante | 
|---|
| 73 | //! Set vector elements to constant value \b x | 
|---|
| 74 | inline  TVector<T>&  operator = (T x)             { SetT(x); return(*this); } | 
|---|
| 75 | //! Add constant value \b x to vector elements | 
|---|
| 76 | inline  TVector<T>&  operator += (T x)            { AddCst(x,*this); return(*this); } | 
|---|
| 77 | //! Substract constant value \b x to vector elements | 
|---|
| 78 | inline  TVector<T>&  operator -= (T x)            { SubCst(x,*this); return(*this); } | 
|---|
| 79 | //! Multiply vector elements by constant value \b x | 
|---|
| 80 | inline  TVector<T>&  operator *= (T x)            { MulCst(x,*this); return(*this); } | 
|---|
| 81 | //! Divide vector elements by constant value \b x | 
|---|
| 82 | inline  TVector<T>&  operator /= (T x)            { DivCst(x,*this); return(*this); } | 
|---|
| 83 |  | 
|---|
| 84 | //  operations avec matrices | 
|---|
| 85 | //! += : add a vector in place | 
|---|
| 86 | inline  TVector<T>&  operator += (const TVector<T>& a)  { AddElt(a,*this); return(*this); } | 
|---|
| 87 | //! += : substract a vector in place | 
|---|
| 88 | inline  TVector<T>&  operator -= (const TVector<T>& a)  { SubElt(a,*this); return(*this); } | 
|---|
| 89 |  | 
|---|
| 90 | virtual string InfoString() const; | 
|---|
| 91 |  | 
|---|
| 92 | }; | 
|---|
| 93 |  | 
|---|
| 94 | //  ---- inline acces methods ------ | 
|---|
| 95 |  | 
|---|
| 96 | //! Return the value of element \b n | 
|---|
| 97 | template <class T> | 
|---|
| 98 | inline T const& TVector<T>::operator()(sa_size_t n) const | 
|---|
| 99 | { | 
|---|
| 100 | #ifdef SO_BOUNDCHECKING | 
|---|
| 101 | if (veceli_ == 0)   CheckBound(n, 0, 0, 0, 0, 4); | 
|---|
| 102 | else   CheckBound(0, n, 0, 0, 0, 4); | 
|---|
| 103 | #endif | 
|---|
| 104 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | //! Return the value of element \b n | 
|---|
| 108 | template <class T> | 
|---|
| 109 | inline T & TVector<T>::operator()(sa_size_t n) | 
|---|
| 110 | { | 
|---|
| 111 | #ifdef SO_BOUNDCHECKING | 
|---|
| 112 | if (veceli_ == 0)   CheckBound(n, 0, 0, 0, 0, 4); | 
|---|
| 113 | else   CheckBound(0, n, 0, 0, 0, 4); | 
|---|
| 114 | #endif | 
|---|
| 115 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | // Typedef pour simplifier et compatibilite Peida | 
|---|
| 119 | /*! \ingroup TArray | 
|---|
| 120 | \typedef Vector | 
|---|
| 121 | \brief To simplified TVector<r_8> writing | 
|---|
| 122 | */ | 
|---|
| 123 | typedef TVector<r_8> Vector; | 
|---|
| 124 |  | 
|---|
| 125 | } // Fin du namespace | 
|---|
| 126 |  | 
|---|
| 127 | #endif | 
|---|