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