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