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

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

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