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

Last change on this file since 3910 was 3837, checked in by ansari, 15 years ago

MAJ commentaires pour doxygen, Reza 09/08/2010

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