[772] | 1 | // Persistence manager for template numerical arrays
|
---|
| 2 | // R. Ansari, C.Magneville 03/2000
|
---|
| 3 |
|
---|
| 4 | #include "pexceptions.h"
|
---|
[804] | 5 | #include "fiondblock.h"
|
---|
[772] | 6 | #include "fioarr.h"
|
---|
[804] | 7 | #include "tmatrix.h"
|
---|
| 8 | #include "tvector.h"
|
---|
[772] | 9 |
|
---|
| 10 | // --------------------------------------------------------
|
---|
| 11 | // Les objets delegues pour la gestion de persistance
|
---|
| 12 | // --------------------------------------------------------
|
---|
| 13 | ///////////////////////////////////////////////////////////
|
---|
| 14 |
|
---|
[894] | 15 | //! Default constructor
|
---|
[772] | 16 | template <class T>
|
---|
| 17 | FIO_TArray<T>::FIO_TArray()
|
---|
| 18 | {
|
---|
[804] | 19 | dobj=NULL;
|
---|
| 20 | ownobj=false;
|
---|
[772] | 21 | }
|
---|
| 22 |
|
---|
[894] | 23 |
|
---|
| 24 | //! Constructor from the file \b filename
|
---|
[772] | 25 | template <class T>
|
---|
| 26 | FIO_TArray<T>::FIO_TArray(string const & filename)
|
---|
| 27 | {
|
---|
[804] | 28 | dobj=NULL;
|
---|
| 29 | ownobj=false;
|
---|
[772] | 30 | Read(filename);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[894] | 33 | //! Constructor from the TArray \b obj
|
---|
[772] | 34 | template <class T>
|
---|
| 35 | FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
|
---|
| 36 | {
|
---|
[804] | 37 | const TVector<T> * tv = dynamic_cast<const TVector<T> *>(&obj);
|
---|
| 38 | if (tv != NULL) dobj = new TVector<T>(*tv, true);
|
---|
| 39 | else {
|
---|
| 40 | const TMatrix<T> * tm = dynamic_cast<const TMatrix<T> *>(&obj);
|
---|
| 41 | if (tm != NULL) dobj = new TMatrix<T>(*tm, true);
|
---|
| 42 | else dobj = new TArray<T>(obj, true);
|
---|
| 43 | }
|
---|
[772] | 44 | ownobj=true;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[894] | 47 | //! Connect with a TArray \b obj
|
---|
[772] | 48 | template <class T>
|
---|
| 49 | FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
|
---|
| 50 | {
|
---|
| 51 | dobj = obj;
|
---|
| 52 | ownobj=false;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[894] | 55 | //! destructor
|
---|
[772] | 56 | template <class T>
|
---|
| 57 | FIO_TArray<T>::~FIO_TArray()
|
---|
| 58 | {
|
---|
| 59 | if (ownobj && dobj) delete dobj;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[894] | 62 | //! Return pointer to the connected TArray
|
---|
[772] | 63 | template <class T>
|
---|
| 64 | AnyDataObj* FIO_TArray<T>::DataObj()
|
---|
| 65 | {
|
---|
| 66 | return(dobj);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[894] | 69 | //! Connect TArray \b o
|
---|
[772] | 70 | template <class T>
|
---|
| 71 | void FIO_TArray<T>::SetDataObj(AnyDataObj & o)
|
---|
| 72 | {
|
---|
| 73 | TArray<T> * po = dynamic_cast< TArray<T> * >(&o);
|
---|
| 74 | if (po == NULL) return;
|
---|
| 75 | if (ownobj && dobj) delete dobj;
|
---|
| 76 | dobj = po; ownobj = false;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | template <class T>
|
---|
| 80 | void FIO_TArray<T>::ReadSelf(PInPersist& is)
|
---|
| 81 | {
|
---|
[804] | 82 | // On lit les 5 premiers uint_4
|
---|
| 83 | // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
|
---|
| 84 | // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
|
---|
[772] | 85 | uint_4 itab[5];
|
---|
| 86 | is.Get(itab,5);
|
---|
[804] | 87 | if (dobj == NULL) {
|
---|
| 88 | if (itab[1] == 12) dobj = new TMatrix<T>;
|
---|
| 89 | else if (itab[1] == 48) dobj = new TVector<T>;
|
---|
| 90 | else dobj = new TArray<T>;
|
---|
| 91 | }
|
---|
[772] | 92 | // On lit les tailles, etc ...
|
---|
| 93 | is.Get(dobj->ndim_);
|
---|
[787] | 94 | is.Get(dobj->size_, BASEARRAY_MAXNDIMS);
|
---|
[772] | 95 | is.Get(dobj->totsize_);
|
---|
[787] | 96 | is.Get(dobj->step_, BASEARRAY_MAXNDIMS);
|
---|
[772] | 97 | is.Get(dobj->minstep_);
|
---|
[785] | 98 | is.Get(dobj->moystep_);
|
---|
[772] | 99 | is.Get(dobj->offset_);
|
---|
| 100 | is.Get(dobj->marowi_);
|
---|
| 101 | is.Get(dobj->macoli_);
|
---|
[804] | 102 | is.Get(dobj->veceli_);
|
---|
[772] | 103 | // On lit le datablock
|
---|
| 104 | is >> dobj->DataBlock();
|
---|
| 105 | // On ecrit le DVList info si necessaire
|
---|
| 106 | if (itab[2] != 0) is >> dobj->Info();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | template <class T>
|
---|
| 110 | void FIO_TArray<T>::WriteSelf(POutPersist& os) const
|
---|
| 111 | {
|
---|
| 112 | if (dobj == NULL) return;
|
---|
[804] | 113 | // On ecrit 5 uint_4 ....
|
---|
[772] | 114 | // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
|
---|
[804] | 115 | // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
|
---|
| 116 | uint_4 typa = 0;
|
---|
| 117 | TVector<T> * tv = dynamic_cast<TVector<T> *>(dobj);
|
---|
| 118 | if (tv != NULL) typa = 48;
|
---|
| 119 | else {
|
---|
| 120 | TMatrix<T> * tm = dynamic_cast<TMatrix<T> *>(dobj);
|
---|
| 121 | if (tm != NULL) typa = 12;
|
---|
| 122 | else typa = 0;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[772] | 125 | uint_4 itab[5];
|
---|
| 126 | itab[0] = 1; // Numero de version a 1
|
---|
[804] | 127 | itab[1] = typa; // Real object type
|
---|
[772] | 128 | itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
|
---|
| 129 | itab[3] = itab[4] = 0;
|
---|
[804] | 130 | os.Put(itab,5);
|
---|
[772] | 131 | // On ecrit les tailles, etc ...
|
---|
| 132 | os.Put(dobj->ndim_);
|
---|
[787] | 133 | os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
|
---|
[772] | 134 | os.Put(dobj->totsize_);
|
---|
[787] | 135 | os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
|
---|
[772] | 136 | os.Put(dobj->minstep_);
|
---|
[785] | 137 | os.Put(dobj->moystep_);
|
---|
[772] | 138 | os.Put(dobj->offset_);
|
---|
| 139 | os.Put(dobj->marowi_);
|
---|
| 140 | os.Put(dobj->macoli_);
|
---|
[804] | 141 | os.Put(dobj->veceli_);
|
---|
[772] | 142 | // On ecrit le datablock
|
---|
| 143 | os << dobj->DataBlock();
|
---|
| 144 | // On ecrit le DVList info si necessaire
|
---|
| 145 | if (itab[2] != 0) os << dobj->Info();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | ///////////////////////////////////////////////////////////////
|
---|
| 151 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 152 | // Instances des delegues FileIO (PPersist)
|
---|
[804] | 153 | // #pragma define_template FIO_TArray<uint_1>
|
---|
[772] | 154 | #pragma define_template FIO_TArray<uint_2>
|
---|
[804] | 155 | // #pragma define_template FIO_TArray<int_2>
|
---|
[772] | 156 | #pragma define_template FIO_TArray<int_4>
|
---|
| 157 | #pragma define_template FIO_TArray<int_8>
|
---|
[804] | 158 | // #pragma define_template FIO_TArray<uint_4>
|
---|
| 159 | // #pragma define_template FIO_TArray<uint_8>
|
---|
[772] | 160 | #pragma define_template FIO_TArray<r_8>
|
---|
| 161 | #pragma define_template FIO_TArray<r_4>
|
---|
| 162 | #pragma define_template FIO_TArray< complex<r_4> >
|
---|
| 163 | #pragma define_template FIO_TArray< complex<r_8> >
|
---|
| 164 | #endif
|
---|
| 165 |
|
---|
| 166 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 167 | // Instances des delegues FileIO (PPersist)
|
---|
[804] | 168 | // template class FIO_TArray<uint_1>;
|
---|
[772] | 169 | template class FIO_TArray<uint_2>;
|
---|
[804] | 170 | // template class FIO_TArray<int_2>;
|
---|
[818] | 171 | template class FIO_TArray<int_4>;
|
---|
[772] | 172 | template class FIO_TArray<int_8>;
|
---|
[804] | 173 | // template class FIO_TArray<uint_4>;
|
---|
| 174 | // template class FIO_TArray<uint_8>;
|
---|
[772] | 175 | template class FIO_TArray<r_8>;
|
---|
| 176 | template class FIO_TArray<r_4>;
|
---|
| 177 | template class FIO_TArray< complex<r_4> >;
|
---|
| 178 | template class FIO_TArray< complex<r_8> >;
|
---|
| 179 | #endif
|
---|