source: Sophya/trunk/SophyaLib/TArray/tvector.h@ 914

Last change on this file since 914 was 914, checked in by ansari, 25 years ago

documentation cmv 13/4/00

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