source: Sophya/trunk/SophyaLib/TArray/fioarr.cc@ 3835

Last change on this file since 3835 was 3751, checked in by ansari, 16 years ago

Prise en charge de float 128 bits (r_16, complex<r_16>) par TArray<T>,TMatrix<T>,TVector<T>. activation par le flag de compilation SO_LDBLE128

File size: 7.1 KB
RevLine 
[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]16namespace 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]29template <class T>
30FIO_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]38template <class T>
39FIO_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]47template <class T>
48FIO_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]61template <class T>
62FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
63{
64 dobj = obj;
65 ownobj=false;
66}
67
[894]68//! destructor
[772]69template <class T>
70FIO_TArray<T>::~FIO_TArray()
71{
72 if (ownobj && dobj) delete dobj;
73}
74
[894]75//! Return pointer to the connected TArray
[772]76template <class T>
77AnyDataObj* FIO_TArray<T>::DataObj()
78{
79 return(dobj);
80}
81
[894]82//! Connect TArray \b o
[772]83template <class T>
84void 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
97template <class T>
98void 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
150template <class T>
151void 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]241template class FIO_TArray<uint_1>;
[772]242template class FIO_TArray<uint_2>;
[2927]243template class FIO_TArray<uint_4>;
244template class FIO_TArray<uint_8>;
[3661]245template class FIO_TArray<int_1>;
[2927]246template class FIO_TArray<int_2>;
[818]247template class FIO_TArray<int_4>;
[772]248template class FIO_TArray<int_8>;
249template class FIO_TArray<r_8>;
250template class FIO_TArray<r_4>;
251template class FIO_TArray< complex<r_4> >;
252template class FIO_TArray< complex<r_8> >;
[3751]253#ifdef SO_LDBLE128
254template class FIO_TArray<r_16>;
255template class FIO_TArray< complex<r_16> >;
[772]256#endif
[3751]257#endif
258
259} // FIN namespace SOPHYA
Note: See TracBrowser for help on using the repository browser.