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

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

Instanciation FIO_TArray<int_4> pour g++/KCC/ansi - Reza 05/04/2000

File size: 4.6 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
15template <class T>
16FIO_TArray<T>::FIO_TArray()
17{
18 dobj=NULL;
19 ownobj=false;
20}
21
22template <class T>
23FIO_TArray<T>::FIO_TArray(string const & filename)
24{
25 dobj=NULL;
26 ownobj=false;
27 Read(filename);
28}
29
30template <class T>
31FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
32{
33 const TVector<T> * tv = dynamic_cast<const TVector<T> *>(&obj);
34 if (tv != NULL) dobj = new TVector<T>(*tv, true);
35 else {
36 const TMatrix<T> * tm = dynamic_cast<const TMatrix<T> *>(&obj);
37 if (tm != NULL) dobj = new TMatrix<T>(*tm, true);
38 else dobj = new TArray<T>(obj, true);
39 }
40 ownobj=true;
41}
42
43template <class T>
44FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
45{
46 dobj = obj;
47 ownobj=false;
48}
49
50template <class T>
51FIO_TArray<T>::~FIO_TArray()
52{
53 if (ownobj && dobj) delete dobj;
54}
55
56template <class T>
57AnyDataObj* FIO_TArray<T>::DataObj()
58{
59 return(dobj);
60}
61
62template <class T>
63void FIO_TArray<T>::SetDataObj(AnyDataObj & o)
64{
65 TArray<T> * po = dynamic_cast< TArray<T> * >(&o);
66 if (po == NULL) return;
67 if (ownobj && dobj) delete dobj;
68 dobj = po; ownobj = false;
69}
70
71template <class T>
72void FIO_TArray<T>::ReadSelf(PInPersist& is)
73{
74// On lit les 5 premiers uint_4
75// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
76// 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
77 uint_4 itab[5];
78 is.Get(itab,5);
79 if (dobj == NULL) {
80 if (itab[1] == 12) dobj = new TMatrix<T>;
81 else if (itab[1] == 48) dobj = new TVector<T>;
82 else dobj = new TArray<T>;
83 }
84// On lit les tailles, etc ...
85 is.Get(dobj->ndim_);
86 is.Get(dobj->size_, BASEARRAY_MAXNDIMS);
87 is.Get(dobj->totsize_);
88 is.Get(dobj->step_, BASEARRAY_MAXNDIMS);
89 is.Get(dobj->minstep_);
90 is.Get(dobj->moystep_);
91 is.Get(dobj->offset_);
92 is.Get(dobj->marowi_);
93 is.Get(dobj->macoli_);
94 is.Get(dobj->veceli_);
95// On lit le datablock
96 is >> dobj->DataBlock();
97// On ecrit le DVList info si necessaire
98 if (itab[2] != 0) is >> dobj->Info();
99}
100
101template <class T>
102void FIO_TArray<T>::WriteSelf(POutPersist& os) const
103{
104 if (dobj == NULL) return;
105// On ecrit 5 uint_4 ....
106// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
107// 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector
108 uint_4 typa = 0;
109 TVector<T> * tv = dynamic_cast<TVector<T> *>(dobj);
110 if (tv != NULL) typa = 48;
111 else {
112 TMatrix<T> * tm = dynamic_cast<TMatrix<T> *>(dobj);
113 if (tm != NULL) typa = 12;
114 else typa = 0;
115 }
116
117 uint_4 itab[5];
118 itab[0] = 1; // Numero de version a 1
119 itab[1] = typa; // Real object type
120 itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
121 itab[3] = itab[4] = 0;
122 os.Put(itab,5);
123// On ecrit les tailles, etc ...
124 os.Put(dobj->ndim_);
125 os.Put(dobj->size_, BASEARRAY_MAXNDIMS);
126 os.Put(dobj->totsize_);
127 os.Put(dobj->step_, BASEARRAY_MAXNDIMS);
128 os.Put(dobj->minstep_);
129 os.Put(dobj->moystep_);
130 os.Put(dobj->offset_);
131 os.Put(dobj->marowi_);
132 os.Put(dobj->macoli_);
133 os.Put(dobj->veceli_);
134// On ecrit le datablock
135 os << dobj->DataBlock();
136// On ecrit le DVList info si necessaire
137 if (itab[2] != 0) os << dobj->Info();
138}
139
140
141
142///////////////////////////////////////////////////////////////
143#ifdef __CXX_PRAGMA_TEMPLATES__
144// Instances des delegues FileIO (PPersist)
145// #pragma define_template FIO_TArray<uint_1>
146#pragma define_template FIO_TArray<uint_2>
147// #pragma define_template FIO_TArray<int_2>
148#pragma define_template FIO_TArray<int_4>
149#pragma define_template FIO_TArray<int_8>
150// #pragma define_template FIO_TArray<uint_4>
151// #pragma define_template FIO_TArray<uint_8>
152#pragma define_template FIO_TArray<r_8>
153#pragma define_template FIO_TArray<r_4>
154#pragma define_template FIO_TArray< complex<r_4> >
155#pragma define_template FIO_TArray< complex<r_8> >
156#endif
157
158#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
159// Instances des delegues FileIO (PPersist)
160// template class FIO_TArray<uint_1>;
161template class FIO_TArray<uint_2>;
162// template class FIO_TArray<int_2>;
163template class FIO_TArray<int_4>;
164template class FIO_TArray<int_8>;
165// template class FIO_TArray<uint_4>;
166// template class FIO_TArray<uint_8>;
167template class FIO_TArray<r_8>;
168template class FIO_TArray<r_4>;
169template class FIO_TArray< complex<r_4> >;
170template class FIO_TArray< complex<r_8> >;
171#endif
Note: See TracBrowser for help on using the repository browser.