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

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

modifs doc cmv 27/4/00

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