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

Last change on this file since 3810 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
Line 
1// Persistence manager for template numerical arrays
2// R. Ansari, C.Magneville 03/2000
3
4#include "sopnamsp.h"
5#include "pexceptions.h"
6#include "fiondblock.h"
7#include "fioarr.h"
8#include "tmatrix.h"
9#include "tvector.h"
10#include "datatype.h"
11#include <typeinfo>
12
13// --------------------------------------------------------
14// Les objets delegues pour la gestion de persistance
15// --------------------------------------------------------
16namespace SOPHYA {
17
18/*!
19 \class FIO_TArray
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 */
26///////////////////////////////////////////////////////////
27
28//! Default constructor
29template <class T>
30FIO_TArray<T>::FIO_TArray()
31{
32 dobj=NULL;
33 ownobj=false;
34}
35
36
37//! Constructor from the file \b filename
38template <class T>
39FIO_TArray<T>::FIO_TArray(string const & filename)
40{
41 dobj=NULL;
42 ownobj=false;
43 Read(filename);
44}
45
46//! Constructor from the TArray \b obj
47template <class T>
48FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
49{
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 }
57 ownobj=true;
58}
59
60//! Connect with a TArray \b obj
61template <class T>
62FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
63{
64 dobj = obj;
65 ownobj=false;
66}
67
68//! destructor
69template <class T>
70FIO_TArray<T>::~FIO_TArray()
71{
72 if (ownobj && dobj) delete dobj;
73}
74
75//! Return pointer to the connected TArray
76template <class T>
77AnyDataObj* FIO_TArray<T>::DataObj()
78{
79 return(dobj);
80}
81
82//! Connect TArray \b o
83template <class T>
84void FIO_TArray<T>::SetDataObj(AnyDataObj & o)
85{
86 TArray<T> * po = dynamic_cast< TArray<T> * >(&o);
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 }
93 if (ownobj && dobj) delete dobj;
94 dobj = po; ownobj = false;
95}
96
97template <class T>
98void FIO_TArray<T>::ReadSelf(PInPersist& is)
99{
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
103 uint_4 itab[5];
104 is.Get(itab,5);
105
106 // Checking version number
107 if (itab[0] < 2)
108 FileFormatExc("FIO_TArray<T>::ReadSelf() - Unsupported (old V<2) version");
109
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 }
115// On lit les tailles, etc ...
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];
128 int kk;
129
130 is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
131 for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
132 dobj->size_[kk] = tmpi8s[kk];
133 is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
134 for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
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
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;
154// On ecrit 5 uint_4 ....
155// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
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
166 uint_4 itab[5];
167 itab[0] = 2; // Numero de version a 2 depuis Aout 2000 - Reza
168 itab[1] = typa; // Real object type
169 itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
170 itab[3] = itab[4] = 0;
171 os.Put(itab,5);
172
173// On ecrit les tailles, etc ...
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];
189 int kk;
190 // os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
191 for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
192 tmpi8s[kk] = dobj->size_[kk];
193 os.Put(tmpi8s, BASEARRAY_MAXNDIMS);
194 // os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
195 for(kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
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
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)
221#pragma define_template FIO_TArray<uint_1>
222#pragma define_template FIO_TArray<uint_2>
223#pragma define_template FIO_TArray<uint_4>
224#pragma define_template FIO_TArray<uint_8>
225#pragma define_template FIO_TArray<int_1>
226#pragma define_template FIO_TArray<int_2>
227#pragma define_template FIO_TArray<int_4>
228#pragma define_template FIO_TArray<int_8>
229#pragma define_template FIO_TArray<r_4>
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> >
233#ifdef SO_LDBLE128
234#pragma define_template FIO_TArray<r_16>
235#pragma define_template FIO_TArray< complex<r_16> >
236#endif
237#endif
238
239#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
240// Instances des delegues FileIO (PPersist)
241template class FIO_TArray<uint_1>;
242template class FIO_TArray<uint_2>;
243template class FIO_TArray<uint_4>;
244template class FIO_TArray<uint_8>;
245template class FIO_TArray<int_1>;
246template class FIO_TArray<int_2>;
247template class FIO_TArray<int_4>;
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> >;
253#ifdef SO_LDBLE128
254template class FIO_TArray<r_16>;
255template class FIO_TArray< complex<r_16> >;
256#endif
257#endif
258
259} // FIN namespace SOPHYA
Note: See TracBrowser for help on using the repository browser.