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

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

modif ReSize() cmv 27/4/99

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