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