source: Sophya/trunk/SophyaLib/BaseTools/fiondblock.cc@ 2441

Last change on this file since 2441 was 2441, checked in by ansari, 22 years ago

1) Premiere serie des modifications et ajout fonctionalites pour les PPersist:

  • Ecriture/lecture complex<> et tableaux de complex
  • Ecriture/lecture int_1, uint_1 et tableaux de
  • Tag de positionnement et table de tag de positionnement

2) Adaptation de Read/Write NDataBlock et suppression du fichier piocmplx.h

Reza 03/10/2003

File size: 5.7 KB
RevLine 
[802]1// Classe pour la gestion de persistance pour NDataBlock<T>
2// C.Magneville 04/99-03/2000
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4#include "machdefs.h"
5#include <stdio.h>
6#include <stdlib.h>
[2322]7#include <iostream>
[802]8#include <complex>
9#include "pexceptions.h"
[2441]10#include "datatype.h"
[802]11#include "fiondblock.h"
[1967]12#include <typeinfo>
[802]13
14////////////////////////////////////////////////////////////////
15// -------------------------------------------------------------------------
16// Les objets delegues pour la gestion de persistance
17// -------------------------------------------------------------------------
18
19/*
20template <class T>
21void ObjFileIO< NDataBlock<T> >::ReadSelf(PInPersist& is)
22template <class T>
23void ObjFileIO< NDataBlock<T> >::WriteSelf(POutPersist& os)
24*/
25
26
27template <class T>
28FIO_NDataBlock<T>::FIO_NDataBlock()
29{
30dobj=new NDataBlock<T>;
31ownobj=true;
32}
33
34template <class T>
35FIO_NDataBlock<T>::FIO_NDataBlock(string const & filename)
36{
37dobj=new NDataBlock<T>;
38ownobj=true;
39Read(filename);
40}
41
42template <class T>
43FIO_NDataBlock<T>::FIO_NDataBlock(const NDataBlock<T> & obj)
44{
45dobj = new NDataBlock<T>(obj);
46ownobj=true;
47}
48
49template <class T>
50FIO_NDataBlock<T>::FIO_NDataBlock(NDataBlock<T> * obj)
51{
52dobj = obj;
53ownobj=false;
54}
55
56template <class T>
57FIO_NDataBlock<T>::~FIO_NDataBlock()
58{
59if (ownobj && dobj) delete dobj;
60}
61
62template <class T>
63AnyDataObj* FIO_NDataBlock<T>::DataObj()
64{
65return(dobj);
66}
67
68template <class T>
69void FIO_NDataBlock<T>::SetDataObj(AnyDataObj & o)
70{
71NDataBlock<T> * po = dynamic_cast< NDataBlock<T> * >(&o);
[1967]72if (po == NULL) {
73 char buff[160];
74 sprintf(buff,"FIO_NDataBlock<T><%s>::SetDataObj(%s) - Object type error ! ",
75 DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
76 throw TypeMismatchExc(PExcLongMessage(buff));
77}
[802]78if (ownobj && dobj) delete dobj;
79dobj = po; ownobj = false;
80}
81
82template <class T>
83uint_8 FIO_NDataBlock<T>::getMemOId() const
84{
85 uint_8 rv = 0;
[1426]86 if (dobj) rv = (uint_8)(dobj->DRefId());
[802]87 return(rv);
88}
89
90template <class T>
91void FIO_NDataBlock<T>::ShareDataReference(PPersist & pp)
92{
93 FIO_NDataBlock<T> *ppo = dynamic_cast< FIO_NDataBlock<T> * >(&pp);
94 if (ppo == NULL) throw TypeMismatchExc("FIO_NDataBlock<T>::ShareDataReference() - Type Mismatch Error");
95 if (ppo->dobj) {
96 if (dobj == NULL) { dobj = new NDataBlock<T>; ownobj = true; }
97 dobj->Share(*(ppo->dobj));
98 }
99}
100
101template <class T>
102PPersist* FIO_NDataBlock<T>::CloneSharedReference()
103{
104 FIO_NDataBlock<T> * ppo = new FIO_NDataBlock<T>;
105 if (dobj) (ppo->dobj)->Share(*dobj);
106 return(ppo);
107}
108
[2441]109//---------------------------------------------------------------------------
110// Pour compatibilite de lecture avec PPF V2
111inline void PIOSReadArray(PInPersist & is, uint_1 * arr, size_t n)
112{ is.GetBytes(arr, n); }
113inline void PIOSReadArray(PInPersist & is, uint_2 * arr, size_t n)
114{ is.Get(arr, n); }
115inline void PIOSReadArray(PInPersist & is, int_2 * arr, size_t n)
116{ is.Get(arr, n); }
117inline void PIOSReadArray(PInPersist & is, uint_4 * arr, size_t n)
118{ is.Get(arr, n); }
119inline void PIOSReadArray(PInPersist & is, int_4 * arr, size_t n)
120{ is.Get(arr, n); }
121inline void PIOSReadArray(PInPersist & is, uint_8 * arr, size_t n)
122{ is.Get(arr, n); }
123inline void PIOSReadArray(PInPersist & is, int_8 * arr, size_t n)
124{ is.Get(arr, n); }
125inline void PIOSReadArray(PInPersist & is, r_4 * arr, size_t n)
126{ is.Get(arr, n); }
127inline void PIOSReadArray(PInPersist & is, r_8 * arr, size_t n)
128{ is.Get(arr, n); }
129inline void PIOSReadArray(PInPersist & is, complex<float> * arr, size_t n)
130{ r_4 * pr = (r_4 *)arr; is.Get(pr, n*2); }
131inline void PIOSReadArray(PInPersist & is, complex<double> * arr, size_t n)
132{ r_8 * pr = (r_8 *)arr; is.Get(pr, n*2); }
133//---------------------------------------------------------------------------
134
[802]135template <class T>
136void FIO_NDataBlock<T>::ReadSelf(PInPersist& is)
137{
138// On lit les 3 premiers uint_8
139uint_8 itab[3];
140is.Get(itab, 3);
141if (dobj == NULL) dobj = new NDataBlock<T>(itab[1]);
142else if (itab[1] != dobj->Size()) dobj->ReSize(itab[1]);
143// On lit le tableau de nombres
[2441]144if (is.Version() <= 2) // lecture ancienne version PPF
145 PIOSReadArray(is, dobj->Data(), dobj->Size());
146else is.Get(dobj->Data(), dobj->Size());
[802]147}
148
149
150template <class T>
151void FIO_NDataBlock<T>::WriteSelf(POutPersist& os) const
152{
153if (dobj == NULL) return; // Attention - $CHECK$ Reza 26/04/99
154// On ecrit 3 uint_8
155// 0 : Numero de version, 1 : Taille, 2 reserve a l
156uint_8 itab[3];
157itab[0] = 1;
158itab[1] = dobj->Size();
159itab[2] = 0;
160os.Put(itab, 3);
161// On ecrit le tableau de nombres
[2441]162os.Put(dobj->Data(), dobj->Size());
[802]163}
164
165///////////////////////////////////////////////////////////////
166#ifdef __CXX_PRAGMA_TEMPLATES__
167// Instances des delegues FileIO (PPersist)
168#pragma define_template FIO_NDataBlock<uint_1>
169#pragma define_template FIO_NDataBlock<uint_2>
170#pragma define_template FIO_NDataBlock<int_2>
171#pragma define_template FIO_NDataBlock<int_4>
172#pragma define_template FIO_NDataBlock<int_8>
173#pragma define_template FIO_NDataBlock<uint_4>
174#pragma define_template FIO_NDataBlock<uint_8>
175#pragma define_template FIO_NDataBlock<r_8>
176#pragma define_template FIO_NDataBlock<r_4>
177#pragma define_template FIO_NDataBlock< complex<r_4> >
178#pragma define_template FIO_NDataBlock< complex<r_8> >
179#endif
180
181#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
182// Instances des delegues FileIO (PPersist)
183template class FIO_NDataBlock<uint_1>;
184template class FIO_NDataBlock<uint_2>;
185template class FIO_NDataBlock<int_2>;
186template class FIO_NDataBlock<int_4>;
187template class FIO_NDataBlock<int_8>;
188template class FIO_NDataBlock<uint_4>;
189template class FIO_NDataBlock<uint_8>;
190template class FIO_NDataBlock<r_8>;
191template class FIO_NDataBlock<r_4>;
192template class FIO_NDataBlock< complex<r_4> >;
193template class FIO_NDataBlock< complex<r_8> >;
194#endif
Note: See TracBrowser for help on using the repository browser.