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

Last change on this file since 2367 was 2299, checked in by ansari, 23 years ago

Correction nom variable - lors compil avec Bound-Checking , Reza 15/12/2002

File size: 4.2 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)
11template <class T>
12class TVector : public TMatrix<T> {
13public:
14 // Creation / destruction
15 TVector();
16 TVector(sa_size_t 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 TVector(const BaseArray& a);
22
23 virtual ~TVector();
24
25 //! Operator =
26 /*! \warning Datas are copied (cloned) from \b a.
27 \sa NDataBlock::operator=(const NDataBlock<T>&) */
28 inline TVector<T>& operator = (const TVector<T>& a)
29 { Set(a); return(*this); }
30 //! Operator = between a vector and a matrix
31 inline TVector<T>& operator = (const TMatrix<T>& a)
32 { Set(a); return(*this); }
33 //! Operator = between a vector and an array
34 inline TVector<T>& operator = (const TArray<T>& a)
35 { Set(a); return(*this); }
36 //! Operator = between Vectors with different types
37 inline TVector<T>& operator = (const BaseArray& a)
38 { SetBA(a); return(*this); }
39
40 // Gestion taille/Remplissage
41 void ReSize(sa_size_t n, short lcv=SameVectorType );
42 //! a synonym (alias) for method ReSize(sa_size_t, short)
43 inline void SetSize(sa_size_t n, short lcv=SameVectorType )
44 { ReSize(n, lcv); }
45 void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false);
46
47 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
48 TVector<T> SubVector(Range relt) const ;
49 //! Extract a vector define by Range \b relt
50 inline TVector<T> operator () (Range relt) const
51 { return SubVector(relt); }
52
53 // Informations pointeur/data
54 //! return the number of elements
55 inline sa_size_t NElts() const {return Size(); }
56
57 // Inline element acces methods
58 inline T const& operator()(sa_size_t n) const;
59 inline T& operator()(sa_size_t n);
60
61 // Operateur d'affectation
62 //! Fill the vector with Sequence \b seq
63 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
64
65 // Operations diverses avec une constante
66 //! Set vector elements to constant value \b x
67 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
68 //! Add constant value \b x to vector elements
69 inline TVector<T>& operator += (T x) { Add(x); return(*this); }
70 //! Substract constant value \b x to vector elements
71 inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
72 //! Multiply vector elements by constant value \b x
73 inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
74 //! Divide vector elements by constant value \b x
75 inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
76
77 // operations avec matrices
78 //! += : add a vector in place
79 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
80 //! += : substract a vector in place
81 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
82
83 // Norme(^2)
84 T Norm2() const ;
85
86 virtual string InfoString() const;
87
88};
89
90// ---- inline acces methods ------
91
92//! Return the value of element \b n
93template <class T>
94inline T const& TVector<T>::operator()(sa_size_t n) const
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//! Return the value of element \b n
104template <class T>
105inline T & TVector<T>::operator()(sa_size_t n)
106{
107#ifdef SO_BOUNDCHECKING
108 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
109 else CheckBound(0, n, 0, 0, 0, 4);
110#endif
111 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
112}
113
114// Typedef pour simplifier et compatibilite Peida
115/*! \ingroup TArray
116 \typedef Vector
117 \brief To simplified TVector<r_8> writing
118*/
119typedef TVector<r_8> Vector;
120
121} // Fin du namespace
122
123#endif
Note: See TracBrowser for help on using the repository browser.