// Classe pour la gestion de persistance pour NDataBlock // C.Magneville 04/99-03/2000 // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA #include "sopnamsp.h" #include "machdefs.h" #include #include #include #include #include "pexceptions.h" #include "datatype.h" #include "fiondblock.h" #include //////////////////////////////////////////////////////////////// // ------------------------------------------------------------------------- // Les objets delegues pour la gestion de persistance // ------------------------------------------------------------------------- /*! \class SOPHYA::FIO_NDataBlock \ingroup BaseTools Handler for PPF persistence of NDataBlock classes. */ /* template void ObjFileIO< NDataBlock >::ReadSelf(PInPersist& is) template void ObjFileIO< NDataBlock >::WriteSelf(POutPersist& os) */ template FIO_NDataBlock::FIO_NDataBlock() { dobj=new NDataBlock; ownobj=true; } template FIO_NDataBlock::FIO_NDataBlock(string const & filename) { dobj=new NDataBlock; ownobj=true; Read(filename); } template FIO_NDataBlock::FIO_NDataBlock(const NDataBlock & obj) { dobj = new NDataBlock(obj); ownobj=true; } template FIO_NDataBlock::FIO_NDataBlock(NDataBlock * obj) { dobj = obj; ownobj=false; } template FIO_NDataBlock::~FIO_NDataBlock() { if (ownobj && dobj) delete dobj; } template AnyDataObj* FIO_NDataBlock::DataObj() { return(dobj); } template void FIO_NDataBlock::SetDataObj(AnyDataObj & o) { NDataBlock * po = dynamic_cast< NDataBlock * >(&o); if (po == NULL) { char buff[160]; sprintf(buff,"FIO_NDataBlock<%s>::SetDataObj(%s) - Object type error ! ", DataTypeInfo::getTypeName().c_str(), typeid(o).name()); throw TypeMismatchExc(PExcLongMessage(buff)); } if (ownobj && dobj) delete dobj; dobj = po; ownobj = false; } template uint_8 FIO_NDataBlock::getMemOId() const { uint_8 rv = 0; if (dobj) rv = (uint_8)(dobj->DRefId()); return(rv); } template void FIO_NDataBlock::ShareDataReference(PPersist & pp) { FIO_NDataBlock *ppo = dynamic_cast< FIO_NDataBlock * >(&pp); if (ppo == NULL) throw TypeMismatchExc("FIO_NDataBlock::ShareDataReference() - Type Mismatch Error"); if (ppo->dobj) { if (dobj == NULL) { dobj = new NDataBlock; ownobj = true; } dobj->Share(*(ppo->dobj)); } } template PPersist* FIO_NDataBlock::CloneSharedReference() { FIO_NDataBlock * ppo = new FIO_NDataBlock; if (dobj) (ppo->dobj)->Share(*dobj); return(ppo); } //--------------------------------------------------------------------------- // Pour compatibilite de lecture avec PPF V2 inline void PIOSReadArray(PInPersist & is, uint_1 * arr, size_t n) { is.GetBytes(arr, n); } inline void PIOSReadArray(PInPersist & is, int_1 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, uint_2 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, int_2 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, uint_4 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, int_4 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, uint_8 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, int_8 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, r_4 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, r_8 * arr, size_t n) { is.Get(arr, n); } inline void PIOSReadArray(PInPersist & is, complex * arr, size_t n) { r_4 * pr = (r_4 *)arr; is.Get(pr, n*2); } inline void PIOSReadArray(PInPersist & is, complex * arr, size_t n) { r_8 * pr = (r_8 *)arr; is.Get(pr, n*2); } //--------------------------------------------------------------------------- template void FIO_NDataBlock::ReadSelf(PInPersist& is) { // On lit les 3 premiers uint_8 uint_8 itab[3]; is.Get(itab, 3); if (dobj == NULL) { if (itab[1] > 0) dobj = new NDataBlock(itab[1]); else dobj = new NDataBlock(); } else { if (itab[1] != dobj->Size()) { if (itab[1] > 0) dobj->ReSize(itab[1]); else dobj->Dealloc(); } } if (dobj->Size() < 1) return; // Pas de donnees a lire ... // On lit le tableau de nombres if (is.Version() <= 2) // lecture ancienne version PPF PIOSReadArray(is, dobj->Data(), dobj->Size()); else is.Get(dobj->Data(), dobj->Size()); } template void FIO_NDataBlock::WriteSelf(POutPersist& os) const { if (dobj == NULL) return; // Attention - $CHECK$ Reza 26/04/99 // On ecrit 3 uint_8 // 0 : Numero de version, 1 : Taille, 2 reserve a l uint_8 itab[3]; itab[0] = 1; itab[1] = dobj->Size(); itab[2] = 0; os.Put(itab, 3); // On ecrit le tableau de nombres if (dobj->Size() > 0) // On ecrit les donnees, s'il y en a ... (sz>0) os.Put(dobj->Data(), dobj->Size()); } /////////////////////////////////////////////////////////////// #ifdef __CXX_PRAGMA_TEMPLATES__ // Instances des delegues FileIO (PPersist) #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock #pragma define_template FIO_NDataBlock< complex > #pragma define_template FIO_NDataBlock< complex > #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) namespace SOPHYA { // Instances des delegues FileIO (PPersist) template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock; template class FIO_NDataBlock< complex >; template class FIO_NDataBlock< complex >; } #endif