| 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 | vector<T> ConvertTostdvec();
|
|---|
| 54 |
|
|---|
| 55 | // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
|---|
| 56 | TVector<T> SubVector(Range relt) const ;
|
|---|
| 57 | //! Extract a vector define by Range \b relt
|
|---|
| 58 | inline TVector<T> operator () (Range relt) const
|
|---|
| 59 | { return SubVector(relt); }
|
|---|
| 60 |
|
|---|
| 61 | // Informations pointeur/data
|
|---|
| 62 | //! return the number of elements
|
|---|
| 63 | inline sa_size_t NElts() const {return Size(); }
|
|---|
| 64 |
|
|---|
| 65 | // Inline element acces methods
|
|---|
| 66 | inline T const& operator()(sa_size_t n) const;
|
|---|
| 67 | inline T& operator()(sa_size_t n);
|
|---|
| 68 |
|
|---|
| 69 | // Operateur d'affectation
|
|---|
| 70 | //! Fill the vector with Sequence \b seq
|
|---|
| 71 | inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
|
|---|
| 72 |
|
|---|
| 73 | // Operations diverses avec une constante
|
|---|
| 74 | //! Set vector elements to constant value \b x
|
|---|
| 75 | inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
|
|---|
| 76 | //! Add constant value \b x to vector elements
|
|---|
| 77 | inline TVector<T>& operator += (T x) { AddCst(x,*this); return(*this); }
|
|---|
| 78 | //! Substract constant value \b x to vector elements
|
|---|
| 79 | inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); }
|
|---|
| 80 | //! Multiply vector elements by constant value \b x
|
|---|
| 81 | inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); }
|
|---|
| 82 | //! Divide vector elements by constant value \b x
|
|---|
| 83 | inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); }
|
|---|
| 84 |
|
|---|
| 85 | // operations avec matrices
|
|---|
| 86 | //! += : add a vector in place
|
|---|
| 87 | inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a,*this); return(*this); }
|
|---|
| 88 | //! += : substract a vector in place
|
|---|
| 89 | inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a,*this); return(*this); }
|
|---|
| 90 |
|
|---|
| 91 | virtual string InfoString() const;
|
|---|
| 92 |
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 | // ---- inline acces methods ------
|
|---|
| 96 |
|
|---|
| 97 | //! Return the value of element \b n
|
|---|
| 98 | template <class T>
|
|---|
| 99 | inline T const& TVector<T>::operator()(sa_size_t n) const
|
|---|
| 100 | {
|
|---|
| 101 | #ifdef SO_BOUNDCHECKING
|
|---|
| 102 | if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
|---|
| 103 | else CheckBound(0, n, 0, 0, 0, 4);
|
|---|
| 104 | #endif
|
|---|
| 105 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | //! Return the value of element \b n
|
|---|
| 109 | template <class T>
|
|---|
| 110 | inline T & TVector<T>::operator()(sa_size_t n)
|
|---|
| 111 | {
|
|---|
| 112 | #ifdef SO_BOUNDCHECKING
|
|---|
| 113 | if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
|---|
| 114 | else CheckBound(0, n, 0, 0, 0, 4);
|
|---|
| 115 | #endif
|
|---|
| 116 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | // Typedef pour simplifier et compatibilite Peida
|
|---|
| 120 | /*! \ingroup TArray
|
|---|
| 121 | \typedef Vector
|
|---|
| 122 | \brief To simplified TVector<r_8> writing
|
|---|
| 123 | */
|
|---|
| 124 | typedef TVector<r_8> Vector;
|
|---|
| 125 |
|
|---|
| 126 | //--------- extern template declarations (if needed) -----------
|
|---|
| 127 | #if defined ( NEED_EXT_DECL_TEMP ) && !defined( TVECTOR_CC_BFILE )
|
|---|
| 128 | extern template class TVector<uint_1>;
|
|---|
| 129 | extern template class TVector<uint_2>;
|
|---|
| 130 | extern template class TVector<uint_4>;
|
|---|
| 131 | extern template class TVector<uint_8>;
|
|---|
| 132 | extern template class TVector<int_1>;
|
|---|
| 133 | extern template class TVector<int_2>;
|
|---|
| 134 | extern template class TVector<int_4>;
|
|---|
| 135 | extern template class TVector<int_8>;
|
|---|
| 136 | extern template class TVector<r_4>;
|
|---|
| 137 | extern template class TVector<r_8>;
|
|---|
| 138 | extern template class TVector< complex<r_4> >;
|
|---|
| 139 | extern template class TVector< complex<r_8> >;
|
|---|
| 140 | #ifdef SO_LDBLE128
|
|---|
| 141 | extern template class TVector<r_16>;
|
|---|
| 142 | extern template class TVector< complex<r_16> >;
|
|---|
| 143 | #endif
|
|---|
| 144 | #endif // Fin de if defined ( NEED_EXT_DECL_TEMP )
|
|---|
| 145 |
|
|---|
| 146 | } // Fin du namespace
|
|---|
| 147 |
|
|---|
| 148 | #endif
|
|---|