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

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

Modifs sur TMatrix::Transpose() et ajout methode SetSize comme alias de ReSize ds TMatrix et TVector - Reza 20/2/2001

File size: 4.2 KB
RevLine 
[762]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
[894]10//! Class of vector (line or column)
[762]11template <class T>
12class TVector : public TMatrix<T> {
13public:
14 // Creation / destruction
[804]15 TVector();
[1156]16 TVector(sa_size_t n, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
[762]17 TVector(const TVector<T>& v);
[804]18 TVector(const TVector<T>& v, bool share);
19 TVector(const TArray<T>& a);
[914]20 TVector(const TArray<T>& a, bool share, short lcv=AutoVectorType, short mm=AutoMemoryMapping);
[1099]21 TVector(const BaseArray& a);
[762]22
[804]23 virtual ~TVector();
24
[967]25 //! Operator =
[976]26 /*! \warning Datas are copied (cloned) from \b a.
27 \sa NDataBlock::operator=(const NDataBlock<T>&) */
[804]28 inline TVector<T>& operator = (const TVector<T>& a)
29 { Set(a); return(*this); }
[1099]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
[762]40 // Gestion taille/Remplissage
[1156]41 void ReSize(sa_size_t n, short lcv=SameVectorType );
[1412]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); }
[1156]45 void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false);
[762]46
[804]47 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
[813]48 TVector<T> SubVector(Range relt) const ;
[894]49 //! Extract a vector define by Range \b relt
[813]50 inline TVector<T> operator () (Range relt) const
51 { return SubVector(relt); }
[804]52
[762]53 // Informations pointeur/data
[894]54 //! return the number of elements
[1156]55 inline sa_size_t NElts() const {return Size(); }
[762]56
[804]57 // Inline element acces methods
[1156]58 inline T const& operator()(sa_size_t n) const;
59 inline T& operator()(sa_size_t n);
[762]60
[813]61 // Operateur d'affectation
[898]62 //! Fill the vector with Sequence \b seq
[1103]63 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
[813]64
[804]65 // Operations diverses avec une constante
[894]66 //! Set vector elements to constant value \b x
[813]67 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
[894]68 //! Add constant value \b x to vector elements
[804]69 inline TVector<T>& operator += (T x) { Add(x); return(*this); }
[894]70 //! Substract constant value \b x to vector elements
[804]71 inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
[894]72 //! Multiply vector elements by constant value \b x
[804]73 inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
[894]74 //! Divide vector elements by constant value \b x
[804]75 inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
[762]76
[804]77 // operations avec matrices
[894]78 //! += : add a vector in place
[804]79 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
[894]80 //! += : substract a vector in place
[804]81 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
[762]82
[804]83 // Norme(^2)
84 T Norm2() const ;
[813]85
86 virtual string InfoString() const;
87
[762]88};
89
[804]90// ---- inline acces methods ------
[894]91
92//! Return the value of element \b n
[762]93template <class T>
[1156]94inline T const& TVector<T>::operator()(sa_size_t n) const
[804]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}
[762]102
[894]103//! Return the value of element \b n
[762]104template <class T>
[1156]105inline T & TVector<T>::operator()(sa_size_t n)
[804]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}
[762]113
114// Typedef pour simplifier et compatibilite Peida
[956]115/*! \ingroup TArray
116 \typedef Vector
117 \brief To simplified TVector<r_8> writing
118*/
[762]119typedef TVector<r_8> Vector;
120
121} // Fin du namespace
122
123#endif
Note: See TracBrowser for help on using the repository browser.