// This may look like C code, but it is really -*- C++ -*- // C.Magneville 05/99 #ifndef TVector_SEEN #define TVector_SEEN #include "tmatrix.h" namespace SOPHYA { //! Class of vector (line or column) template class TVector : public TMatrix { public: // Creation / destruction TVector(); TVector(sa_size_t n, short lcv=AutoVectorType, short mm=AutoMemoryMapping); TVector(const TVector& v); TVector(const TVector& v, bool share); TVector(const TArray& a); TVector(const TArray& a, bool share, short lcv=AutoVectorType, short mm=AutoMemoryMapping); TVector(const BaseArray& a); virtual ~TVector(); //! Operator = /*! \warning Datas are copied (cloned) from \b a. \sa NDataBlock::operator=(const NDataBlock&) */ inline TVector& operator = (const TVector& a) { Set(a); return(*this); } //! Operator = between a vector and a matrix inline TVector& operator = (const TMatrix& a) { Set(a); return(*this); } //! Operator = between a vector and an array inline TVector& operator = (const TArray& a) { Set(a); return(*this); } //! Operator = between Vectors with different types inline TVector& operator = (const BaseArray& a) { SetBA(a); return(*this); } // Gestion taille/Remplissage void ReSize(sa_size_t n, short lcv=SameVectorType ); void Realloc(sa_size_t n, short lcv=SameVectorType, bool force=false); // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ? TVector SubVector(Range relt) const ; //! Extract a vector define by Range \b relt inline TVector operator () (Range relt) const { return SubVector(relt); } // Informations pointeur/data //! return the number of elements inline sa_size_t NElts() const {return Size(); } // Inline element acces methods inline T const& operator()(sa_size_t n) const; inline T& operator()(sa_size_t n); // Operateur d'affectation //! Fill the vector with Sequence \b seq inline TVector& operator = (Sequence const & seq) { SetSeq(seq); return(*this); } // Operations diverses avec une constante //! Set vector elements to constant value \b x inline TVector& operator = (T x) { SetT(x); return(*this); } //! Add constant value \b x to vector elements inline TVector& operator += (T x) { Add(x); return(*this); } //! Substract constant value \b x to vector elements inline TVector& operator -= (T x) { Sub(x); return(*this); } //! Multiply vector elements by constant value \b x inline TVector& operator *= (T x) { Mul(x); return(*this); } //! Divide vector elements by constant value \b x inline TVector& operator /= (T x) { Div(x); return(*this); } // operations avec matrices //! += : add a vector in place inline TVector& operator += (const TVector& a) { AddElt(a); return(*this); } //! += : substract a vector in place inline TVector& operator -= (const TVector& a) { SubElt(a); return(*this); } // Norme(^2) T Norm2() const ; virtual string InfoString() const; }; // ---- inline acces methods ------ //! Return the value of element \b n template inline T const& TVector::operator()(sa_size_t n) const { #ifdef SO_BOUNDCHECKING if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4); else CheckBound(0, n, 0, 0, 0, 4); #endif return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); } //! Return the value of element \b n template inline T & TVector::operator()(sa_size_t n) { #ifdef SO_BOUNDCHECKING if (veceli__ == 0) CheckBound(n, 0, 0, 0, 0, 4); else CheckBound(0, n, 0, 0, 0, 4); #endif return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) ); } // Typedef pour simplifier et compatibilite Peida /*! \ingroup TArray \typedef Vector \brief To simplified TVector writing */ typedef TVector Vector; } // Fin du namespace #endif