| [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> | 
|---|
|  | 7 | #include <iostream.h> | 
|---|
|  | 8 | #include <complex> | 
|---|
|  | 9 | #include "pexceptions.h" | 
|---|
|  | 10 | #include "fiondblock.h" | 
|---|
|  | 11 |  | 
|---|
|  | 12 | //////////////////////////////////////////////////////////////// | 
|---|
|  | 13 | // ------------------------------------------------------------------------- | 
|---|
|  | 14 | //   Les objets delegues pour la gestion de persistance | 
|---|
|  | 15 | // ------------------------------------------------------------------------- | 
|---|
|  | 16 |  | 
|---|
|  | 17 | /* | 
|---|
|  | 18 | template <class T> | 
|---|
|  | 19 | void ObjFileIO< NDataBlock<T> >::ReadSelf(PInPersist& is) | 
|---|
|  | 20 | template <class T> | 
|---|
|  | 21 | void ObjFileIO< NDataBlock<T> >::WriteSelf(POutPersist& os) | 
|---|
|  | 22 | */ | 
|---|
|  | 23 |  | 
|---|
|  | 24 | // Pour pouvoir ecrire des tableaux de complex, en attendant | 
|---|
|  | 25 | // PIn/POutPersist::Get/Put(complex<>) | 
|---|
|  | 26 | #include "piocmplx.h" | 
|---|
|  | 27 |  | 
|---|
|  | 28 | template <class T> | 
|---|
|  | 29 | FIO_NDataBlock<T>::FIO_NDataBlock() | 
|---|
|  | 30 | { | 
|---|
|  | 31 | dobj=new NDataBlock<T>; | 
|---|
|  | 32 | ownobj=true; | 
|---|
|  | 33 | } | 
|---|
|  | 34 |  | 
|---|
|  | 35 | template <class T> | 
|---|
|  | 36 | FIO_NDataBlock<T>::FIO_NDataBlock(string const & filename) | 
|---|
|  | 37 | { | 
|---|
|  | 38 | dobj=new NDataBlock<T>; | 
|---|
|  | 39 | ownobj=true; | 
|---|
|  | 40 | Read(filename); | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | template <class T> | 
|---|
|  | 44 | FIO_NDataBlock<T>::FIO_NDataBlock(const NDataBlock<T> & obj) | 
|---|
|  | 45 | { | 
|---|
|  | 46 | dobj = new NDataBlock<T>(obj); | 
|---|
|  | 47 | ownobj=true; | 
|---|
|  | 48 | } | 
|---|
|  | 49 |  | 
|---|
|  | 50 | template <class T> | 
|---|
|  | 51 | FIO_NDataBlock<T>::FIO_NDataBlock(NDataBlock<T> * obj) | 
|---|
|  | 52 | { | 
|---|
|  | 53 | dobj = obj; | 
|---|
|  | 54 | ownobj=false; | 
|---|
|  | 55 | } | 
|---|
|  | 56 |  | 
|---|
|  | 57 | template <class T> | 
|---|
|  | 58 | FIO_NDataBlock<T>::~FIO_NDataBlock() | 
|---|
|  | 59 | { | 
|---|
|  | 60 | if (ownobj && dobj) delete dobj; | 
|---|
|  | 61 | } | 
|---|
|  | 62 |  | 
|---|
|  | 63 | template <class T> | 
|---|
|  | 64 | AnyDataObj* FIO_NDataBlock<T>::DataObj() | 
|---|
|  | 65 | { | 
|---|
|  | 66 | return(dobj); | 
|---|
|  | 67 | } | 
|---|
|  | 68 |  | 
|---|
|  | 69 | template <class T> | 
|---|
|  | 70 | void FIO_NDataBlock<T>::SetDataObj(AnyDataObj & o) | 
|---|
|  | 71 | { | 
|---|
|  | 72 | NDataBlock<T> * po = dynamic_cast< NDataBlock<T> * >(&o); | 
|---|
|  | 73 | if (po == NULL) throw TypeMismatchExc("FIO_NDataBlock<T>::SetDataObj() - Type Mismatch Error"); | 
|---|
|  | 74 | if (ownobj && dobj) delete dobj; | 
|---|
|  | 75 | dobj = po; ownobj = false; | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | template <class T> | 
|---|
|  | 79 | uint_8 FIO_NDataBlock<T>::getMemOId() const | 
|---|
|  | 80 | { | 
|---|
|  | 81 | uint_8 rv = 0; | 
|---|
|  | 82 | if (dobj) rv = (uint_8)(dobj->Begin()); | 
|---|
|  | 83 | return(rv); | 
|---|
|  | 84 | } | 
|---|
|  | 85 |  | 
|---|
|  | 86 | template <class T> | 
|---|
|  | 87 | void FIO_NDataBlock<T>::ShareDataReference(PPersist & pp) | 
|---|
|  | 88 | { | 
|---|
|  | 89 | FIO_NDataBlock<T> *ppo = dynamic_cast< FIO_NDataBlock<T> * >(&pp); | 
|---|
|  | 90 | if (ppo == NULL) throw TypeMismatchExc("FIO_NDataBlock<T>::ShareDataReference() - Type Mismatch Error"); | 
|---|
|  | 91 | if (ppo->dobj) { | 
|---|
|  | 92 | if (dobj == NULL) { dobj = new NDataBlock<T>; ownobj = true; } | 
|---|
|  | 93 | dobj->Share(*(ppo->dobj)); | 
|---|
|  | 94 | } | 
|---|
|  | 95 | } | 
|---|
|  | 96 |  | 
|---|
|  | 97 | template <class T> | 
|---|
|  | 98 | PPersist* FIO_NDataBlock<T>::CloneSharedReference() | 
|---|
|  | 99 | { | 
|---|
|  | 100 | FIO_NDataBlock<T> * ppo = new FIO_NDataBlock<T>; | 
|---|
|  | 101 | if (dobj) (ppo->dobj)->Share(*dobj); | 
|---|
|  | 102 | return(ppo); | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | template <class T> | 
|---|
|  | 106 | void FIO_NDataBlock<T>::ReadSelf(PInPersist& is) | 
|---|
|  | 107 | { | 
|---|
|  | 108 | // On lit les 3 premiers uint_8 | 
|---|
|  | 109 | uint_8 itab[3]; | 
|---|
|  | 110 | is.Get(itab, 3); | 
|---|
|  | 111 | if (dobj == NULL) dobj = new NDataBlock<T>(itab[1]); | 
|---|
|  | 112 | else if (itab[1] != dobj->Size()) dobj->ReSize(itab[1]); | 
|---|
|  | 113 | // On lit le tableau de nombres | 
|---|
|  | 114 | PIOSReadArray(is, dobj->Data(), dobj->Size()); | 
|---|
|  | 115 | } | 
|---|
|  | 116 |  | 
|---|
|  | 117 |  | 
|---|
|  | 118 | template <class T> | 
|---|
|  | 119 | void FIO_NDataBlock<T>::WriteSelf(POutPersist& os) const | 
|---|
|  | 120 | { | 
|---|
|  | 121 | if (dobj == NULL)   return;  // Attention - $CHECK$ Reza 26/04/99 | 
|---|
|  | 122 | //  On ecrit 3 uint_8 | 
|---|
|  | 123 | //  0 : Numero de version,  1 : Taille,  2  reserve a l | 
|---|
|  | 124 | uint_8 itab[3]; | 
|---|
|  | 125 | itab[0] = 1; | 
|---|
|  | 126 | itab[1] = dobj->Size(); | 
|---|
|  | 127 | itab[2] = 0; | 
|---|
|  | 128 | os.Put(itab, 3); | 
|---|
|  | 129 | //  On ecrit le tableau de nombres | 
|---|
|  | 130 | PIOSWriteArray(os, dobj->Data(), dobj->Size()); | 
|---|
|  | 131 | } | 
|---|
|  | 132 |  | 
|---|
|  | 133 | /////////////////////////////////////////////////////////////// | 
|---|
|  | 134 | #ifdef __CXX_PRAGMA_TEMPLATES__ | 
|---|
|  | 135 | // Instances des delegues FileIO (PPersist) | 
|---|
|  | 136 | #pragma define_template FIO_NDataBlock<uint_1> | 
|---|
|  | 137 | #pragma define_template FIO_NDataBlock<uint_2> | 
|---|
|  | 138 | #pragma define_template FIO_NDataBlock<int_2> | 
|---|
|  | 139 | #pragma define_template FIO_NDataBlock<int_4> | 
|---|
|  | 140 | #pragma define_template FIO_NDataBlock<int_8> | 
|---|
|  | 141 | #pragma define_template FIO_NDataBlock<uint_4> | 
|---|
|  | 142 | #pragma define_template FIO_NDataBlock<uint_8> | 
|---|
|  | 143 | #pragma define_template FIO_NDataBlock<r_8> | 
|---|
|  | 144 | #pragma define_template FIO_NDataBlock<r_4> | 
|---|
|  | 145 | #pragma define_template FIO_NDataBlock< complex<r_4> > | 
|---|
|  | 146 | #pragma define_template FIO_NDataBlock< complex<r_8> > | 
|---|
|  | 147 | #endif | 
|---|
|  | 148 |  | 
|---|
|  | 149 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) | 
|---|
|  | 150 | // Instances des delegues FileIO (PPersist) | 
|---|
|  | 151 | template class FIO_NDataBlock<uint_1>; | 
|---|
|  | 152 | template class FIO_NDataBlock<uint_2>; | 
|---|
|  | 153 | template class FIO_NDataBlock<int_2>; | 
|---|
|  | 154 | template class FIO_NDataBlock<int_4>; | 
|---|
|  | 155 | template class FIO_NDataBlock<int_8>; | 
|---|
|  | 156 | template class FIO_NDataBlock<uint_4>; | 
|---|
|  | 157 | template class FIO_NDataBlock<uint_8>; | 
|---|
|  | 158 | template class FIO_NDataBlock<r_8>; | 
|---|
|  | 159 | template class FIO_NDataBlock<r_4>; | 
|---|
|  | 160 | template class FIO_NDataBlock< complex<r_4> >; | 
|---|
|  | 161 | template class FIO_NDataBlock< complex<r_8> >; | 
|---|
|  | 162 | #endif | 
|---|