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

Last change on this file since 1156 was 1156, checked in by ansari, 25 years ago

Introduction du type sa_size_t (taille des tableaux), operateur - (TArray::operator - et NegateElt()) - Reza 29/8/2000

File size: 6.5 KB
Line 
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 \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 */
21///////////////////////////////////////////////////////////
22
23//! Default constructor
24template <class T>
25FIO_TArray<T>::FIO_TArray()
26{
27 dobj=NULL;
28 ownobj=false;
29}
30
31
32//! Constructor from the file \b filename
33template <class T>
34FIO_TArray<T>::FIO_TArray(string const & filename)
35{
36 dobj=NULL;
37 ownobj=false;
38 Read(filename);
39}
40
41//! Constructor from the TArray \b obj
42template <class T>
43FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
44{
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 }
52 ownobj=true;
53}
54
55//! Connect with a TArray \b obj
56template <class T>
57FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
58{
59 dobj = obj;
60 ownobj=false;
61}
62
63//! destructor
64template <class T>
65FIO_TArray<T>::~FIO_TArray()
66{
67 if (ownobj && dobj) delete dobj;
68}
69
70//! Return pointer to the connected TArray
71template <class T>
72AnyDataObj* FIO_TArray<T>::DataObj()
73{
74 return(dobj);
75}
76
77//! Connect TArray \b o
78template <class T>
79void 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
87template <class T>
88void FIO_TArray<T>::ReadSelf(PInPersist& is)
89{
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
93 uint_4 itab[5];
94 is.Get(itab,5);
95
96 // Checking version number
97 if (itab[0] < 2)
98 FileFormatExc("FIO_TArray<T>::ReadSelf() - Unsupported (old V<2) version");
99
100 if (dobj == NULL) {
101 if (itab[1] == 12) dobj = new TMatrix<T>;
102 else if (itab[1] == 48) dobj = new TVector<T>;
103 else dobj = new TArray<T>;
104 }
105// On lit les tailles, etc ...
106// On ecrit les tailles, etc ...
107 int_4 tmpi4s[5];
108 is.Get(tmpi4s, 5);
109 dobj->ndim_ = tmpi4s[0];
110 dobj->marowi_ = tmpi4s[1];
111 dobj->macoli_ = tmpi4s[2];
112 dobj->veceli_ = tmpi4s[3];
113// tmpi4s[4] Reserved for future use
114
115// Tous les sa_size_t sont ecrit/lu en int_8 afin de maintenir la compatibilite
116// entre version du programme utilisant int_4 OU int_8 pour sa_size_t
117 int_8 tmpi8s[BASEARRAY_MAXNDIMS];
118
119 is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
120 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
121 dobj->size_[kk] = tmpi8s[kk];
122 is.Get(tmpi8s, BASEARRAY_MAXNDIMS);
123 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
124 dobj->step_[kk] = tmpi8s[kk];
125
126 is.Get(tmpi8s, 5);
127 dobj->totsize_ = tmpi8s[0];
128 dobj->offset_ = tmpi8s[1];
129 dobj->minstep_ = tmpi8s[2];
130 dobj->moystep_ = tmpi8s[3];
131// tmpi8s[4] Reserved for future use
132
133// On lit le datablock
134 is >> dobj->DataBlock();
135// On ecrit le DVList info si necessaire
136 if (itab[2] != 0) is >> dobj->Info();
137}
138
139template <class T>
140void FIO_TArray<T>::WriteSelf(POutPersist& os) const
141{
142 if (dobj == NULL) return;
143// On ecrit 5 uint_4 ....
144// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
145// 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
146 uint_4 typa = 0;
147 TVector<T> * tv = dynamic_cast<TVector<T> *>(dobj);
148 if (tv != NULL) typa = 48;
149 else {
150 TMatrix<T> * tm = dynamic_cast<TMatrix<T> *>(dobj);
151 if (tm != NULL) typa = 12;
152 else typa = 0;
153 }
154
155 uint_4 itab[5];
156 itab[0] = 2; // Numero de version a 2 depuis Aout 2000 - Reza
157 itab[1] = typa; // Real object type
158 itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
159 itab[3] = itab[4] = 0;
160 os.Put(itab,5);
161
162// On ecrit les tailles, etc ...
163 int_4 tmpi4s[5];
164 // os.Put(dobj->ndim_);
165 // os.Put(dobj->marowi_);
166 // os.Put(dobj->macoli_);
167 // os.Put(dobj->veceli_);
168 tmpi4s[0] = dobj->ndim_;
169 tmpi4s[1] = dobj->marowi_;
170 tmpi4s[2] = dobj->macoli_;
171 tmpi4s[3] = dobj->veceli_;
172 tmpi4s[4] = 0; // Reserved for future use
173 os.Put(tmpi4s, 5);
174
175// Tous les sa_size_t sont ecrit en int_8 afin de pouvoir etre ecrit/relu
176// entre version du programme utilisant int_4 OU int_8 pour sa_size_t
177 int_8 tmpi8s[BASEARRAY_MAXNDIMS];
178
179 // os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
180 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
181 tmpi8s[kk] = dobj->size_[kk];
182 os.Put(tmpi8s, BASEARRAY_MAXNDIMS);
183 // os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
184 for(int kk=0; kk<BASEARRAY_MAXNDIMS; kk++)
185 tmpi8s[kk] = dobj->step_[kk];
186 os.Put(tmpi8s, BASEARRAY_MAXNDIMS);
187
188 // os.Put(dobj->totsize_);
189 // os.Put(dobj->offset_);
190 // os.Put(dobj->minstep_);
191 // os.Put(dobj->moystep_);
192 tmpi8s[0] = dobj->totsize_;
193 tmpi8s[1] = dobj->offset_;
194 tmpi8s[2] = dobj->minstep_;
195 tmpi8s[3] = dobj->moystep_;
196 tmpi8s[4] = 0; // Reserved for future use
197 os.Put(tmpi8s, 5);
198
199// On ecrit le datablock
200 os << dobj->DataBlock();
201// On ecrit le DVList info si necessaire
202 if (itab[2] != 0) os << dobj->Info();
203}
204
205
206
207///////////////////////////////////////////////////////////////
208#ifdef __CXX_PRAGMA_TEMPLATES__
209// Instances des delegues FileIO (PPersist)
210// #pragma define_template FIO_TArray<uint_1>
211#pragma define_template FIO_TArray<uint_2>
212// #pragma define_template FIO_TArray<int_2>
213#pragma define_template FIO_TArray<int_4>
214#pragma define_template FIO_TArray<int_8>
215// #pragma define_template FIO_TArray<uint_4>
216// #pragma define_template FIO_TArray<uint_8>
217#pragma define_template FIO_TArray<r_8>
218#pragma define_template FIO_TArray<r_4>
219#pragma define_template FIO_TArray< complex<r_4> >
220#pragma define_template FIO_TArray< complex<r_8> >
221#endif
222
223#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
224// Instances des delegues FileIO (PPersist)
225// template class FIO_TArray<uint_1>;
226template class FIO_TArray<uint_2>;
227// template class FIO_TArray<int_2>;
228template class FIO_TArray<int_4>;
229template class FIO_TArray<int_8>;
230// template class FIO_TArray<uint_4>;
231// template class FIO_TArray<uint_8>;
232template class FIO_TArray<r_8>;
233template class FIO_TArray<r_4>;
234template class FIO_TArray< complex<r_4> >;
235template class FIO_TArray< complex<r_8> >;
236#endif
Note: See TracBrowser for help on using the repository browser.