[772] | 1 | // Persistence manager for template numerical arrays
|
---|
| 2 | // R. Ansari, C.Magneville 03/2000
|
---|
| 3 |
|
---|
[2615] | 4 | #include "sopnamsp.h"
|
---|
[772] | 5 | #include "pexceptions.h"
|
---|
[804] | 6 | #include "fiondblock.h"
|
---|
[772] | 7 | #include "fioarr.h"
|
---|
[804] | 8 | #include "tmatrix.h"
|
---|
| 9 | #include "tvector.h"
|
---|
[1953] | 10 | #include "datatype.h"
|
---|
| 11 | #include <typeinfo>
|
---|
[772] | 12 |
|
---|
| 13 | // --------------------------------------------------------
|
---|
| 14 | // Les objets delegues pour la gestion de persistance
|
---|
| 15 | // --------------------------------------------------------
|
---|
[3751] | 16 | namespace SOPHYA {
|
---|
| 17 |
|
---|
[926] | 18 | /*!
|
---|
[3751] | 19 | \class FIO_TArray
|
---|
[926] | 20 | \ingroup TArray
|
---|
| 21 | Class for persistent management of TArray
|
---|
| 22 |
|
---|
| 23 | This class manage also persistence for TMatrix and TVector.
|
---|
| 24 | \sa TArray TMatrix TVector.
|
---|
| 25 | */
|
---|
[772] | 26 | ///////////////////////////////////////////////////////////
|
---|
| 27 |
|
---|
[894] | 28 | //! Default constructor
|
---|
[772] | 29 | template <class T>
|
---|
| 30 | FIO_TArray<T>::FIO_TArray()
|
---|
| 31 | {
|
---|
[804] | 32 | dobj=NULL;
|
---|
| 33 | ownobj=false;
|
---|
[772] | 34 | }
|
---|
| 35 |
|
---|
[894] | 36 |
|
---|
| 37 | //! Constructor from the file \b filename
|
---|
[772] | 38 | template <class T>
|
---|
| 39 | FIO_TArray<T>::FIO_TArray(string const & filename)
|
---|
| 40 | {
|
---|
[804] | 41 | dobj=NULL;
|
---|
| 42 | ownobj=false;
|
---|
[772] | 43 | Read(filename);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[894] | 46 | //! Constructor from the TArray \b obj
|
---|
[772] | 47 | template <class T>
|
---|
| 48 | FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
|
---|
| 49 | {
|
---|
[804] | 50 | const TVector<T> * tv = dynamic_cast<const TVector<T> *>(&obj);
|
---|
| 51 | if (tv != NULL) dobj = new TVector<T>(*tv, true);
|
---|
| 52 | else {
|
---|
| 53 | const TMatrix<T> * tm = dynamic_cast<const TMatrix<T> *>(&obj);
|
---|
| 54 | if (tm != NULL) dobj = new TMatrix<T>(*tm, true);
|
---|
| 55 | else dobj = new TArray<T>(obj, true);
|
---|
| 56 | }
|
---|
[772] | 57 | ownobj=true;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[894] | 60 | //! Connect with a TArray \b obj
|
---|
[772] | 61 | template <class T>
|
---|
| 62 | FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
|
---|
| 63 | {
|
---|
| 64 | dobj = obj;
|
---|
| 65 | ownobj=false;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[894] | 68 | //! destructor
|
---|
[772] | 69 | template <class T>
|
---|
| 70 | FIO_TArray<T>::~FIO_TArray()
|
---|
| 71 | {
|
---|
| 72 | if (ownobj && dobj) delete dobj;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[894] | 75 | //! Return pointer to the connected TArray
|
---|
[772] | 76 | template <class T>
|
---|
| 77 | AnyDataObj* FIO_TArray<T>::DataObj()
|
---|
| 78 | {
|
---|
| 79 | return(dobj);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[894] | 82 | //! Connect TArray \b o
|
---|
[772] | 83 | template <class T>
|
---|
| 84 | void FIO_TArray<T>::SetDataObj(AnyDataObj & o)
|
---|
| 85 | {
|
---|
| 86 | TArray<T> * po = dynamic_cast< TArray<T> * >(&o);
|
---|
[1953] | 87 | if (po == NULL) {
|
---|
| 88 | char buff[160];
|
---|
| 89 | sprintf(buff,"FIO_TArray<%s>::SetDataObj(%s) - Object type error ! ",
|
---|
| 90 | DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
|
---|
| 91 | throw TypeMismatchExc(PExcLongMessage(buff));
|
---|
| 92 | }
|
---|
[772] | 93 | if (ownobj && dobj) delete dobj;
|
---|
| 94 | dobj = po; ownobj = false;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | template <class T>
|
---|
| 98 | void FIO_TArray<T>::ReadSelf(PInPersist& is)
|
---|
| 99 | {
|
---|
[804] | 100 | // On lit les 5 premiers uint_4
|
---|
| 101 | // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
|
---|
| 102 | // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
|
---|
[772] | 103 | uint_4 itab[5];
|
---|
| 104 | is.Get(itab,5);
|
---|
[1156] | 105 |
|
---|
| 106 | // Checking version number
|
---|
| 107 | if (itab[0] < 2)
|
---|
| 108 | FileFormatExc("FIO_TArray<T>::ReadSelf() - Unsupported (old V<2) version");
|
---|
| 109 |
|
---|
[804] | 110 | if (dobj == NULL) {
|
---|
| 111 | if (itab[1] == 12) dobj = new TMatrix<T>;
|
---|
| 112 | else if (itab[1] == 48) dobj = new TVector<T>;
|
---|
| 113 | else dobj = new TArray<T>;
|
---|
| 114 | }
|
---|
[772] | 115 | // On lit les tailles, etc ...
|
---|
[1156] | 116 | // On ecrit les tailles, etc ...
|
---|
| 117 | int_4 tmpi4s[5];
|
---|
| 118 | is.Get(tmpi4s, 5);
|
---|
| 119 | dobj->ndim_ = tmpi4s[0];
|
---|
| 120 | dobj->marowi_ = tmpi4s[1];
|
---|
| 121 | dobj->macoli_ = tmpi4s[2];
|
---|
| 122 | dobj->veceli_ = tmpi4s[3];
|
---|
| 123 | // tmpi4s[4] Reserved for future use
|
---|
| 124 |
|
---|
| 125 | // Tous les sa_size_t sont ecrit/lu en int_8 afin de maintenir la compatibilite
|
---|
| 126 | // entre version du programme utilisant int_4 OU int_8 pour sa_size_t
|
---|
| 127 | int_8 tmpi8s[BASEARRAY_MAXNDIMS];
|
---|
[1173] | 128 | int kk;
|
---|
[1156] | 129 |
|
---|
| 130 | is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
|
---|
[1173] | 131 | for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
|
---|
[1156] | 132 | dobj->size_[kk] = tmpi8s[kk];
|
---|
| 133 | is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
|
---|
[1173] | 134 | for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
|
---|
[1156] | 135 | dobj->step_[kk] = tmpi8s[kk];
|
---|
| 136 |
|
---|
| 137 | is.Get(tmpi8s, 5);
|
---|
| 138 | dobj->totsize_ = tmpi8s[0];
|
---|
| 139 | dobj->offset_ = tmpi8s[1];
|
---|
| 140 | dobj->minstep_ = tmpi8s[2];
|
---|
| 141 | dobj->moystep_ = tmpi8s[3];
|
---|
| 142 | // tmpi8s[4] Reserved for future use
|
---|
| 143 |
|
---|
[772] | 144 | // On lit le datablock
|
---|
| 145 | is >> dobj->DataBlock();
|
---|
| 146 | // On ecrit le DVList info si necessaire
|
---|
| 147 | if (itab[2] != 0) is >> dobj->Info();
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | template <class T>
|
---|
| 151 | void FIO_TArray<T>::WriteSelf(POutPersist& os) const
|
---|
| 152 | {
|
---|
| 153 | if (dobj == NULL) return;
|
---|
[804] | 154 | // On ecrit 5 uint_4 ....
|
---|
[772] | 155 | // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
|
---|
[804] | 156 | // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
|
---|
| 157 | uint_4 typa = 0;
|
---|
| 158 | TVector<T> * tv = dynamic_cast<TVector<T> *>(dobj);
|
---|
| 159 | if (tv != NULL) typa = 48;
|
---|
| 160 | else {
|
---|
| 161 | TMatrix<T> * tm = dynamic_cast<TMatrix<T> *>(dobj);
|
---|
| 162 | if (tm != NULL) typa = 12;
|
---|
| 163 | else typa = 0;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
[772] | 166 | uint_4 itab[5];
|
---|
[1156] | 167 | itab[0] = 2; // Numero de version a 2 depuis Aout 2000 - Reza
|
---|
[804] | 168 | itab[1] = typa; // Real object type
|
---|
[772] | 169 | itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
|
---|
| 170 | itab[3] = itab[4] = 0;
|
---|
[804] | 171 | os.Put(itab,5);
|
---|
[1156] | 172 |
|
---|
[772] | 173 | // On ecrit les tailles, etc ...
|
---|
[1156] | 174 | int_4 tmpi4s[5];
|
---|
| 175 | // os.Put(dobj->ndim_);
|
---|
| 176 | // os.Put(dobj->marowi_);
|
---|
| 177 | // os.Put(dobj->macoli_);
|
---|
| 178 | // os.Put(dobj->veceli_);
|
---|
| 179 | tmpi4s[0] = dobj->ndim_;
|
---|
| 180 | tmpi4s[1] = dobj->marowi_;
|
---|
| 181 | tmpi4s[2] = dobj->macoli_;
|
---|
| 182 | tmpi4s[3] = dobj->veceli_;
|
---|
| 183 | tmpi4s[4] = 0; // Reserved for future use
|
---|
| 184 | os.Put(tmpi4s, 5);
|
---|
| 185 |
|
---|
| 186 | // Tous les sa_size_t sont ecrit en int_8 afin de pouvoir etre ecrit/relu
|
---|
| 187 | // entre version du programme utilisant int_4 OU int_8 pour sa_size_t
|
---|
| 188 | int_8 tmpi8s[BASEARRAY_MAXNDIMS];
|
---|
[1173] | 189 | int kk;
|
---|
[1156] | 190 | // os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
|
---|
[1173] | 191 | for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
|
---|
[1156] | 192 | tmpi8s[kk] = dobj->size_[kk];
|
---|
| 193 | os.Put(tmpi8s, BASEARRAY_MAXNDIMS);
|
---|
| 194 | // os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
|
---|
[1173] | 195 | for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
|
---|
[1156] | 196 | tmpi8s[kk] = dobj->step_[kk];
|
---|
| 197 | os.Put(tmpi8s, BASEARRAY_MAXNDIMS);
|
---|
| 198 |
|
---|
| 199 | // os.Put(dobj->totsize_);
|
---|
| 200 | // os.Put(dobj->offset_);
|
---|
| 201 | // os.Put(dobj->minstep_);
|
---|
| 202 | // os.Put(dobj->moystep_);
|
---|
| 203 | tmpi8s[0] = dobj->totsize_;
|
---|
| 204 | tmpi8s[1] = dobj->offset_;
|
---|
| 205 | tmpi8s[2] = dobj->minstep_;
|
---|
| 206 | tmpi8s[3] = dobj->moystep_;
|
---|
| 207 | tmpi8s[4] = 0; // Reserved for future use
|
---|
| 208 | os.Put(tmpi8s, 5);
|
---|
| 209 |
|
---|
[772] | 210 | // On ecrit le datablock
|
---|
| 211 | os << dobj->DataBlock();
|
---|
| 212 | // On ecrit le DVList info si necessaire
|
---|
| 213 | if (itab[2] != 0) os << dobj->Info();
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 |
|
---|
| 217 |
|
---|
| 218 | ///////////////////////////////////////////////////////////////
|
---|
| 219 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 220 | // Instances des delegues FileIO (PPersist)
|
---|
[3661] | 221 | #pragma define_template FIO_TArray<uint_1>
|
---|
[772] | 222 | #pragma define_template FIO_TArray<uint_2>
|
---|
[2927] | 223 | #pragma define_template FIO_TArray<uint_4>
|
---|
| 224 | #pragma define_template FIO_TArray<uint_8>
|
---|
[3661] | 225 | #pragma define_template FIO_TArray<int_1>
|
---|
[2927] | 226 | #pragma define_template FIO_TArray<int_2>
|
---|
[772] | 227 | #pragma define_template FIO_TArray<int_4>
|
---|
| 228 | #pragma define_template FIO_TArray<int_8>
|
---|
[3751] | 229 | #pragma define_template FIO_TArray<r_4>
|
---|
[772] | 230 | #pragma define_template FIO_TArray<r_8>
|
---|
| 231 | #pragma define_template FIO_TArray< complex<r_4> >
|
---|
| 232 | #pragma define_template FIO_TArray< complex<r_8> >
|
---|
[3751] | 233 | #ifdef SO_LDBLE128
|
---|
| 234 | #pragma define_template FIO_TArray<r_16>
|
---|
| 235 | #pragma define_template FIO_TArray< complex<r_16> >
|
---|
[772] | 236 | #endif
|
---|
[3751] | 237 | #endif
|
---|
[772] | 238 |
|
---|
| 239 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
| 240 | // Instances des delegues FileIO (PPersist)
|
---|
[3661] | 241 | template class FIO_TArray<uint_1>;
|
---|
[772] | 242 | template class FIO_TArray<uint_2>;
|
---|
[2927] | 243 | template class FIO_TArray<uint_4>;
|
---|
| 244 | template class FIO_TArray<uint_8>;
|
---|
[3661] | 245 | template class FIO_TArray<int_1>;
|
---|
[2927] | 246 | template class FIO_TArray<int_2>;
|
---|
[818] | 247 | template class FIO_TArray<int_4>;
|
---|
[772] | 248 | template class FIO_TArray<int_8>;
|
---|
| 249 | template class FIO_TArray<r_8>;
|
---|
| 250 | template class FIO_TArray<r_4>;
|
---|
| 251 | template class FIO_TArray< complex<r_4> >;
|
---|
| 252 | template class FIO_TArray< complex<r_8> >;
|
---|
[3751] | 253 | #ifdef SO_LDBLE128
|
---|
| 254 | template class FIO_TArray<r_16>;
|
---|
| 255 | template class FIO_TArray< complex<r_16> >;
|
---|
[772] | 256 | #endif
|
---|
[3751] | 257 | #endif
|
---|
| 258 |
|
---|
| 259 | } // FIN namespace SOPHYA
|
---|