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

Last change on this file since 785 was 785, checked in by ansari, 26 years ago

Corrections,amelioration de TArray<T> - Reza 16/3/2000

File size: 3.7 KB
Line 
1// Persistence manager for template numerical arrays
2// R. Ansari, C.Magneville 03/2000
3
4#include "pexceptions.h"
5#include "fioarr.h"
6
7// --------------------------------------------------------
8// Les objets delegues pour la gestion de persistance
9// --------------------------------------------------------
10///////////////////////////////////////////////////////////
11
12template <class T>
13FIO_TArray<T>::FIO_TArray()
14{
15 dobj=new TArray<T>;
16 ownobj=true;
17}
18
19template <class T>
20FIO_TArray<T>::FIO_TArray(string const & filename)
21{
22 dobj=new TArray<T>;
23 ownobj=true;
24 Read(filename);
25}
26
27template <class T>
28FIO_TArray<T>::FIO_TArray(const TArray<T> & obj)
29{
30 dobj = new TArray<T>(obj);
31 ownobj=true;
32}
33
34template <class T>
35FIO_TArray<T>::FIO_TArray(TArray<T> * obj)
36{
37 dobj = obj;
38 ownobj=false;
39}
40
41template <class T>
42FIO_TArray<T>::~FIO_TArray()
43{
44 if (ownobj && dobj) delete dobj;
45}
46
47template <class T>
48AnyDataObj* FIO_TArray<T>::DataObj()
49{
50 return(dobj);
51}
52
53template <class T>
54void FIO_TArray<T>::SetDataObj(AnyDataObj & o)
55{
56 TArray<T> * po = dynamic_cast< TArray<T> * >(&o);
57 if (po == NULL) return;
58 if (ownobj && dobj) delete dobj;
59 dobj = po; ownobj = false;
60}
61
62template <class T>
63void FIO_TArray<T>::ReadSelf(PInPersist& is)
64{
65// On lit les 3 premiers uint_4
66// 0: Numero de version, : NRows, 2 : NCol
67 uint_4 itab[5];
68 is.Get(itab,5);
69 if (dobj == NULL) dobj = new TArray<T>;
70// On lit les tailles, etc ...
71 is.Get(dobj->ndim_);
72 is.Get(dobj->size_, TARRAY_MAXNDIMS);
73 is.Get(dobj->totsize_);
74 is.Get(dobj->step_, TARRAY_MAXNDIMS);
75 is.Get(dobj->minstep_);
76 is.Get(dobj->moystep_);
77 is.Get(dobj->offset_);
78 is.Get(dobj->marowi_);
79 is.Get(dobj->macoli_);
80// On lit le datablock
81 is >> dobj->DataBlock();
82// On ecrit le DVList info si necessaire
83 if (itab[2] != 0) is >> dobj->Info();
84}
85
86template <class T>
87void FIO_TArray<T>::WriteSelf(POutPersist& os) const
88{
89 if (dobj == NULL) return;
90// On ecrit 4 uint_4 ....
91// 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info
92 uint_4 itab[5];
93 itab[0] = 1; // Numero de version a 1
94 itab[1] = 0;
95 itab[2] = (dobj->mInfo != NULL) ? 1 : 0;
96 itab[3] = itab[4] = 0;
97 os.Put(itab,3);
98// On ecrit les tailles, etc ...
99 os.Put(dobj->ndim_);
100 os.Put(dobj->size_, TARRAY_MAXNDIMS);
101 os.Put(dobj->totsize_);
102 os.Put(dobj->step_, TARRAY_MAXNDIMS);
103 os.Put(dobj->minstep_);
104 os.Put(dobj->moystep_);
105 os.Put(dobj->offset_);
106 os.Put(dobj->marowi_);
107 os.Put(dobj->macoli_);
108// On ecrit le datablock
109 os << dobj->DataBlock();
110// On ecrit le DVList info si necessaire
111 if (itab[2] != 0) os << dobj->Info();
112}
113
114
115
116///////////////////////////////////////////////////////////////
117#ifdef __CXX_PRAGMA_TEMPLATES__
118// Instances des delegues FileIO (PPersist)
119#pragma define_template FIO_TArray<uint_1>
120#pragma define_template FIO_TArray<uint_2>
121#pragma define_template FIO_TArray<int_2>
122#pragma define_template FIO_TArray<int_4>
123#pragma define_template FIO_TArray<int_8>
124#pragma define_template FIO_TArray<uint_4>
125#pragma define_template FIO_TArray<uint_8>
126#pragma define_template FIO_TArray<r_8>
127#pragma define_template FIO_TArray<r_4>
128#pragma define_template FIO_TArray< complex<r_4> >
129#pragma define_template FIO_TArray< complex<r_8> >
130#endif
131
132#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
133// Instances des delegues FileIO (PPersist)
134template class FIO_TArray<uint_1>;
135template class FIO_TArray<uint_2>;
136template class FIO_TArray<int_2>;
137template class FIO_TArray<int_4>;
138template class FIO_TArray<int_8>;
139template class FIO_TArray<uint_4>;
140template class FIO_TArray<uint_8>;
141template class FIO_TArray<r_8>;
142template class FIO_TArray<r_4>;
143template class FIO_TArray< complex<r_4> >;
144template class FIO_TArray< complex<r_8> >;
145#endif
Note: See TracBrowser for help on using the repository browser.