| 1 | // Persistence manager for template numerical arrays
|
|---|
| 2 | // R. Ansari, C.Magneville 03/2000
|
|---|
| 3 |
|
|---|
| 4 | #include "pexceptions.h"
|
|---|
| 5 | #include "fiondblock.h"
|
|---|
| 6 | #include "fioarr.h"
|
|---|
| 7 | #include "tmatrix.h"
|
|---|
| 8 | #include "tvector.h"
|
|---|
| 9 |
|
|---|
| 10 | // --------------------------------------------------------
|
|---|
| 11 | // Les objets delegues pour la gestion de persistance
|
|---|
| 12 | // --------------------------------------------------------
|
|---|
| 13 | ///////////////////////////////////////////////////////////
|
|---|
| 14 |
|
|---|
| 15 | //! Default constructor
|
|---|
| 16 | template <class T>
|
|---|
| 17 | FIO_TArray<T>::FIO_TArray()
|
|---|
| 18 | {
|
|---|
| 19 | dobj=NULL;
|
|---|
| 20 | ownobj=false;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | //! Constructor from the file \b filename
|
|---|
| 25 | template <class T>
|
|---|
| 26 | FIO_TArray<T>::FIO_TArray(string const & filename)
|
|---|
| 27 | {
|
|---|
| 28 | dobj=NULL;
|
|---|
| 29 | ownobj=false;
|
|---|
| 30 | Read(filename);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | //! Constructor from the TArray \b obj
|
|---|
| 34 | template <class T>
|
|---|
| 35 | FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
|
|---|
| 36 | {
|
|---|
| 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 | }
|
|---|
| 44 | ownobj=true;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | //! Connect with a TArray \b obj
|
|---|
| 48 | template <class T>
|
|---|
| 49 | FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
|
|---|
| 50 | {
|
|---|
| 51 | dobj = obj;
|
|---|
| 52 | ownobj=false;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | //! destructor
|
|---|
| 56 | template <class T>
|
|---|
| 57 | FIO_TArray<T>::~FIO_TArray()
|
|---|
| 58 | {
|
|---|
| 59 | if (ownobj && dobj) delete dobj;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | //! Return pointer to the connected TArray
|
|---|
| 63 | template <class T>
|
|---|
| 64 | AnyDataObj* FIO_TArray<T>::DataObj()
|
|---|
| 65 | {
|
|---|
| 66 | return(dobj);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | //! Connect TArray \b o
|
|---|
| 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 | {
|
|---|
| 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
|
|---|
| 85 | uint_4 itab[5];
|
|---|
| 86 | is.Get(itab,5);
|
|---|
| 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 | }
|
|---|
| 92 | // On lit les tailles, etc ...
|
|---|
| 93 | is.Get(dobj->ndim_);
|
|---|
| 94 | is.Get(dobj->size_, BASEARRAY_MAXNDIMS);
|
|---|
| 95 | is.Get(dobj->totsize_);
|
|---|
| 96 | is.Get(dobj->step_, BASEARRAY_MAXNDIMS);
|
|---|
| 97 | is.Get(dobj->minstep_);
|
|---|
| 98 | is.Get(dobj->moystep_);
|
|---|
| 99 | is.Get(dobj->offset_);
|
|---|
| 100 | is.Get(dobj->marowi_);
|
|---|
| 101 | is.Get(dobj->macoli_);
|
|---|
| 102 | is.Get(dobj->veceli_);
|
|---|
| 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;
|
|---|
| 113 | // On ecrit 5 uint_4 ....
|
|---|
| 114 | // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
|
|---|
| 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 |
|
|---|
| 125 | uint_4 itab[5];
|
|---|
| 126 | itab[0] = 1; // Numero de version a 1
|
|---|
| 127 | itab[1] = typa; // Real object type
|
|---|
| 128 | itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
|
|---|
| 129 | itab[3] = itab[4] = 0;
|
|---|
| 130 | os.Put(itab,5);
|
|---|
| 131 | // On ecrit les tailles, etc ...
|
|---|
| 132 | os.Put(dobj->ndim_);
|
|---|
| 133 | os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
|
|---|
| 134 | os.Put(dobj->totsize_);
|
|---|
| 135 | os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
|
|---|
| 136 | os.Put(dobj->minstep_);
|
|---|
| 137 | os.Put(dobj->moystep_);
|
|---|
| 138 | os.Put(dobj->offset_);
|
|---|
| 139 | os.Put(dobj->marowi_);
|
|---|
| 140 | os.Put(dobj->macoli_);
|
|---|
| 141 | os.Put(dobj->veceli_);
|
|---|
| 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)
|
|---|
| 153 | // #pragma define_template FIO_TArray<uint_1>
|
|---|
| 154 | #pragma define_template FIO_TArray<uint_2>
|
|---|
| 155 | // #pragma define_template FIO_TArray<int_2>
|
|---|
| 156 | #pragma define_template FIO_TArray<int_4>
|
|---|
| 157 | #pragma define_template FIO_TArray<int_8>
|
|---|
| 158 | // #pragma define_template FIO_TArray<uint_4>
|
|---|
| 159 | // #pragma define_template FIO_TArray<uint_8>
|
|---|
| 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)
|
|---|
| 168 | // template class FIO_TArray<uint_1>;
|
|---|
| 169 | template class FIO_TArray<uint_2>;
|
|---|
| 170 | // template class FIO_TArray<int_2>;
|
|---|
| 171 | template class FIO_TArray<int_4>;
|
|---|
| 172 | template class FIO_TArray<int_8>;
|
|---|
| 173 | // template class FIO_TArray<uint_4>;
|
|---|
| 174 | // template class FIO_TArray<uint_8>;
|
|---|
| 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
|
|---|