// Persistence manager for template numerical arrays // R. Ansari, C.Magneville 03/2000 #include "pexceptions.h" #include "fiondblock.h" #include "fioarr.h" #include "tmatrix.h" #include "tvector.h" // -------------------------------------------------------- // Les objets delegues pour la gestion de persistance // -------------------------------------------------------- /*! \class SOPHYA::FIO_TArray \ingroup TArray Class for persistent management of TArray This class manage also persistence for TMatrix and TVector. \sa TArray TMatrix TVector. */ /////////////////////////////////////////////////////////// //! Default constructor template FIO_TArray::FIO_TArray() { dobj=NULL; ownobj=false; } //! Constructor from the file \b filename template FIO_TArray::FIO_TArray(string const & filename) { dobj=NULL; ownobj=false; Read(filename); } //! Constructor from the TArray \b obj template FIO_TArray::FIO_TArray(const TArray & obj) { const TVector * tv = dynamic_cast *>(&obj); if (tv != NULL) dobj = new TVector(*tv, true); else { const TMatrix * tm = dynamic_cast *>(&obj); if (tm != NULL) dobj = new TMatrix(*tm, true); else dobj = new TArray(obj, true); } ownobj=true; } //! Connect with a TArray \b obj template FIO_TArray::FIO_TArray(TArray * obj) { dobj = obj; ownobj=false; } //! destructor template FIO_TArray::~FIO_TArray() { if (ownobj && dobj) delete dobj; } //! Return pointer to the connected TArray template AnyDataObj* FIO_TArray::DataObj() { return(dobj); } //! Connect TArray \b o template void FIO_TArray::SetDataObj(AnyDataObj & o) { TArray * po = dynamic_cast< TArray * >(&o); if (po == NULL) return; if (ownobj && dobj) delete dobj; dobj = po; ownobj = false; } template void FIO_TArray::ReadSelf(PInPersist& is) { // On lit les 5 premiers uint_4 // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector uint_4 itab[5]; is.Get(itab,5); if (dobj == NULL) { if (itab[1] == 12) dobj = new TMatrix; else if (itab[1] == 48) dobj = new TVector; else dobj = new TArray; } // On lit les tailles, etc ... is.Get(dobj->ndim_); is.Get(dobj->size_, BASEARRAY_MAXNDIMS); is.Get(dobj->totsize_); is.Get(dobj->step_, BASEARRAY_MAXNDIMS); is.Get(dobj->minstep_); is.Get(dobj->moystep_); is.Get(dobj->offset_); is.Get(dobj->marowi_); is.Get(dobj->macoli_); is.Get(dobj->veceli_); // On lit le datablock is >> dobj->DataBlock(); // On ecrit le DVList info si necessaire if (itab[2] != 0) is >> dobj->Info(); } template void FIO_TArray::WriteSelf(POutPersist& os) const { if (dobj == NULL) return; // On ecrit 5 uint_4 .... // 0: Numero de version, 1 : Type (Array, matrix, Vector, ...) 2 != 0 , has Info // 1:Type = 0 TArray , 12=(4+8) TMatrix , 48=(16+32) TVector uint_4 typa = 0; TVector * tv = dynamic_cast *>(dobj); if (tv != NULL) typa = 48; else { TMatrix * tm = dynamic_cast *>(dobj); if (tm != NULL) typa = 12; else typa = 0; } uint_4 itab[5]; itab[0] = 1; // Numero de version a 1 itab[1] = typa; // Real object type itab[2] = (dobj->mInfo != NULL) ? 1 : 0; itab[3] = itab[4] = 0; os.Put(itab,5); // On ecrit les tailles, etc ... os.Put(dobj->ndim_); os.Put(dobj->size_, BASEARRAY_MAXNDIMS); os.Put(dobj->totsize_); os.Put(dobj->step_, BASEARRAY_MAXNDIMS); os.Put(dobj->minstep_); os.Put(dobj->moystep_); os.Put(dobj->offset_); os.Put(dobj->marowi_); os.Put(dobj->macoli_); os.Put(dobj->veceli_); // On ecrit le datablock os << dobj->DataBlock(); // On ecrit le DVList info si necessaire if (itab[2] != 0) os << dobj->Info(); } /////////////////////////////////////////////////////////////// #ifdef __CXX_PRAGMA_TEMPLATES__ // Instances des delegues FileIO (PPersist) // #pragma define_template FIO_TArray #pragma define_template FIO_TArray // #pragma define_template FIO_TArray #pragma define_template FIO_TArray #pragma define_template FIO_TArray // #pragma define_template FIO_TArray // #pragma define_template FIO_TArray #pragma define_template FIO_TArray #pragma define_template FIO_TArray #pragma define_template FIO_TArray< complex > #pragma define_template FIO_TArray< complex > #endif #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES) // Instances des delegues FileIO (PPersist) // template class FIO_TArray; template class FIO_TArray; // template class FIO_TArray; template class FIO_TArray; template class FIO_TArray; // template class FIO_TArray; // template class FIO_TArray; template class FIO_TArray; template class FIO_TArray; template class FIO_TArray< complex >; template class FIO_TArray< complex >; #endif