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

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

Introduction du type sa_size_t (taille des tableaux), operateur - (TArray::operator - et NegateElt()) - Reza 29/8/2000

File size: 4.0 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 );
42 void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false);
[762]43
[804]44 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
[813]45 TVector<T> SubVector(Range relt) const ;
[894]46 //! Extract a vector define by Range \b relt
[813]47 inline TVector<T> operator () (Range relt) const
48 { return SubVector(relt); }
[804]49
[762]50 // Informations pointeur/data
[894]51 //! return the number of elements
[1156]52 inline sa_size_t NElts() const {return Size(); }
[762]53
[804]54 // Inline element acces methods
[1156]55 inline T const& operator()(sa_size_t n) const;
56 inline T& operator()(sa_size_t n);
[762]57
[813]58 // Operateur d'affectation
[898]59 //! Fill the vector with Sequence \b seq
[1103]60 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
[813]61
[804]62 // Operations diverses avec une constante
[894]63 //! Set vector elements to constant value \b x
[813]64 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
[894]65 //! Add constant value \b x to vector elements
[804]66 inline TVector<T>& operator += (T x) { Add(x); return(*this); }
[894]67 //! Substract constant value \b x to vector elements
[804]68 inline TVector<T>& operator -= (T x) { Sub(x); return(*this); }
[894]69 //! Multiply vector elements by constant value \b x
[804]70 inline TVector<T>& operator *= (T x) { Mul(x); return(*this); }
[894]71 //! Divide vector elements by constant value \b x
[804]72 inline TVector<T>& operator /= (T x) { Div(x); return(*this); }
[762]73
[804]74 // operations avec matrices
[894]75 //! += : add a vector in place
[804]76 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a); return(*this); }
[894]77 //! += : substract a vector in place
[804]78 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a); return(*this); }
[762]79
[804]80 // Norme(^2)
81 T Norm2() const ;
[813]82
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
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}
[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
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}
[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.