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
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();
[2575]16 TVector(sa_size_t n, short lcv=AutoVectorType, short mm=AutoMemoryMapping, bool fzero=true);
[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
[2575]41 void ReSize(sa_size_t n, short lcv=SameVectorType, bool fzero=true);
[1412]42 //! a synonym (alias) for method ReSize(sa_size_t, short)
[2575]43 inline void SetSize(sa_size_t n, short lcv=SameVectorType, bool fzero=true)
44 { ReSize(n, lcv, fzero); }
[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
[2564]69 inline TVector<T>& operator += (T x) { AddCst(x,*this); return(*this); }
[894]70 //! Substract constant value \b x to vector elements
[2564]71 inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); }
[894]72 //! Multiply vector elements by constant value \b x
[2564]73 inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); }
[894]74 //! Divide vector elements by constant value \b x
[2564]75 inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); }
[762]76
[804]77 // operations avec matrices
[894]78 //! += : add a vector in place
[2575]79 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a,*this); return(*this); }
[894]80 //! += : substract a vector in place
[2575]81 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a,*this); return(*this); }
[762]82
[813]83 virtual string InfoString() const;
84
[762]85};
86
[804]87// ---- inline acces methods ------
[894]88
89//! Return the value of element \b n
[762]90template <class T>
[1156]91inline T const& TVector<T>::operator()(sa_size_t n) const
[804]92{
93#ifdef SO_BOUNDCHECKING
[2299]94 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
[804]95 else CheckBound(0, n, 0, 0, 0, 4);
96#endif
97 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
98}
[762]99
[894]100//! Return the value of element \b n
[762]101template <class T>
[1156]102inline T & TVector<T>::operator()(sa_size_t n)
[804]103{
104#ifdef SO_BOUNDCHECKING
[2299]105 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
[804]106 else CheckBound(0, n, 0, 0, 0, 4);
107#endif
108 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
109}
[762]110
111// Typedef pour simplifier et compatibilite Peida
[956]112/*! \ingroup TArray
113 \typedef Vector
114 \brief To simplified TVector<r_8> writing
115*/
[762]116typedef TVector<r_8> Vector;
117
118} // Fin du namespace
119
120#endif
Note: See TracBrowser for help on using the repository browser.