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