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

Last change on this file since 2715 was 2575, checked in by ansari, 21 years ago

1/ Remplacement des methodes Add/Sub/Mul/DivElt(a) par

Add/Sub/Mul/DivElt(TArray a, TArray res)

2/ Operateurs += -= A+B A-B TArray et TMatrix/TVecteur modifies en consequence
3/ Ajout methode TArray::ScalarProduct()
4/ Methode TArray::SetT renomme en SetCst() SetT garde en alias
5/ Ajout parametre bool fzero (mise a zero) ajoute ds constructeur et

ReSize() de TMatrix et TVecteur.

Reza 29/07/2004

File size: 4.3 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, bool fzero=true);
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, bool fzero=true);
42 //! a synonym (alias) for method ReSize(sa_size_t, short)
43 inline void SetSize(sa_size_t n, short lcv=SameVectorType, bool fzero=true)
44 { ReSize(n, lcv, fzero); }
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) { AddCst(x,*this); return(*this); }
70 //! Substract constant value \b x to vector elements
71 inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); }
72 //! Multiply vector elements by constant value \b x
73 inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); }
74 //! Divide vector elements by constant value \b x
75 inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); }
76
77 // operations avec matrices
78 //! += : add a vector in place
79 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a,*this); return(*this); }
80 //! += : substract a vector in place
81 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a,*this); return(*this); }
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.