[279] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // C.Magneville 04/99
|
---|
| 3 | #ifndef TMATRIX_SEEN
|
---|
| 4 | #define TMATRIX_SEEN
|
---|
| 5 |
|
---|
| 6 | #include "machdefs.h"
|
---|
| 7 | #include <stdio.h>
|
---|
| 8 | #include <iostream.h>
|
---|
| 9 | #include "ppersist.h"
|
---|
| 10 | #include "anydataobj.h"
|
---|
| 11 | #include "ndatablock.h"
|
---|
| 12 |
|
---|
| 13 | namespace PlanckDPC {
|
---|
| 14 |
|
---|
| 15 | template <class T>
|
---|
| 16 | class TMatrix : public AnyDataObj {
|
---|
| 17 | public:
|
---|
| 18 | // Creation / destruction
|
---|
| 19 | TMatrix();
|
---|
| 20 | TMatrix(uint_4 r,uint_4 c);
|
---|
| 21 | TMatrix(uint_4 r,uint_4 c,T* values,Bridge* br=NULL);
|
---|
| 22 | TMatrix(const TMatrix<T>& a);
|
---|
| 23 | TMatrix(const TMatrix<T>& a,bool share);
|
---|
| 24 | virtual ~TMatrix();
|
---|
| 25 |
|
---|
| 26 | // Gestion taille/Remplissage
|
---|
| 27 | void Clone(const TMatrix<T>& a);
|
---|
| 28 | void Reset(T v=0);
|
---|
| 29 | void Realloc(uint_4 r,uint_4 c,bool force_alloc=true);
|
---|
| 30 |
|
---|
| 31 | // Informations pointeur/data
|
---|
| 32 | inline int NRows() const {return mNr;}
|
---|
| 33 | inline int NCol() const {return mNc;}
|
---|
| 34 | T const& operator()(uint_4 r,uint_4 c) const
|
---|
| 35 | {return *(mNDBlock->Begin()+r*mNc+c);}
|
---|
| 36 | T& operator()(uint_4 r,uint_4 c)
|
---|
| 37 | {return *(mNDBlock->Begin()+r*mNc+c);}
|
---|
| 38 | inline T* Data() {return mNDBlock->Begin();}
|
---|
| 39 | inline const T* Data() const {return mNDBlock->Begin();}
|
---|
| 40 | inline NDataBlock<T>* DataBlock() {return mNDBlock;}
|
---|
| 41 | inline const NDataBlock<T>* DataBlock() const {return mNDBlock;}
|
---|
| 42 |
|
---|
| 43 | // Operateur d'affectation
|
---|
| 44 | TMatrix<T>& operator = (T x);
|
---|
| 45 | TMatrix<T>& operator = (const TMatrix<T>& a);
|
---|
| 46 |
|
---|
| 47 | // Impression
|
---|
| 48 | void Print(ostream& os,int lp=0,uint_4 i0=0,uint_4 ni=10,uint_4 j0=0,uint_4 nj=10) const;
|
---|
| 49 | inline void Print(int lp=0,uint_4 i0=0,uint_4 ni=10,uint_4 j0=0,uint_4 nj=10) const
|
---|
| 50 | {Print(cout,lp,i0,ni,j0,nj);}
|
---|
| 51 |
|
---|
| 52 | // Surcharge d'operateurs
|
---|
| 53 | TMatrix<T>& operator += (T b);
|
---|
| 54 | TMatrix<T>& operator -= (T b);
|
---|
| 55 | TMatrix<T>& operator *= (T b);
|
---|
| 56 | TMatrix<T>& operator /= (T b);
|
---|
| 57 |
|
---|
| 58 | TMatrix<T>& operator += (const TMatrix<T>& a);
|
---|
| 59 | TMatrix<T>& operator -= (const TMatrix<T>& a);
|
---|
| 60 | TMatrix<T>& operator *= (const TMatrix<T>& a);
|
---|
| 61 |
|
---|
| 62 | protected:
|
---|
| 63 | void Delete(void);
|
---|
| 64 |
|
---|
| 65 | uint_4 mNr,mNc;
|
---|
| 66 | NDataBlock<T>* mNDBlock;
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 | template<class T>
|
---|
| 70 | inline ostream& operator << (ostream& os, const TMatrix<T>& a)
|
---|
| 71 | {a.Print(os); return(os);}
|
---|
| 72 |
|
---|
| 73 | } // Fin du namespace
|
---|
| 74 |
|
---|
| 75 | #endif
|
---|