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