[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 |
|
---|
| 8 | namespace SOPHYA {
|
---|
| 9 |
|
---|
| 10 | template <class T>
|
---|
| 11 | class TVector : public TMatrix<T> {
|
---|
| 12 | public:
|
---|
| 13 |
|
---|
| 14 | // Creation / destruction
|
---|
| 15 | TVector(uint_4 n=1);
|
---|
| 16 | TVector(uint_4 n, T* values,Bridge* br=NULL);
|
---|
| 17 | TVector(const TVector<T>& v);
|
---|
| 18 | TVector(const TVector<T>& v,bool share);
|
---|
| 19 | TVector(const TMatrix<T>& a);
|
---|
| 20 |
|
---|
| 21 | // Gestion taille/Remplissage
|
---|
| 22 | inline void ReSize(uint_4 n) {TMatrix<T>::ReSize(n,1);} // Reallocation de place
|
---|
| 23 | inline void Realloc(uint_4 n,bool force=false) {TMatrix<T>::Realloc(n,1,force);}
|
---|
| 24 |
|
---|
| 25 | // Informations pointeur/data
|
---|
| 26 | inline uint_4 NElts() const {return NRows();}
|
---|
| 27 |
|
---|
| 28 | // Acces aux elements
|
---|
| 29 | inline T& operator()(uint_4 n) {return (*this)[n];}
|
---|
| 30 | inline T const& operator()(uint_4 n) const {return (*this)[n];}
|
---|
| 31 | inline T& Element(uint_4 n) {return (*this)[n];}
|
---|
| 32 | inline T const& Element(uint_4 n) const {return (*this)[n];}
|
---|
| 33 |
|
---|
| 34 | // Operateur d'affectation
|
---|
| 35 | inline TVector& operator = (const TVector& v)
|
---|
| 36 | {TMatrix<T>::operator =(v); return *this;}
|
---|
| 37 | inline TVector& operator = (T x)
|
---|
| 38 | {for(uint_4 i=0;i<NRows();i++) (*this)(i)=x; return *this;}
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | // produit scalaire, matrice*vecteur
|
---|
| 44 | template <class T>
|
---|
| 45 | inline T operator* (const TVector<T>& v1, const TVector<T>& v2)
|
---|
| 46 | {if(v1.NRows() != v2.NRows())
|
---|
| 47 | throw(SzMismatchError("TVector::operator*(TVector& v1,TVector v2) size mismatch"));
|
---|
| 48 | T *p = const_cast<T *>(v1.Data()), *pEnd = p+v1.NElts(),
|
---|
| 49 | *q = const_cast<T *>(v2.Data()), r = 0;
|
---|
| 50 | while (p<pEnd) r += *p++ * *q++;
|
---|
| 51 | return r;}
|
---|
| 52 |
|
---|
| 53 | template <class T>
|
---|
| 54 | inline TVector<T> operator* (const TMatrix<T>& a, const TVector<T>& b)
|
---|
| 55 | {return TVector<T>(a * ((TMatrix<T> const&)(b)));}
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | // Typedef pour simplifier et compatibilite Peida
|
---|
| 59 | typedef TVector<r_8> Vector;
|
---|
| 60 |
|
---|
| 61 | /////////////////////////////////////////////////////////////////////////
|
---|
| 62 | // Classe pour la gestion de persistance
|
---|
| 63 | template <class T>
|
---|
| 64 | class FIO_TVector : public PPersist {
|
---|
| 65 | public:
|
---|
| 66 | FIO_TVector();
|
---|
| 67 | FIO_TVector(string const & filename);
|
---|
| 68 | FIO_TVector(const TVector<T> & obj);
|
---|
| 69 | FIO_TVector(TVector<T> * obj);
|
---|
| 70 | virtual ~FIO_TVector();
|
---|
| 71 | virtual AnyDataObj* DataObj();
|
---|
| 72 | virtual void SetDataObj(AnyDataObj & o);
|
---|
| 73 | inline operator TVector<T>() { return(*dobj); }
|
---|
| 74 | protected :
|
---|
| 75 | virtual void ReadSelf(PInPersist&);
|
---|
| 76 | virtual void WriteSelf(POutPersist&) const;
|
---|
| 77 | TVector<T> * dobj;
|
---|
| 78 | bool ownobj;
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | template <class T>
|
---|
| 82 | inline POutPersist& operator << (POutPersist& os, TVector<T> & obj)
|
---|
| 83 | { FIO_TVector<T> fio(&obj); fio.Write(os); return(os); }
|
---|
| 84 | template <class T>
|
---|
| 85 | inline PInPersist& operator >> (PInPersist& is, TVector<T> & obj)
|
---|
| 86 | { FIO_TVector<T> fio(&obj); fio.Read(is); return(is); }
|
---|
| 87 |
|
---|
| 88 | } // Fin du namespace
|
---|
| 89 |
|
---|
| 90 | #endif
|
---|