source: Sophya/trunk/SophyaLib/BaseTools/ndatablock.cc@ 285

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

complex est un include system -> <...> et pas "..." sinon pb mkmf
ndatablock ameliore cmv 30/4/99

File size: 20.1 KB
Line 
1// Gestion de block de donnees avec partage de references
2// C.Magneville 04/99
3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4#include "machdefs.h"
5#include <stdio.h>
6#include <stdlib.h>
7#include <iostream.h>
8#include <complex>
9#include "pexceptions.h"
10#include "ndatablock.h"
11#include "objfio.h"
12
13using namespace PlanckDPC;
14
15// define DEBUG_NDATABLOCK
16
17#ifdef DEBUG_NDATABLOCK
18 static size_t NallocData = 0;
19 static size_t NallocSRef = 0;
20#endif
21
22// LOGIQUE DE BASE:
23// - le createur par copie et la surcharge de l operateur = "partage" les donnees
24// - gestion du partage de reference
25
26////////////////////////////////////////////////////////////////
27//************ Createur, Destructeur, gestion des donnees
28
29template <class T>
30NDataBlock<T>::NDataBlock(size_t n)
31// Createur d'une structure de "n" donnees
32: mSz(0), mSRef(NULL), mIsTemp(false)
33{
34#ifdef DEBUG_NDATABLOCK
35cout<<"DEBUG_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl;
36#endif
37
38Alloc(n);
39}
40
41template <class T>
42NDataBlock<T>::NDataBlock(size_t n, T* data, Bridge* br)
43// Createur d'une structure de "n" donnees, avec donnees preallouees
44// (Voir explications dans Alloc())
45: mSz(0), mSRef(NULL), mIsTemp(false)
46{
47#ifdef DEBUG_NDATABLOCK
48cout<<"DEBUG_NDataBlock::NDataBlock("<<this
49 <<",data="<<data<<",br="<<br<<")"<<endl;
50#endif
51
52Alloc(n,data,br);
53}
54
55template <class T>
56NDataBlock<T>::NDataBlock()
57// Createur par default
58: mSz(0), mSRef(NULL), mIsTemp(false)
59{
60#ifdef DEBUG_NDATABLOCK
61cout<<"DEBUG_NDataBlock::NDataBlock("<<this<<") default"<<endl;
62#endif
63}
64
65template <class T>
66NDataBlock<T>::NDataBlock(const NDataBlock<T>& a)
67// Createur par copie
68// ATTENTION: partage les donnees avec "a"
69// Ecriture: NDataBlock a = b;
70// NDataBlock a(b)
71: mSz(0), mSRef(NULL), mIsTemp(false)
72{
73#ifdef DEBUG_NDATABLOCK
74cout<<"DEBUG_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<") a.(mSz="
75 <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()<<")"<<endl;
76#endif
77
78Share(a);
79}
80
81template <class T>
82NDataBlock<T>::NDataBlock(const NDataBlock<T>& a,bool share)
83// Createur avec choix de partager ou non
84// Si "a" temporaire alors partage meme si share=false
85: mSz(0), mSRef(NULL), mIsTemp(false)
86{
87#ifdef DEBUG_NDATABLOCK
88cout<<"DEBUG_NDataBlock::NDataBlock("<<this<<",&a="<<&a<<",sh=<<"<<share<<")"
89 <<" a.(mSz="<<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()<<")"<<endl;
90#endif
91
92if(share) Share(a); else Clone(a);
93}
94
95template <class T>
96NDataBlock<T>::~NDataBlock()
97// Destructeur
98{
99#ifdef DEBUG_NDATABLOCK
100cout<<"DEBUG_NDataBlock::~NDataBlock("<<this<<")"<<endl;
101#endif
102
103Delete();
104}
105
106////////////////////////////////////////////////////////////////
107
108template <class T>
109void NDataBlock<T>::SetTemp(bool temp) const
110// Set temporary
111{
112mIsTemp=temp;
113
114#ifdef DEBUG_NDATABLOCK
115cout<<"DEBUG_NDataBlock::SetTemp("<<this<<","<<temp
116 <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
117#endif
118}
119
120template <class T>
121void NDataBlock<T>::Alloc(size_t n,T* data,Bridge* br)
122// Allocation d'un NOUVEL espace de stoquage de "n" donnees
123// Si data==NULL : allocation de l'espace memoire (vide)
124// data!=NULL : partage des donnees avec l'adresse data
125// Si br==NULL : les donnees nous appartiennent
126// br!=NULL : les donnees ne nous appartiennent pas (ex: Blitz)
127//
128// Exemple: on veut connecter a un tableau de T*
129// 1- On veut que NDataBlock NE DESALLOUE PAS le tableau "data"
130// a- Premiere solution
131// float *x = new float[5]; ... remplissage de x[] ...;
132// NDataBlock A(5,x,new Bridge);
133// delete [] x; // Il faut deleter explicitement
134// (et Bridge est delete par le destructeur de la classe)
135// b- Autre solution:
136// NDataBlock A(5); A.FillFrom(5,x);
137// delete [] x; // Il faut deleter explicitement
138// 2- On veut que NDataBlock desalloue le tableau
139// float *x = new float[5]; ... remplissage de x[] ...;
140// NDataBlock A(5,x);
141// (Ne Pas Faire "delete [] x;")
142{
143#ifdef DEBUG_NDATABLOCK
144cout<<"DEBUG_NDataBlock::Alloc("<<this<<","
145 <<n<<","<<data<<","<<br<<") mSz="<<mSz
146 <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
147#endif
148
149if(br && !data)
150 throw(NullPtrError("NDataBlock::Alloc br!=NULL && data==NULL\n"));
151if(n==0) throw(SzMismatchError("NDataBlock::Alloc n==0\n"));
152if(mSRef) Delete();
153mSz = n;
154mSRef = new NDREF;
155mSRef->nref = 1;
156if(data) mSRef->data = data;
157else {mSRef->data = new T[n]; memset(mSRef->data,0,n*sizeof(T));}
158mSRef->bridge = br;
159
160#ifdef DEBUG_NDATABLOCK
161// Meme dans le cas data!=0 et br==0 (connexion d'un tableau
162// avec destruction geree par ~NDataBlock (cas 2-) on compte
163// comme si on avait fait une allocation du tableau (ce qui a ete
164// fait au niveau du dessus!).
165if(!br) NallocData++; NallocSRef++;
166cout<<"...DEBUG_NDataBlock::Alloc mSz="<<mSz<<" mSRef="<<mSRef
167 <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
168 <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp
169 <<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
170#endif
171}
172
173template <class T>
174void NDataBlock<T>::Clone(const NDataBlock<T>& a)
175// Clone (copie de donnee) a partir de "a"
176// sauf si "a" est une classe temporaire (dans ce cas share!)
177{
178#ifdef DEBUG_NDATABLOCK
179cout<<"DEBUG_NDataBlock::Clone("<<this<<","<<&a<<") a.(mSz="
180 <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
181 <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
182#endif
183
184if(a.mSz==0) throw(SzMismatchError("NDataBlock::Clone a.mSz==0\n"));
185else if(a.IsTemp()) Share(a);
186else {Alloc(a.mSz); memcpy(Data(),a.Data(),mSz*sizeof(T));}
187}
188
189template <class T>
190void NDataBlock<T>::Share(const NDataBlock<T>& a)
191// Partage des donnees avec "a"
192{
193#ifdef DEBUG_NDATABLOCK
194cout<<"DEBUG_NDataBlock::Share("<<this<<","<<&a<<")";
195if(&a!=NULL) cout<<" a.(mSz="<<a.mSz<<" mSRef="<<a.mSRef
196 <<" IsTemp="<<a.IsTemp()<<")";
197cout<<", mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
198#endif
199
200if(&a==NULL) throw(NullPtrError("NDataBlock::Share &a==NULL\n"));
201// on ne peut partager si "a" pas alloue
202if(!a.mSRef) throw(NullPtrError("NDataBlock::Share not allocated a\n"));
203if(mSRef) Delete();
204mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++;
205
206#ifdef DEBUG_NDATABLOCK
207cout<<"...DEBUG_NDataBlock::Share mSz="<<mSz<<" mSRef="<<mSRef
208 <<" mSRef->nref="<<mSRef->nref<<" mSRef->data="<< mSRef->data
209 <<" mSRef->bridge="<<mSRef->bridge<<" IsTemp="<<mIsTemp<<endl;
210#endif
211}
212
213template <class T>
214void NDataBlock<T>::Delete(void)
215// Pour detruire les pointeurs en tenant compte des references
216{
217#ifdef DEBUG_NDATABLOCK
218cout<<"DEBUG_NDataBlock::Delete("<<this<<") mSz="<<mSz
219 <<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp;
220if(mSRef)
221 cout<<" mSRef->nref="<<mSRef->nref<<" mSRef->data="
222 <<mSRef->data<<" mSRef->bridge="<<mSRef->bridge;
223cout<<endl;
224#endif
225
226if(mSRef==NULL) return; // cas du createur par defaut
227mSRef->nref--;
228if(mSRef->nref != 0) {
229
230#ifdef DEBUG_NDATABLOCK
231cout<<"...DEBUG_NDataBlock::Delete() pas de desallocation il reste nref="
232 <<mSRef->nref<<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
233#endif
234
235 mSz = 0; mSRef=NULL;
236 return;
237}
238
239#ifdef DEBUG_NDATABLOCK
240if(!mSRef->bridge) NallocData--; NallocSRef--;
241cout<<"...DEBUG_NDataBlock::Delete() desallocation complete il reste nref="
242 <<mSRef->nref<<" Total("<<NallocData<<","<<NallocSRef<<")"<<endl;
243#endif
244
245// Si il y a un Bridge les donnees ne n'appartiennent pas, on detruit le Bridge
246// sinon, les donnees ont ete allouees par nos soins, on libere l'espace
247if(mSRef->bridge) delete mSRef->bridge; else delete [] mSRef->data;
248mSRef->bridge=NULL; mSRef->data=NULL;
249delete mSRef; mSRef=NULL; mSz = 0;
250}
251
252////////////////////////////////////////////////////////////////
253
254template <class T>
255void NDataBlock<T>::Reset(T v)
256{
257if(mSRef==NULL || mSRef->data==NULL || mSz==0) return;
258T *p=Begin(), *pe=End(); while(p<pe) *p++ = v;
259}
260
261template <class T>
262void NDataBlock<T>::ReSize(size_t n,bool force_alloc)
263// Re-dimension, avec re-allocation de la place si n != mSz
264// Si n==mSz, la place n'est re-allouee que si force_alloc=true
265{
266if(!force_alloc && n == mSz) return;
267Alloc(n);
268}
269
270template <class T>
271void NDataBlock<T>::FillFrom(size_t n,T* data)
272// Remplissage par un tableau de donnees
273// - Si classe vide : creation de l'espace memoire
274// - Si classe connectee : on ecrit selon la longueur
275{
276if(data==NULL) throw(NullPtrError("NDataBlock::FillFrom data==NULL\n"));
277if(n==0) throw(ParmError("NDataBlock::FillFrom n<=0\n"));
278if(mSRef==NULL) Alloc(n); // cas du createur par default
279if(mSz<n) n = mSz;
280memcpy(Data(),data,n*sizeof(T));
281}
282
283////////////////////////////////////////////////////////////////
284//**** Impression
285
286template <class T>
287void NDataBlock<T>::Print(ostream& os,size_t i1,size_t n) const
288// Impression de n elements a partir de i1
289{
290size_t nr = 0;
291T* p = NULL; Bridge* br = NULL;
292if(mSRef) {nr = mSRef->nref; p = mSRef->data; br = mSRef->bridge;}
293os<<"NDataBlock::Print("<<this<<",Sz="<<mSz<<",IsTemp="<<mIsTemp<<")\n"
294 <<" mSRef="<<mSRef<<"(nref="<<nr<<",data="<<p
295 <<",bridge="<<br<<")"<<endl;
296if(i1>=mSz || n<=0 || !p) return;
297size_t i2 = i1+n; if(i2>mSz) i2=mSz;
298size_t im = 1; bool enl=false;
299while(i1<i2) {
300 enl = false;
301 os<<" "<<(*this)(i1); i1++;
302 if(im==8) {os<<"\n"; im=1; enl=true;} else im++;
303}
304if(!enl) os<<endl;
305}
306
307////////////////////////////////////////////////////////////////
308//**** Surcharge de = : NDataBlock=NDataBlock; NDataBlock=<T> b;
309
310template <class T>
311NDataBlock<T>& NDataBlock<T>::operator = (const NDataBlock<T>& a)
312// surcharge avec partage des donnees
313// Ecriture: NDataBlock a; a = b;
314// NDataBlock a(10); a = b; (a est re-affecte)
315{
316#ifdef DEBUG_NDATABLOCK
317cout<<"DEBUG_NDataBlock::operator=("<<this<<","<<&a<<") a.(mSz="
318 <<a.mSz<<" mSRef="<<a.mSRef<<" IsTemp="<<a.IsTemp()
319 <<"), mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
320#endif
321
322if(this == &a) return *this;
323if(a.mSz!=mSz)
324 throw(SzMismatchError("NDataBlock::operator=A size mismatch/null\n"));
325Share(a);
326return *this;
327}
328
329template <class T>
330NDataBlock<T>& NDataBlock<T>::operator = (T v)
331// surcharge avec copie des donnees (pas de partage)
332// "this" est sur-ecrit, attention au partage de reference!
333// NDataBlock a; a = v; ou bien NDataBlock a(10); a = v;
334{
335#ifdef DEBUG_NDATABLOCK
336cout<<"DEBUG_NDataBlock::operator=("<<this<<","<<v<<")"
337 <<" mSz="<<mSz<<" mSRef="<<mSRef<<" IsTemp="<<mIsTemp<<endl;
338#endif
339
340if(mSz==0) throw(SzMismatchError("NDataBlock::operator=v null size\n"));
341T *p=Begin(), *pe=End();
342while (p<pe) *p++ = v;
343return *this;
344}
345
346////////////////////////////////////////////////////////////////
347
348template <class T>
349T NDataBlock<T>::Sum(size_t i1,size_t n) const
350// Somme des elements de i1 a i1+n-1
351{
352if(i1>=mSz) return 0;
353if(n>mSz) n = mSz; if(n==0) n = mSz-i1;
354T const *p=Begin()+i1, *pe=p+n;
355T val = 0;
356while (p<pe) val += *p++;
357return val;
358}
359
360template <class T>
361T NDataBlock<T>::Product(size_t i1,size_t n) const
362// Produit des elements de i1 a i1+n-1
363{
364if(i1>=mSz) return 0;
365if(n>mSz) n = mSz; if(n==0) n = mSz-i1;
366T const *p=Begin()+i1, *pe=p+n;
367T val = 0;
368while (p<pe) val *= *p++;
369return val;
370}
371
372////////////////////////////////////////////////////////////////
373//**** Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += <T> b;
374
375template <class T>
376NDataBlock<T>& NDataBlock<T>::operator += (T b)
377{
378if(mSz==0) throw(SzMismatchError("NDataBlock::operator+=v null size\n"));
379T *p=Begin(), *pe=End();
380while (p<pe) *p++ += b;
381return *this;
382}
383
384template <class T>
385NDataBlock<T>& NDataBlock<T>::operator -= (T b)
386{
387if(mSz==0) throw(SzMismatchError("NDataBlock::operator-=v null size\n"));
388T *p=Begin(), *pe=End();
389while (p<pe) *p++ -= b;
390return *this;
391}
392
393template <class T>
394NDataBlock<T>& NDataBlock<T>::operator *= (T b)
395{
396if(mSz==0) throw(SzMismatchError("NDataBlock::operator*=v null size\n"));
397T *p=Begin(), *pe=End();
398while (p<pe) *p++ *= b;
399return *this;
400}
401
402template <class T>
403NDataBlock<T>& NDataBlock<T>::operator /= (T b)
404{
405if(b==(T) 0) throw(ParmError("NDataBlock::operator/=v divide by zero\n"));
406if(mSz==0) throw(SzMismatchError("NDataBlock::operator/=v null size\n"));
407T *p=Begin(), *pe=End();
408while (p<pe) *p++ /= b;
409return *this;
410}
411
412
413////////////////////////////////////////////////////////////////
414//**** Surcharge de +=,-=,*=,/= (INPLACE): NDataBlock += NDataBlock;
415
416template <class T>
417NDataBlock<T>& NDataBlock<T>::operator += (const NDataBlock<T>& a)
418{
419if(mSz==0 || mSz!=a.mSz)
420 throw(SzMismatchError("NDataBlock::operator+=A size mismatch/null"));
421T *p=Begin(), *pe=End();
422T const * pa=a.Begin();
423while (p<pe) *p++ += *pa++; // ca marche meme si *this=a
424return *this;
425}
426
427template <class T>
428NDataBlock<T>& NDataBlock<T>::operator -= (const NDataBlock<T>& a)
429{
430if(mSz==0 || mSz!=a.mSz)
431 throw(SzMismatchError("NDataBlock::operator-=A size mismatch/null"));
432T *p=Begin(), *pe=End();
433T const *pa=a.Begin();
434while (p<pe) *p++ -= *pa++; // ca marche meme si *this=a
435return *this;
436}
437
438template <class T>
439NDataBlock<T>& NDataBlock<T>::operator *= (const NDataBlock<T>& a)
440{
441if(mSz==0 || mSz!=a.mSz)
442 throw(SzMismatchError("NDataBlock::operator*=A size mismatch/null"));
443T *p=Begin(), *pe=End();
444T const *pa=a.Begin();
445while (p<pe) *p++ *= *pa++; // ca marche meme si *this=a
446return *this;
447}
448
449template <class T>
450NDataBlock<T>& NDataBlock<T>::operator /= (const NDataBlock<T>& a)
451{
452if(mSz==0 || mSz!=a.mSz)
453 throw(SzMismatchError("NDataBlock::operator/=A size mismatch/null"));
454T *p=Begin(), *pe=End();
455T const *pa=a.Begin();
456while (p<pe) *p++ /= *pa++;
457return *this;
458}
459
460////////////////////////////////////////////////////////////////
461//**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+<T>b;
462// NDataBlock = <T>b+NDataBlock;
463// ATTENTION: re-affectation imposee
464
465template <class T>
466NDataBlock<T> NDataBlock<T>::Add(T b) const
467// Pour A+b
468{
469NDataBlock<T> result(*this,false); result.SetTemp(true);
470result += b;
471return result;
472}
473
474template <class T>
475NDataBlock<T> NDataBlock<T>::Sub(T b) const
476// Pour A-b
477{
478NDataBlock<T> result(*this,false); result.SetTemp(true);
479return result -= b;
480}
481
482template <class T>
483NDataBlock<T> NDataBlock<T>::SubInv(T b) const
484// Pour b-A
485{
486NDataBlock<T> result(*this,false); result.SetTemp(true);
487T *p=result.Begin(), *pe=result.End();
488T const *pa=this->Begin();
489while(p<pe) {*p++ = b - *pa++;}
490return result;
491}
492
493template <class T>
494NDataBlock<T> NDataBlock<T>::Mul(T b) const
495// Pour A*b
496{
497NDataBlock<T> result(*this,false); result.SetTemp(true);
498return result *= b;
499}
500
501template <class T>
502NDataBlock<T> NDataBlock<T>::Div(T b) const
503// Pour A/b
504{
505NDataBlock<T> result(*this,false); result.SetTemp(true);
506return result /= b;
507}
508
509template <class T>
510NDataBlock<T> NDataBlock<T>::DivInv(T b) const
511// Pour b/A
512{
513NDataBlock<T> result(*this,false); result.SetTemp(true);
514T *p=result.Begin(), *pe=result.End();
515T const *pa = this->Begin();
516while(p<pe) {*p++ = b / *pa++;}
517return result;
518}
519
520
521////////////////////////////////////////////////////////////////
522//**** Surcharge de +,-,*,/ : NDataBlock = NDataBlock+NDataBlock;
523
524template <class T>
525NDataBlock<T> NDataBlock<T>::Add(const NDataBlock<T>& b) const
526// Pour A+B
527{
528if(mSz!=b.mSz)
529 throw(SzMismatchError("NDataBlock operator C=A+B size mismatch/null\n"));
530NDataBlock<T> result; result.SetTemp(true);
531if(b.IsTemp()) {
532 result.Share(b);
533 result += *this;
534} else {
535 result.Clone(*this);
536 result += b;
537}
538return result;
539}
540
541template <class T>
542NDataBlock<T> NDataBlock<T>::Mul(const NDataBlock<T>& b) const
543// Pour A*B
544{
545if(mSz!=b.mSz)
546 throw(SzMismatchError("NDataBlock operator C=A*B size mismatch/null\n"));
547NDataBlock<T> result; result.SetTemp(true);
548if(b.IsTemp()) {
549 result.Share(b);
550 result *= *this;
551} else {
552 result.Clone(*this);
553 result *= b;
554}
555return result;
556}
557
558template <class T>
559NDataBlock<T> NDataBlock<T>::Sub(const NDataBlock<T>& b) const
560// Pour A-B
561{
562if(mSz!=b.mSz)
563 throw(SzMismatchError("NDataBlock operator C=A-B size mismatch/null\n"));
564NDataBlock<T> result; result.SetTemp(true);
565if(b.IsTemp()) {
566 result.Share(b);
567 T *p=result.Begin(), *pe=result.End();
568 T const *pa=Begin();
569 while(p<pe) {*p = *pa++ - *p; p++;}
570} else {
571 result.Clone(*this);
572 result -= b;
573}
574return result;
575}
576
577template <class T>
578NDataBlock<T> NDataBlock<T>::Div(const NDataBlock<T>& b) const
579// Pour A/B
580{
581if(mSz!=b.mSz)
582 throw(SzMismatchError("NDataBlock operator C=A/B size mismatch/null\n"));
583NDataBlock<T> result; result.SetTemp(true);
584if(b.IsTemp()) {
585 result.Share(b);
586 T *p=result.Begin(), *pe=result.End();
587 T const *pa=Begin();
588 while(p<pe) {*p = *pa++ / *p; p++;}
589} else {
590 result.Clone(*this);
591 result /= b;
592}
593return result;
594}
595
596////////////////////////////////////////////////////////////////
597// -------------------------------------------------------------------------
598// Les objets delegues pour la gestion de persistance
599// -------------------------------------------------------------------------
600
601/*
602template <class T>
603void ObjFileIO< NDataBlock<T> >::ReadSelf(PInPersist& is)
604template <class T>
605void ObjFileIO< NDataBlock<T> >::WriteSelf(POutPersist& os)
606*/
607
608// Pour pouvoir ecrire des tableaux de complex, en attendant
609// PIn/POutPersist::Get/Put(complex<>)
610#include <piocmplx.h>
611
612template <class T>
613FIO_NDataBlock<T>::FIO_NDataBlock()
614{
615dobj=new NDataBlock<T>;
616ownobj=true;
617}
618
619template <class T>
620FIO_NDataBlock<T>::FIO_NDataBlock(string const & filename)
621{
622dobj=new NDataBlock<T>;
623ownobj=true;
624Read(filename);
625}
626
627template <class T>
628FIO_NDataBlock<T>::FIO_NDataBlock(const NDataBlock<T> & obj)
629{
630dobj = new NDataBlock<T>(obj);
631ownobj=true;
632}
633
634template <class T>
635FIO_NDataBlock<T>::FIO_NDataBlock(NDataBlock<T> * obj)
636{
637dobj = obj;
638ownobj=false;
639}
640
641template <class T>
642FIO_NDataBlock<T>::~FIO_NDataBlock()
643{
644if (ownobj && dobj) delete dobj;
645}
646
647template <class T>
648AnyDataObj* FIO_NDataBlock<T>::DataObj()
649{
650return(dobj);
651}
652
653
654template <class T>
655void FIO_NDataBlock<T>::ReadSelf(PInPersist& is)
656{
657// On lit les 3 premiers uint_8
658uint_8 itab[3];
659is.Get(itab, 3);
660if (dobj == NULL) dobj = new NDataBlock<T>(itab[1]);
661else dobj->ReSize(itab[1], false);
662// On lit le tableau de nombres
663PIOSReadArray(is, dobj->Data(), dobj->Size());
664}
665
666
667template <class T>
668void FIO_NDataBlock<T>::WriteSelf(POutPersist& os) const
669{
670if (dobj == NULL) return; // Attention - $CHECK$ Reza 26/04/99
671// On ecrit 3 uint_4
672// 0 : Numero de version, 1 : Taille, 2 reserve a l
673uint_8 itab[3];
674itab[0] = 1;
675itab[1] = dobj->Size();
676itab[2] = 0;
677os.Put(itab, 3);
678// On ecrit le tableau de nombres
679PIOSWriteArray(os, dobj->Data(), dobj->Size());
680}
681
682///////////////////////////////////////////////////////////////
683#ifdef __CXX_PRAGMA_TEMPLATES__
684#pragma define_template NDataBlock<uint_1>
685#pragma define_template NDataBlock<uint_2>
686#pragma define_template NDataBlock<int_2>
687#pragma define_template NDataBlock<int_4>
688#pragma define_template NDataBlock<int_8>
689#pragma define_template NDataBlock<uint_4>
690#pragma define_template NDataBlock<uint_8>
691#pragma define_template NDataBlock<r_4>
692#pragma define_template NDataBlock<r_8>
693#pragma define_template NDataBlock< complex<float> >
694#pragma define_template NDataBlock< complex<double> >
695// Instances des delegues FileIO (PPersist)
696#pragma define_template FIO_NDataBlock<uint_1>
697#pragma define_template FIO_NDataBlock<uint_2>
698#pragma define_template FIO_NDataBlock<int_2>
699#pragma define_template FIO_NDataBlock<int_4>
700#pragma define_template FIO_NDataBlock<int_8>
701#pragma define_template FIO_NDataBlock<uint_4>
702#pragma define_template FIO_NDataBlock<uint_8>
703#pragma define_template FIO_NDataBlock<r_8>
704#pragma define_template FIO_NDataBlock<r_4>
705#pragma define_template FIO_NDataBlock< complex<float> >
706#pragma define_template FIO_NDataBlock< complex<double> >
707#endif
708
709
710#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
711template class NDataBlock<uint_1>;
712template class NDataBlock<uint_2>;
713template class NDataBlock<int_2>;
714template class NDataBlock<int_4>;
715template class NDataBlock<int_8>;
716template class NDataBlock<uint_4>;
717template class NDataBlock<uint_8>;
718template class NDataBlock<r_4>;
719template class NDataBlock<r_8>;
720template class NDataBlock< complex<float> >;
721template class NDataBlock< complex<double> >;
722// Instances des delegues FileIO (PPersist)
723template class FIO_NDataBlock<uint_1>;
724template class FIO_NDataBlock<uint_2>;
725template class FIO_NDataBlock<int_2>;
726template class FIO_NDataBlock<int_4>;
727template class FIO_NDataBlock<int_8>;
728template class FIO_NDataBlock<uint_4>;
729template class FIO_NDataBlock<uint_8>;
730template class FIO_NDataBlock<r_8>;
731template class FIO_NDataBlock<r_4>;
732template class FIO_NDataBlock< complex<float> >;
733template class FIO_NDataBlock< complex<double> >;
734#endif
Note: See TracBrowser for help on using the repository browser.