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

Last change on this file since 4042 was 4035, checked in by ansari, 14 years ago

1/ modif mineure ds TArray<T>::::ReadASCII() au print level global de BaseArray
2/ Correction bug gestion memoire au niveau des constructeurs de copie TArray/TMatrix/TVector
avec un BaseArray en argument. Ajout argument optionnel bool pack a ces constructeurs
3/ On autorise desormais la creation des objets TArray/TMatrix/TVector par constructeur de
copie sur des objets non alloues

Reza, 14/11/2011

File size: 5.4 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:
[2884]14
15#include "tvector_tsnl.h" /* For two level name look-up gcc >= 3.4 */
16
[762]17 // Creation / destruction
[804]18 TVector();
[2868]19 TVector(sa_size_t n, short lcv=BaseArray::AutoVectorType, short mm=BaseArray::AutoMemoryMapping, bool fzero=true);
[762]20 TVector(const TVector<T>& v);
[804]21 TVector(const TVector<T>& v, bool share);
[4035]22 TVector(const TArray<T>& a, bool share=true, short lcv=BaseArray::AutoVectorType);
23 TVector(const BaseArray& a, bool pack=true);
[2868]24 TVector(const vector<T>& v, short lcv=BaseArray::AutoVectorType);
[762]25
[804]26 virtual ~TVector();
27
[967]28 //! Operator =
[976]29 /*! \warning Datas are copied (cloned) from \b a.
30 \sa NDataBlock::operator=(const NDataBlock<T>&) */
[804]31 inline TVector<T>& operator = (const TVector<T>& a)
32 { Set(a); return(*this); }
[1099]33 //! Operator = between a vector and a matrix
34 inline TVector<T>& operator = (const TMatrix<T>& a)
35 { Set(a); return(*this); }
36 //! Operator = between a vector and an array
37 inline TVector<T>& operator = (const TArray<T>& a)
38 { Set(a); return(*this); }
39 //! Operator = between Vectors with different types
40 inline TVector<T>& operator = (const BaseArray& a)
41 { SetBA(a); return(*this); }
42
[762]43 // Gestion taille/Remplissage
[2868]44 void ReSize(sa_size_t n, short lcv=BaseArray::SameVectorType, bool fzero=true);
[1412]45 //! a synonym (alias) for method ReSize(sa_size_t, short)
[2868]46 inline void SetSize(sa_size_t n, short lcv=BaseArray::SameVectorType, bool fzero=true)
[2575]47 { ReSize(n, lcv, fzero); }
[2868]48 void Realloc(sa_size_t n, short lcv=BaseArray::SameVectorType, bool force=false);
[2719]49
50 // Remplissage from/to a STL vector
51 sa_size_t FillFr(const vector<T>& v,bool noresize=false);
52 sa_size_t FillTo(vector<T>& v,bool addtoend=false);
[3857]53 vector<T> ConvertTostdvec();
[762]54
[804]55 // Sub-Vector extraction $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ?
[813]56 TVector<T> SubVector(Range relt) const ;
[894]57 //! Extract a vector define by Range \b relt
[813]58 inline TVector<T> operator () (Range relt) const
59 { return SubVector(relt); }
[804]60
[762]61 // Informations pointeur/data
[894]62 //! return the number of elements
[1156]63 inline sa_size_t NElts() const {return Size(); }
[762]64
[804]65 // Inline element acces methods
[1156]66 inline T const& operator()(sa_size_t n) const;
67 inline T& operator()(sa_size_t n);
[762]68
[813]69 // Operateur d'affectation
[898]70 //! Fill the vector with Sequence \b seq
[1103]71 inline TVector<T>& operator = (Sequence const & seq) { SetSeq(seq); return(*this); }
[813]72
[804]73 // Operations diverses avec une constante
[894]74 //! Set vector elements to constant value \b x
[813]75 inline TVector<T>& operator = (T x) { SetT(x); return(*this); }
[894]76 //! Add constant value \b x to vector elements
[2564]77 inline TVector<T>& operator += (T x) { AddCst(x,*this); return(*this); }
[894]78 //! Substract constant value \b x to vector elements
[2564]79 inline TVector<T>& operator -= (T x) { SubCst(x,*this); return(*this); }
[894]80 //! Multiply vector elements by constant value \b x
[2564]81 inline TVector<T>& operator *= (T x) { MulCst(x,*this); return(*this); }
[894]82 //! Divide vector elements by constant value \b x
[2564]83 inline TVector<T>& operator /= (T x) { DivCst(x,*this); return(*this); }
[762]84
[804]85 // operations avec matrices
[894]86 //! += : add a vector in place
[2575]87 inline TVector<T>& operator += (const TVector<T>& a) { AddElt(a,*this); return(*this); }
[894]88 //! += : substract a vector in place
[2575]89 inline TVector<T>& operator -= (const TVector<T>& a) { SubElt(a,*this); return(*this); }
[762]90
[813]91 virtual string InfoString() const;
92
[762]93};
94
[804]95// ---- inline acces methods ------
[894]96
97//! Return the value of element \b n
[762]98template <class T>
[1156]99inline T const& TVector<T>::operator()(sa_size_t n) const
[804]100{
101#ifdef SO_BOUNDCHECKING
[2299]102 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
[804]103 else CheckBound(0, n, 0, 0, 0, 4);
104#endif
105 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
106}
[762]107
[894]108//! Return the value of element \b n
[762]109template <class T>
[1156]110inline T & TVector<T>::operator()(sa_size_t n)
[804]111{
112#ifdef SO_BOUNDCHECKING
[2299]113 if (veceli_ == 0) CheckBound(n, 0, 0, 0, 0, 4);
[804]114 else CheckBound(0, n, 0, 0, 0, 4);
115#endif
116 return ( *( mNDBlock.Begin()+ offset_ + n*step_[veceli_] ) );
117}
[762]118
119// Typedef pour simplifier et compatibilite Peida
[956]120/*! \ingroup TArray
121 \typedef Vector
122 \brief To simplified TVector<r_8> writing
123*/
[762]124typedef TVector<r_8> Vector;
125
[3831]126//--------- extern template declarations (if needed) -----------
127#if defined ( NEED_EXT_DECL_TEMP ) && !defined( TVECTOR_CC_BFILE )
128extern template class TVector<uint_1>;
129extern template class TVector<uint_2>;
130extern template class TVector<uint_4>;
131extern template class TVector<uint_8>;
132extern template class TVector<int_1>;
133extern template class TVector<int_2>;
134extern template class TVector<int_4>;
135extern template class TVector<int_8>;
136extern template class TVector<r_4>;
137extern template class TVector<r_8>;
138extern template class TVector< complex<r_4> >;
139extern template class TVector< complex<r_8> >;
140#ifdef SO_LDBLE128
141extern template class TVector<r_16>;
142extern template class TVector< complex<r_16> >;
143#endif
144#endif // Fin de if defined ( NEED_EXT_DECL_TEMP )
145
[762]146} // Fin du namespace
147
148#endif
Note: See TracBrowser for help on using the repository browser.