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

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

Introduction du type sa_size_t (taille des tableaux), operateur - (TArray::operator - et NegateElt()) - Reza 29/8/2000

File size: 4.0 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 void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false);
43
44 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
45 TVector<T> SubVector(Range relt) const ;
46 //! Extract a vector define by Range \b relt
47 inline TVector<T> operator () (Range relt) const
48 { return SubVector(relt); }
49
50 // Informations pointeur/data
51 //! return the number of elements
52 inline sa_size_t NElts() const {return Size(); }
53
54 // Inline element acces methods
55 inline T const& operator()(sa_size_t n) const;
56 inline T& operator()(sa_size_t n);
57
58 // Operateur d'affectation
59 //! Fill the vector with Sequence \b seq
60 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
61
62 // Operations diverses avec une constante
63 //! Set vector elements to constant value \b x
64 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
65 //! Add constant value \b x to vector elements
66 inline TVector<T>& operator += (T x) { Add(x); return(*this); }
67 //! Substract constant value \b x to vector elements
68 inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
69 //! Multiply vector elements by constant value \b x
70 inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
71 //! Divide vector elements by constant value \b x
72 inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
73
74 // operations avec matrices
75 //! += : add a vector in place
76 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
77 //! += : substract a vector in place
78 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
79
80 // Norme(^2)
81 T Norm2() const ;
82
83 virtual string InfoString() const;
84
85};
86
87// ---- inline acces methods ------
88
89//! Return the value of element \b n
90template <class T>
91inline T const& TVector<T>::operator()(sa_size_t n) const
92{
93#ifdef SO_BOUNDCHECKING
94 if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
95 else CheckBound(0, n, 0, 0, 0, 4);
96#endif
97 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
98}
99
100//! Return the value of element \b n
101template <class T>
102inline T & TVector<T>::operator()(sa_size_t n)
103{
104#ifdef SO_BOUNDCHECKING
105 if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4);
106 else CheckBound(0, n, 0, 0, 0, 4);
107#endif
108 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
109}
110
111// Typedef pour simplifier et compatibilite Peida
112/*! \ingroup TArray
113 \typedef Vector
114 \brief To simplified TVector<r_8> writing
115*/
116typedef TVector<r_8> Vector;
117
118} // Fin du namespace
119
120#endif
Note: See TracBrowser for help on using the repository browser.