Changeset 804 in Sophya for trunk/SophyaLib/TArray/tvector.cc
- Timestamp:
- Apr 3, 2000, 7:36:01 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/TArray/tvector.cc
r762 r804 1 // $Id: tvector.cc,v 1. 1.1.1 2000-03-02 16:48:24ansari Exp $1 // $Id: tvector.cc,v 1.2 2000-04-03 17:35:59 ansari Exp $ 2 2 // C.Magneville 04/99 3 3 #include "machdefs.h" 4 #include <stdio.h>5 4 #include <stdlib.h> 6 #include <iostream.h>7 #include <complex>8 5 #include "pexceptions.h" 9 6 #include "tvector.h" 10 #include "objfio.h" 7 8 //////////////////////////////////////////////////////////////// 9 //**** Createur, Destructeur 11 10 12 11 template <class T> 13 TVector<T>::TVector(uint_4 n) 14 // Constructeur d'un vecteur de "n" elements 15 : TMatrix<T>(n,1) 12 TVector<T>::TVector() 13 : TMatrix<T>() 16 14 { 17 15 } 18 16 19 17 template <class T> 20 TVector<T>::TVector(uint_4 n, T* values,Bridge* br) 21 // Construit un vecteur de n elements. On fournit 22 // le tableau des valeurs et eventuellement un Bridge. 23 : TMatrix<T>(n,1,values,br) 18 TVector<T>::TVector(uint_4 n, short lcv, short mm) 19 // Constructeur 20 : TMatrix<T>((lcv == ColumnVector) ? n : 1,(lcv == ColumnVector) ? 1 : 0, mm) 21 { 22 if (lcv == ColumnVector) veceli_ = marowi_; 23 else veceli_ = macoli_; 24 } 25 26 27 template <class T> 28 TVector<T>::TVector(const TVector<T>& a) 29 // Constructeur par copie (partage si "a" temporaire). 30 : TMatrix<T>(a) 24 31 { 25 32 } 26 33 27 34 template <class T> 28 TVector<T>::TVector(const TVector<T>& v)29 // Constructeur par copie (partage si "v" temporaire).30 : TMatrix<T>( v)35 TVector<T>::TVector(const TVector<T>& a, bool share) 36 // Constructeur par copie avec possibilite de forcer le partage ou non. 37 : TMatrix<T>(a, share) 31 38 { 32 39 } 33 40 34 41 template <class T> 35 TVector<T>::TVector(const TVector<T>& v,bool share) 36 // Constructeur par copie avec possibilite de forcer le partage ou non. 37 : TMatrix<T>(v,share) 42 TVector<T>::TVector(const TArray<T>& a) 43 : TMatrix<T>(a) 38 44 { 39 45 } 40 46 47 41 48 template <class T> 42 TVector<T>::TVector(const TMatrix<T>& a) 43 // Constructeur a partir d'une matrice "a" de dimension (n,1) 44 : TMatrix<T>(a) 49 TVector<T>::TVector(const TArray<T>& a, bool share, short lcv, short mm ) 50 : TMatrix<T>(a, share, mm) 45 51 { 46 if(a.NCols() != 1) 47 throw(SzMismatchError("TVector(const TMatrix<T>& a) size mismatch, ncol!=1")); 52 if (lcv == SameTypeVector) veceli_ = a.VectKA(); 53 else { 54 if (lcv == ColumnVector) veceli_ = marowi_; 55 else veceli_ = macoli_; 56 } 57 } 58 59 template <class T> 60 TVector<T>::~TVector() 61 // Destructeur 62 { 63 64 } 65 66 template <class T> 67 void TVector<T>::ReSize(uint_4 n, short lcv) 68 { 69 if( n == 0 ) 70 throw(SzMismatchError("TVector::ReSize() n = 0 ")); 71 uint_4 r,c; 72 if (lcv == SameTypeVector) lcv = GetVectorType(); 73 if (lcv == ColumnVector) { r = n; c = 1; } 74 else { c = n; r = 1; } 75 TMatrix<T>::ReSize(r,c); 76 } 77 78 template <class T> 79 void TVector<T>::Realloc(uint_4 n, short lcv, bool force) 80 { 81 if( n == 0 ) 82 throw(SzMismatchError("TVector::Realloc() n = 0 ")); 83 uint_4 r,c; 84 if (lcv == SameTypeVector) lcv = GetVectorType(); 85 if (lcv == ColumnVector) { r = n; c = 1; } 86 else { c = n; r = 1; } 87 TMatrix<T>::Realloc(r,c,SameMemoryMapping,force); 88 } 89 90 // $CHECK$ Reza 03/2000 Doit-on declarer cette methode const ? 91 template <class T> 92 TVector<T> TVector<T>::operator () (Range relt) const 93 { 94 Range rr, cr; 95 if (GetVectorType() == ColumnVector ) rr = relt; 96 else cr = relt; 97 TMatrix<T> const & mtx = (*this); 98 TVector sv( mtx(rr, cr) , true, GetVectorType(), GetMemoryMapping() ); 99 sv.SetTemp(true); 100 return(sv); 101 } 102 103 template <class T> 104 T TVector<T>::Norm2() const 105 { 106 T ret = 0; 107 for(uint_8 k=0; k<Size(); k++) ret += (*this)(k)*(*this)(k); 108 return ret; 48 109 } 49 110 50 111 51 ///////////////////////////////////////////////////////////52 // --------------------------------------------------------53 // Les objets delegues pour la gestion de persistance54 // --------------------------------------------------------55 ///////////////////////////////////////////////////////////56 57 template <class T>58 FIO_TVector<T>::FIO_TVector()59 {60 dobj=new TVector<T>;61 ownobj=true;62 }63 64 template <class T>65 FIO_TVector<T>::FIO_TVector(string const & filename)66 {67 dobj=new TVector<T>;68 ownobj=true;69 Read(filename);70 }71 72 template <class T>73 FIO_TVector<T>::FIO_TVector(const TVector<T> & obj)74 {75 dobj = new TVector<T>(obj);76 ownobj=true;77 }78 79 template <class T>80 FIO_TVector<T>::FIO_TVector(TVector<T> * obj)81 {82 dobj = obj;83 ownobj=false;84 }85 86 template <class T>87 FIO_TVector<T>::~FIO_TVector()88 {89 if (ownobj && dobj) delete dobj;90 }91 92 template <class T>93 AnyDataObj* FIO_TVector<T>::DataObj()94 {95 return(dobj);96 }97 98 template <class T>99 void FIO_TVector<T>::SetDataObj(AnyDataObj & o)100 {101 TVector<T> * po = dynamic_cast< TVector<T> * >(&o);102 if (po == NULL) return;103 if (ownobj && dobj) delete dobj;104 dobj = po; ownobj = false;105 }106 107 template <class T>108 void FIO_TVector<T>::ReadSelf(PInPersist& is)109 {110 // On lit les 3 premiers uint_4111 // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1112 uint_4 itab[3];113 is.Get(itab,3);114 if (dobj == NULL) dobj = new TVector<T>(itab[1]);115 else dobj->ReSize(itab[1]);116 // On lit le NDataBlock117 FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());118 fio_nd.Read(is);119 }120 121 template <class T>122 void FIO_TVector<T>::WriteSelf(POutPersist& os) const123 {124 if (dobj == NULL) return;125 // On ecrit 3 uint_4 ....126 // 0: Numero de version, 1 : NRows=NElts, 2 : NCol=1127 uint_4 itab[3];128 itab[0] = 1; // Numero de version a 1129 itab[1] = dobj->NElts();130 itab[2] = 1;131 os.Put(itab,3);132 // On ecrit le NDataBlock133 FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());134 fio_nd.Write(os);135 }136 137 112 /////////////////////////////////////////////////////////////// 138 113 #ifdef __CXX_PRAGMA_TEMPLATES__ 139 #pragma define_template TVector<uint_1>140 114 #pragma define_template TVector<uint_2> 141 #pragma define_template TVector<int_2>142 115 #pragma define_template TVector<int_4> 143 116 #pragma define_template TVector<int_8> 144 #pragma define_template TVector<uint_4>145 #pragma define_template TVector<uint_8>146 117 #pragma define_template TVector<r_4> 147 118 #pragma define_template TVector<r_8> 148 119 #pragma define_template TVector< complex<r_4> > 149 120 #pragma define_template TVector< complex<r_8> > 150 // Instances des delegues FileIO (PPersist)151 #pragma define_template FIO_TVector<uint_1>152 #pragma define_template FIO_TVector<uint_2>153 #pragma define_template FIO_TVector<int_2>154 #pragma define_template FIO_TVector<int_4>155 #pragma define_template FIO_TVector<int_8>156 #pragma define_template FIO_TVector<uint_4>157 #pragma define_template FIO_TVector<uint_8>158 #pragma define_template FIO_TVector<r_8>159 #pragma define_template FIO_TVector<r_4>160 #pragma define_template FIO_TVector< complex<r_4> >161 #pragma define_template FIO_TVector< complex<r_8> >162 121 #endif 163 122 164 123 #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) 165 template class TVector<uint_1>;166 124 template class TVector<uint_2>; 167 template class TVector<int_2>;168 125 template class TVector<int_4>; 169 126 template class TVector<int_8>; 170 template class TVector<uint_4>;171 template class TVector<uint_8>;172 127 template class TVector<r_4>; 173 128 template class TVector<r_8>; 174 129 template class TVector< complex<r_4> >; 175 130 template class TVector< complex<r_8> >; 176 // Instances des delegues FileIO (PPersist)177 template class FIO_TVector<uint_1>;178 template class FIO_TVector<uint_2>;179 template class FIO_TVector<int_2>;180 template class FIO_TVector<int_4>;181 template class FIO_TVector<int_8>;182 template class FIO_TVector<uint_4>;183 template class FIO_TVector<uint_8>;184 template class FIO_TVector<r_8>;185 template class FIO_TVector<r_4>;186 template class FIO_TVector< complex<r_4> >;187 template class FIO_TVector< complex<r_8> >;188 131 #endif 132
Note:
See TracChangeset
for help on using the changeset viewer.