[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)
|
---|
| 11 | /*!
|
---|
[920] | 12 | \class SOPHYA::TVector
|
---|
| 13 | \ingroup TArray
|
---|
[894] | 14 | \sa TMatrix TArray
|
---|
| 15 | */
|
---|
[762] | 16 | template <class T>
|
---|
| 17 | class TVector : public TMatrix<T> {
|
---|
| 18 | public:
|
---|
| 19 | // Creation / destruction
|
---|
[804] | 20 | TVector();
|
---|
[914] | 21 | TVector(uint_4 n, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
|
---|
[762] | 22 | TVector(const TVector<T>& v);
|
---|
[804] | 23 | TVector(const TVector<T>& v, bool share);
|
---|
| 24 | TVector(const TArray<T>& a);
|
---|
[914] | 25 | TVector(const TArray<T>& a, bool share, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
|
---|
[762] | 26 |
|
---|
[804] | 27 | virtual ~TVector();
|
---|
| 28 |
|
---|
[894] | 29 | //! Operator =
|
---|
[804] | 30 | inline TVector<T>& operator = (const TVector<T>& a)
|
---|
| 31 | { Set(a); return(*this); }
|
---|
| 32 |
|
---|
[762] | 33 | // Gestion taille/Remplissage
|
---|
[813] | 34 | void ReSize(uint_4 n, short lcv=SameVectorType );
|
---|
| 35 | void Realloc(uint_4 n, short lcv=SameVectorType, bool force=false);
|
---|
[762] | 36 |
|
---|
[804] | 37 | // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
|
---|
[813] | 38 | TVector<T> SubVector(Range relt) const ;
|
---|
[894] | 39 | //! Extract a vector define by Range \b relt
|
---|
[813] | 40 | inline TVector<T> operator () (Range relt) const
|
---|
| 41 | { return SubVector(relt); }
|
---|
[804] | 42 |
|
---|
[762] | 43 | // Informations pointeur/data
|
---|
[894] | 44 | //! return the number of elements
|
---|
[804] | 45 | inline uint_4 NElts() const {return Size(); }
|
---|
[762] | 46 |
|
---|
[804] | 47 | // Inline element acces methods
|
---|
| 48 | inline T const& operator()(uint_4 n) const;
|
---|
| 49 | inline T& operator()(uint_4 n);
|
---|
[762] | 50 |
|
---|
[813] | 51 | // Operateur d'affectation
|
---|
[898] | 52 | //! Fill the vector with Sequence \b seq
|
---|
[914] | 53 | inline TVector<T>& operator = (Sequence seq) { SetSeq(seq); return(*this); }
|
---|
[813] | 54 |
|
---|
[804] | 55 | // Operations diverses avec une constante
|
---|
[894] | 56 | //! Set vector elements to constant value \b x
|
---|
[813] | 57 | inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
|
---|
[894] | 58 | //! Add constant value \b x to vector elements
|
---|
[804] | 59 | inline TVector<T>& operator += (T x) { Add(x); return(*this); }
|
---|
[894] | 60 | //! Substract constant value \b x to vector elements
|
---|
[804] | 61 | inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
|
---|
[894] | 62 | //! Multiply vector elements by constant value \b x
|
---|
[804] | 63 | inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
|
---|
[894] | 64 | //! Divide vector elements by constant value \b x
|
---|
[804] | 65 | inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
|
---|
[762] | 66 |
|
---|
[804] | 67 | // operations avec matrices
|
---|
[894] | 68 | //! += : add a vector in place
|
---|
[804] | 69 | inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
|
---|
[894] | 70 | //! += : substract a vector in place
|
---|
[804] | 71 | inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
|
---|
[762] | 72 |
|
---|
[804] | 73 | // Norme(^2)
|
---|
| 74 | T Norm2() const ;
|
---|
[813] | 75 |
|
---|
| 76 | virtual string InfoString() const;
|
---|
| 77 |
|
---|
[762] | 78 | };
|
---|
| 79 |
|
---|
[804] | 80 | // ---- inline acces methods ------
|
---|
[894] | 81 |
|
---|
| 82 | //! Return the value of element \b n
|
---|
[762] | 83 | template <class T>
|
---|
[804] | 84 | inline T const& TVector<T>::operator()(uint_4 n) const
|
---|
| 85 | {
|
---|
| 86 | #ifdef SO_BOUNDCHECKING
|
---|
| 87 | if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
---|
| 88 | else CheckBound(0, n, 0, 0, 0, 4);
|
---|
| 89 | #endif
|
---|
| 90 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
---|
| 91 | }
|
---|
[762] | 92 |
|
---|
[894] | 93 | //! Return the value of element \b n
|
---|
[762] | 94 | template <class T>
|
---|
[804] | 95 | inline T & TVector<T>::operator()(uint_4 n)
|
---|
| 96 | {
|
---|
| 97 | #ifdef SO_BOUNDCHECKING
|
---|
| 98 | if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
|
---|
| 99 | else CheckBound(0, n, 0, 0, 0, 4);
|
---|
| 100 | #endif
|
---|
| 101 | return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
|
---|
| 102 | }
|
---|
[762] | 103 |
|
---|
| 104 | // Typedef pour simplifier et compatibilite Peida
|
---|
[894] | 105 | //! Define Vector to be TVector<r_8>
|
---|
[762] | 106 | typedef TVector<r_8> Vector;
|
---|
| 107 |
|
---|
| 108 | } // Fin du namespace
|
---|
| 109 |
|
---|
| 110 | #endif
|
---|