[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
|
---|
[2615] | 4 | #include "sopnamsp.h"
|
---|
[802] | 5 | #include "machdefs.h"
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 | #include <stdlib.h>
|
---|
[2322] | 8 | #include <iostream>
|
---|
[802] | 9 | #include <complex>
|
---|
| 10 | #include "pexceptions.h"
|
---|
[2441] | 11 | #include "datatype.h"
|
---|
[802] | 12 | #include "fiondblock.h"
|
---|
[1967] | 13 | #include <typeinfo>
|
---|
[802] | 14 |
|
---|
| 15 | ////////////////////////////////////////////////////////////////
|
---|
| 16 | // -------------------------------------------------------------------------
|
---|
| 17 | // Les objets delegues pour la gestion de persistance
|
---|
| 18 | // -------------------------------------------------------------------------
|
---|
[2805] | 19 | /*!
|
---|
| 20 | \class SOPHYA::FIO_NDataBlock
|
---|
| 21 | \ingroup BaseTools
|
---|
| 22 | Handler for PPF persistence of NDataBlock<T> classes.
|
---|
| 23 | */
|
---|
[802] | 24 |
|
---|
| 25 | /*
|
---|
| 26 | template <class T>
|
---|
| 27 | void ObjFileIO< NDataBlock<T> >::ReadSelf(PInPersist& is)
|
---|
| 28 | template <class T>
|
---|
| 29 | void ObjFileIO< NDataBlock<T> >::WriteSelf(POutPersist& os)
|
---|
| 30 | */
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | template <class T>
|
---|
| 34 | FIO_NDataBlock<T>::FIO_NDataBlock()
|
---|
| 35 | {
|
---|
| 36 | dobj=new NDataBlock<T>;
|
---|
| 37 | ownobj=true;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | template <class T>
|
---|
| 41 | FIO_NDataBlock<T>::FIO_NDataBlock(string const & filename)
|
---|
| 42 | {
|
---|
| 43 | dobj=new NDataBlock<T>;
|
---|
| 44 | ownobj=true;
|
---|
| 45 | Read(filename);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | template <class T>
|
---|
| 49 | FIO_NDataBlock<T>::FIO_NDataBlock(const NDataBlock<T> & obj)
|
---|
| 50 | {
|
---|
| 51 | dobj = new NDataBlock<T>(obj);
|
---|
| 52 | ownobj=true;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | template <class T>
|
---|
| 56 | FIO_NDataBlock<T>::FIO_NDataBlock(NDataBlock<T> * obj)
|
---|
| 57 | {
|
---|
| 58 | dobj = obj;
|
---|
| 59 | ownobj=false;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | template <class T>
|
---|
| 63 | FIO_NDataBlock<T>::~FIO_NDataBlock()
|
---|
| 64 | {
|
---|
| 65 | if (ownobj && dobj) delete dobj;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | template <class T>
|
---|
| 69 | AnyDataObj* FIO_NDataBlock<T>::DataObj()
|
---|
| 70 | {
|
---|
| 71 | return(dobj);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | template <class T>
|
---|
| 75 | void FIO_NDataBlock<T>::SetDataObj(AnyDataObj & o)
|
---|
| 76 | {
|
---|
| 77 | NDataBlock<T> * po = dynamic_cast< NDataBlock<T> * >(&o);
|
---|
[1967] | 78 | if (po == NULL) {
|
---|
| 79 | char buff[160];
|
---|
| 80 | sprintf(buff,"FIO_NDataBlock<T><%s>::SetDataObj(%s) - Object type error ! ",
|
---|
| 81 | DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
|
---|
| 82 | throw TypeMismatchExc(PExcLongMessage(buff));
|
---|
| 83 | }
|
---|
[802] | 84 | if (ownobj && dobj) delete dobj;
|
---|
| 85 | dobj = po; ownobj = false;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | template <class T>
|
---|
| 89 | uint_8 FIO_NDataBlock<T>::getMemOId() const
|
---|
| 90 | {
|
---|
| 91 | uint_8 rv = 0;
|
---|
[1426] | 92 | if (dobj) rv = (uint_8)(dobj->DRefId());
|
---|
[802] | 93 | return(rv);
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | template <class T>
|
---|
| 97 | void FIO_NDataBlock<T>::ShareDataReference(PPersist & pp)
|
---|
| 98 | {
|
---|
| 99 | FIO_NDataBlock<T> *ppo = dynamic_cast< FIO_NDataBlock<T> * >(&pp);
|
---|
| 100 | if (ppo == NULL) throw TypeMismatchExc("FIO_NDataBlock<T>::ShareDataReference() - Type Mismatch Error");
|
---|
| 101 | if (ppo->dobj) {
|
---|
| 102 | if (dobj == NULL) { dobj = new NDataBlock<T>; ownobj = true; }
|
---|
| 103 | dobj->Share(*(ppo->dobj));
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | template <class T>
|
---|
| 108 | PPersist* FIO_NDataBlock<T>::CloneSharedReference()
|
---|
| 109 | {
|
---|
| 110 | FIO_NDataBlock<T> * ppo = new FIO_NDataBlock<T>;
|
---|
| 111 | if (dobj) (ppo->dobj)->Share(*dobj);
|
---|
| 112 | return(ppo);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[2441] | 115 | //---------------------------------------------------------------------------
|
---|
| 116 | // Pour compatibilite de lecture avec PPF V2
|
---|
| 117 | inline void PIOSReadArray(PInPersist & is, uint_1 * arr, size_t n)
|
---|
| 118 | { is.GetBytes(arr, n); }
|
---|
[3661] | 119 | inline void PIOSReadArray(PInPersist & is, int_1 * arr, size_t n)
|
---|
| 120 | { is.Get(arr, n); }
|
---|
[2441] | 121 | inline void PIOSReadArray(PInPersist & is, uint_2 * arr, size_t n)
|
---|
| 122 | { is.Get(arr, n); }
|
---|
| 123 | inline void PIOSReadArray(PInPersist & is, int_2 * arr, size_t n)
|
---|
| 124 | { is.Get(arr, n); }
|
---|
| 125 | inline void PIOSReadArray(PInPersist & is, uint_4 * arr, size_t n)
|
---|
| 126 | { is.Get(arr, n); }
|
---|
| 127 | inline void PIOSReadArray(PInPersist & is, int_4 * arr, size_t n)
|
---|
| 128 | { is.Get(arr, n); }
|
---|
| 129 | inline void PIOSReadArray(PInPersist & is, uint_8 * arr, size_t n)
|
---|
| 130 | { is.Get(arr, n); }
|
---|
| 131 | inline void PIOSReadArray(PInPersist & is, int_8 * arr, size_t n)
|
---|
| 132 | { is.Get(arr, n); }
|
---|
| 133 | inline void PIOSReadArray(PInPersist & is, r_4 * arr, size_t n)
|
---|
| 134 | { is.Get(arr, n); }
|
---|
| 135 | inline void PIOSReadArray(PInPersist & is, r_8 * arr, size_t n)
|
---|
| 136 | { is.Get(arr, n); }
|
---|
| 137 | inline void PIOSReadArray(PInPersist & is, complex<float> * arr, size_t n)
|
---|
| 138 | { r_4 * pr = (r_4 *)arr; is.Get(pr, n*2); }
|
---|
| 139 | inline void PIOSReadArray(PInPersist & is, complex<double> * arr, size_t n)
|
---|
| 140 | { r_8 * pr = (r_8 *)arr; is.Get(pr, n*2); }
|
---|
[3750] | 141 | #ifdef SO_LDBLE128
|
---|
| 142 | // ces fonctions ne devraient jamais etre appelees ( pas de r_16 en V_PPF <= 3 )
|
---|
| 143 | inline void PIOSReadArray(PInPersist & is, r_16 * arr, size_t n)
|
---|
| 144 | { is.Get(arr, n); }
|
---|
| 145 | inline void PIOSReadArray(PInPersist & is, complex<long double> * arr, size_t n)
|
---|
| 146 | { r_16 * pr = (r_16 *)arr; is.Get(pr, n*2); }
|
---|
| 147 | #endif
|
---|
[2441] | 148 | //---------------------------------------------------------------------------
|
---|
| 149 |
|
---|
[802] | 150 | template <class T>
|
---|
| 151 | void FIO_NDataBlock<T>::ReadSelf(PInPersist& is)
|
---|
| 152 | {
|
---|
| 153 | // On lit les 3 premiers uint_8
|
---|
| 154 | uint_8 itab[3];
|
---|
| 155 | is.Get(itab, 3);
|
---|
[3385] | 156 | if (dobj == NULL) {
|
---|
| 157 | if (itab[1] > 0) dobj = new NDataBlock<T>(itab[1]);
|
---|
| 158 | else dobj = new NDataBlock<T>();
|
---|
| 159 | }
|
---|
| 160 | else {
|
---|
| 161 | if (itab[1] != dobj->Size()) {
|
---|
| 162 | if (itab[1] > 0) dobj->ReSize(itab[1]);
|
---|
| 163 | else dobj->Dealloc();
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | if (dobj->Size() < 1) return; // Pas de donnees a lire ...
|
---|
[802] | 167 | // On lit le tableau de nombres
|
---|
[2441] | 168 | if (is.Version() <= 2) // lecture ancienne version PPF
|
---|
| 169 | PIOSReadArray(is, dobj->Data(), dobj->Size());
|
---|
| 170 | else is.Get(dobj->Data(), dobj->Size());
|
---|
[802] | 171 | }
|
---|
| 172 |
|
---|
| 173 |
|
---|
| 174 | template <class T>
|
---|
| 175 | void FIO_NDataBlock<T>::WriteSelf(POutPersist& os) const
|
---|
| 176 | {
|
---|
| 177 | if (dobj == NULL) return; // Attention - $CHECK$ Reza 26/04/99
|
---|
| 178 | // On ecrit 3 uint_8
|
---|
| 179 | // 0 : Numero de version, 1 : Taille, 2 reserve a l
|
---|
| 180 | uint_8 itab[3];
|
---|
| 181 | itab[0] = 1;
|
---|
| 182 | itab[1] = dobj->Size();
|
---|
| 183 | itab[2] = 0;
|
---|
| 184 | os.Put(itab, 3);
|
---|
| 185 | // On ecrit le tableau de nombres
|
---|
[3385] | 186 | if (dobj->Size() > 0) // On ecrit les donnees, s'il y en a ... (sz>0)
|
---|
| 187 | os.Put(dobj->Data(), dobj->Size());
|
---|
[802] | 188 | }
|
---|
| 189 |
|
---|
| 190 | ///////////////////////////////////////////////////////////////
|
---|
| 191 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
| 192 | // Instances des delegues FileIO (PPersist)
|
---|
| 193 | #pragma define_template FIO_NDataBlock<uint_1>
|
---|
| 194 | #pragma define_template FIO_NDataBlock<uint_2>
|
---|
[3661] | 195 | #pragma define_template FIO_NDataBlock<uint_4>
|
---|
| 196 | #pragma define_template FIO_NDataBlock<uint_8>
|
---|
| 197 | #pragma define_template FIO_NDataBlock<int_1>
|
---|
[802] | 198 | #pragma define_template FIO_NDataBlock<int_2>
|
---|
| 199 | #pragma define_template FIO_NDataBlock<int_4>
|
---|
| 200 | #pragma define_template FIO_NDataBlock<int_8>
|
---|
| 201 | #pragma define_template FIO_NDataBlock<r_8>
|
---|
| 202 | #pragma define_template FIO_NDataBlock<r_4>
|
---|
| 203 | #pragma define_template FIO_NDataBlock< complex<r_4> >
|
---|
| 204 | #pragma define_template FIO_NDataBlock< complex<r_8> >
|
---|
[3750] | 205 | #ifdef SO_LDBLE128
|
---|
| 206 | #pragma define_template FIO_NDataBlock<r_16>
|
---|
| 207 | #pragma define_template FIO_NDataBlock< complex<r_16> >
|
---|
[802] | 208 | #endif
|
---|
| 209 |
|
---|
[3750] | 210 | #endif
|
---|
| 211 |
|
---|
[802] | 212 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
[2867] | 213 | namespace SOPHYA {
|
---|
[802] | 214 | // Instances des delegues FileIO (PPersist)
|
---|
| 215 | template class FIO_NDataBlock<uint_1>;
|
---|
| 216 | template class FIO_NDataBlock<uint_2>;
|
---|
[3661] | 217 | template class FIO_NDataBlock<uint_4>;
|
---|
| 218 | template class FIO_NDataBlock<uint_8>;
|
---|
| 219 | template class FIO_NDataBlock<int_1>;
|
---|
[802] | 220 | template class FIO_NDataBlock<int_2>;
|
---|
| 221 | template class FIO_NDataBlock<int_4>;
|
---|
| 222 | template class FIO_NDataBlock<int_8>;
|
---|
| 223 | template class FIO_NDataBlock<r_8>;
|
---|
| 224 | template class FIO_NDataBlock<r_4>;
|
---|
| 225 | template class FIO_NDataBlock< complex<r_4> >;
|
---|
| 226 | template class FIO_NDataBlock< complex<r_8> >;
|
---|
[3750] | 227 | #ifdef SO_LDBLE128
|
---|
| 228 | template class FIO_NDataBlock<r_16>;
|
---|
| 229 | template class FIO_NDataBlock< complex<r_16> >;
|
---|
| 230 | #endif
|
---|
[2867] | 231 | }
|
---|
[802] | 232 | #endif
|
---|