| 1 | // This may look like C code, but it is really -*- C++ -*-
 | 
|---|
| 2 | // Class DataTable  (Row-Column data table in memory) 
 | 
|---|
| 3 | //   R. Ansari -  Avril 2005
 | 
|---|
| 4 | //   (C)  LAL-IN2P3/CNRS    CEA-DAPNIA  
 | 
|---|
| 5 | 
 | 
|---|
| 6 | #ifndef SWPPFDTABLE_H_SEEN
 | 
|---|
| 7 | #define SWPPFDTABLE_H_SEEN
 | 
|---|
| 8 | 
 | 
|---|
| 9 | #include "basedtable.h"
 | 
|---|
| 10 | #include "swsegdb.h"
 | 
|---|
| 11 | #include "ppfswapper.h"
 | 
|---|
| 12 | #include "objfio.h"
 | 
|---|
| 13 | 
 | 
|---|
| 14 | 
 | 
|---|
| 15 | namespace SOPHYA {
 | 
|---|
| 16 | 
 | 
|---|
| 17 | //! An implementation of BaseDataTable with using a PPF stream as swap space.
 | 
|---|
| 18 | class SwPPFDataTable : public BaseDataTable {
 | 
|---|
| 19 | public:
 | 
|---|
| 20 |   SwPPFDataTable(sa_size_t segsz=512);
 | 
|---|
| 21 |   SwPPFDataTable(POutPersist & os, sa_size_t segsz=512); 
 | 
|---|
| 22 |   SwPPFDataTable(SwPPFDataTable const& a); 
 | 
|---|
| 23 | 
 | 
|---|
| 24 |   virtual ~SwPPFDataTable();
 | 
|---|
| 25 | 
 | 
|---|
| 26 |   virtual sa_size_t AddColumn(FieldType ft, string const & cnom);
 | 
|---|
| 27 | 
 | 
|---|
| 28 |   // Filling data structures (adding lines/rows)
 | 
|---|
| 29 |   virtual sa_size_t AddRow(const r_8* data);
 | 
|---|
| 30 |   virtual sa_size_t AddRow(const MuTyV * data);
 | 
|---|
| 31 |   virtual sa_size_t AddRow(DataTableRow const& data);
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   //! Equal (copy) operator - Copies the data and the structure if necessary from \b a   
 | 
|---|
| 34 |   inline  SwPPFDataTable& operator = (BaseDataTable const& a) 
 | 
|---|
| 35 |   { CopyMerge(a, true) ; return *this ; } 
 | 
|---|
| 36 |   //! Equal (copy) operator - Copies the structure and shares the data \b a   
 | 
|---|
| 37 |   inline SwPPFDataTable&  operator = (SwPPFDataTable const& a) 
 | 
|---|
| 38 |   { Clear(); Share(a); return *this ; } 
 | 
|---|
| 39 | 
 | 
|---|
| 40 |   //  Pour la gestion de persistance PPF
 | 
|---|
| 41 |   friend class ObjFileIO<BaseDataTable> ;
 | 
|---|
| 42 |   
 | 
|---|
| 43 |   //! Reset(Clear) the table content and structure
 | 
|---|
| 44 |   virtual void Clear();
 | 
|---|
| 45 |   /*! This method should be called in order to empty the swapout buffer, 
 | 
|---|
| 46 |      before saving object to PPF stream 
 | 
|---|
| 47 |   */
 | 
|---|
| 48 |   void SwapOutAll() const;
 | 
|---|
| 49 | protected:
 | 
|---|
| 50 |   SwPPFDataTable(PInPersist & is, sa_size_t segsz); 
 | 
|---|
| 51 |   void Share(SwPPFDataTable const & a);
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   // Donnees en memoire
 | 
|---|
| 54 |   std::vector< SwSegDataBlock<int_4> > mICols; 
 | 
|---|
| 55 |   PPFDataSwapper<int_4> mISwapper;
 | 
|---|
| 56 |   std::vector< SwSegDataBlock<int_8> > mLCols; 
 | 
|---|
| 57 |   PPFDataSwapper<int_8> mLSwapper;
 | 
|---|
| 58 |   std::vector< SwSegDataBlock<r_4> > mFCols;
 | 
|---|
| 59 |   PPFDataSwapper<r_4> mFSwapper;
 | 
|---|
| 60 |   std::vector< SwSegDataBlock<r_8> > mDCols; 
 | 
|---|
| 61 |   PPFDataSwapper<r_8> mDSwapper;
 | 
|---|
| 62 |   std::vector< SwSegDataBlock< complex<r_4> > > mYCols;
 | 
|---|
| 63 |   PPFDataSwapper< complex<r_4> > mYSwapper;
 | 
|---|
| 64 |   std::vector< SwSegDataBlock< complex<r_8> > > mZCols;
 | 
|---|
| 65 |   PPFDataSwapper< complex<r_8> > mZSwapper;
 | 
|---|
| 66 |   std::vector< SwSegDataBlock<string> > mSCols;    
 | 
|---|
| 67 |   PPFDataSwapper<string> mSSwapper;
 | 
|---|
| 68 |  
 | 
|---|
| 69 |   // Output swap stream doit etre cree avant l'appel au constructeur
 | 
|---|
| 70 |   // et rester valide (non detruit) tant que l'objet SwPPFDataTable existe
 | 
|---|
| 71 |   POutPersist* mSwOut;   
 | 
|---|
| 72 |   // Input swap stream - On cree un input swap stream et on fait 
 | 
|---|
| 73 |   // un comptage de reference pour le detruire lorsque tous les tables
 | 
|---|
| 74 |   // l'utilisant sont supprimes
 | 
|---|
| 75 |   //! \cond    Pour NE PAS inclure dans la doc
 | 
|---|
| 76 |   typedef struct { PInPersist* pis; uint_4 refcnt; } St_InSwap; 
 | 
|---|
| 77 |   //! \endcond 
 | 
|---|
| 78 |   St_InSwap * mSwIn;
 | 
|---|
| 79 | }; 
 | 
|---|
| 80 |   
 | 
|---|
| 81 | /*! Writes the object in the POutPersist stream \b os */
 | 
|---|
| 82 | inline POutPersist& operator << (POutPersist& os, SwPPFDataTable & obj)
 | 
|---|
| 83 | { obj.SwapOutAll();  ObjFileIO<BaseDataTable> fio(&obj);  fio.Write(os);  return(os); }
 | 
|---|
| 84 | /*! Reads the object from the PInPersist stream \b is */
 | 
|---|
| 85 | inline PInPersist& operator >> (PInPersist& is, SwPPFDataTable & obj)
 | 
|---|
| 86 | {  ObjFileIO<BaseDataTable> fio(&obj); is.SkipToNextObject(); fio.Read(is); return(is); }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | } // namespace SOPHYA
 | 
|---|
| 89 | 
 | 
|---|
| 90 | #endif
 | 
|---|
| 91 | 
 | 
|---|