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

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

documentation cmv 13/4/00

File size: 5.0 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 if (dobj == NULL) {
96 if (itab[1] == 12) dobj = new TMatrix<T>;
97 else if (itab[1] == 48) dobj = new TVector<T>;
98 else dobj = new TArray<T>;
99 }
100// On lit les tailles, etc ...
101 is.Get(dobj->ndim_);
102 is.Get(dobj->size_, BASEARRAY_MAXNDIMS);
103 is.Get(dobj->totsize_);
104 is.Get(dobj->step_, BASEARRAY_MAXNDIMS);
105 is.Get(dobj->minstep_);
106 is.Get(dobj->moystep_);
107 is.Get(dobj->offset_);
108 is.Get(dobj->marowi_);
109 is.Get(dobj->macoli_);
110 is.Get(dobj->veceli_);
111// On lit le datablock
112 is >> dobj->DataBlock();
113// On ecrit le DVList info si necessaire
114 if (itab[2] != 0) is >> dobj->Info();
115}
116
117template <class T>
118void FIO_TArray<T>::WriteSelf(POutPersist& os) const
119{
120 if (dobj == NULL) return;
121// On ecrit 5 uint_4 ....
122// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
123// 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
124 uint_4 typa = 0;
125 TVector<T> * tv = dynamic_cast<TVector<T> *>(dobj);
126 if (tv != NULL) typa = 48;
127 else {
128 TMatrix<T> * tm = dynamic_cast<TMatrix<T> *>(dobj);
129 if (tm != NULL) typa = 12;
130 else typa = 0;
131 }
132
133 uint_4 itab[5];
134 itab[0] = 1; // Numero de version a 1
135 itab[1] = typa; // Real object type
136 itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
137 itab[3] = itab[4] = 0;
138 os.Put(itab,5);
139// On ecrit les tailles, etc ...
140 os.Put(dobj->ndim_);
141 os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
142 os.Put(dobj->totsize_);
143 os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
144 os.Put(dobj->minstep_);
145 os.Put(dobj->moystep_);
146 os.Put(dobj->offset_);
147 os.Put(dobj->marowi_);
148 os.Put(dobj->macoli_);
149 os.Put(dobj->veceli_);
150// On ecrit le datablock
151 os << dobj->DataBlock();
152// On ecrit le DVList info si necessaire
153 if (itab[2] != 0) os << dobj->Info();
154}
155
156
157
158///////////////////////////////////////////////////////////////
159#ifdef __CXX_PRAGMA_TEMPLATES__
160// Instances des delegues FileIO (PPersist)
161// #pragma define_template FIO_TArray<uint_1>
162#pragma define_template FIO_TArray<uint_2>
163// #pragma define_template FIO_TArray<int_2>
164#pragma define_template FIO_TArray<int_4>
165#pragma define_template FIO_TArray<int_8>
166// #pragma define_template FIO_TArray<uint_4>
167// #pragma define_template FIO_TArray<uint_8>
168#pragma define_template FIO_TArray<r_8>
169#pragma define_template FIO_TArray<r_4>
170#pragma define_template FIO_TArray< complex<r_4> >
171#pragma define_template FIO_TArray< complex<r_8> >
172#endif
173
174#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
175// Instances des delegues FileIO (PPersist)
176// template class FIO_TArray<uint_1>;
177template class FIO_TArray<uint_2>;
178// template class FIO_TArray<int_2>;
179template class FIO_TArray<int_4>;
180template class FIO_TArray<int_8>;
181// template class FIO_TArray<uint_4>;
182// template class FIO_TArray<uint_8>;
183template class FIO_TArray<r_8>;
184template class FIO_TArray<r_4>;
185template class FIO_TArray< complex<r_4> >;
186template class FIO_TArray< complex<r_8> >;
187#endif
Note: See TracBrowser for help on using the repository browser.