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