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