[2660] | 1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
| 2 | // Gestion de block de donnees swapable
|
---|
| 3 | // R. Ansari Mars 2005
|
---|
| 4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
| 5 | #ifndef PPFSWAPPER_H
|
---|
| 6 | #define PPFSWAPPER_H
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | #include "machdefs.h"
|
---|
| 10 | #include "swsegdb.h"
|
---|
| 11 | #include "ppersist.h"
|
---|
| 12 | #include "ppftpointerio.h"
|
---|
| 13 |
|
---|
| 14 | /*!
|
---|
| 15 | \class SOPHYA::PPFDataSwapper
|
---|
| 16 | \ingroup BaseTools
|
---|
| 17 | Implementation of SOPHYA::DataSwapperInterface interface on PPF streams
|
---|
| 18 | (POutPersist , PInPersist) to be used with SOPHYA::SwSegDataBlock classes.
|
---|
[2805] | 19 | the identifier idx is not used in this implementation. In case of re-writing
|
---|
| 20 | to swap, the previous position is ignored, the data is re-written to swap
|
---|
| 21 | and a new swap position is returned.
|
---|
[2660] | 22 | */
|
---|
| 23 |
|
---|
[2805] | 24 | namespace SOPHYA {
|
---|
| 25 |
|
---|
[2660] | 26 | template <class T>
|
---|
| 27 | class PPFDataSwapper : public DataSwapperInterface<T> {
|
---|
| 28 | public:
|
---|
[2695] | 29 | PPFDataSwapper() { ppfos = NULL; ppfis = NULL;}
|
---|
[2660] | 30 | PPFDataSwapper(POutPersist & os) { ppfos = &os; ppfis = NULL;}
|
---|
| 31 | PPFDataSwapper(PInPersist & is) { ppfos = NULL; ppfis = &is;}
|
---|
| 32 | PPFDataSwapper(PInPersist & is, POutPersist & os) { ppfos = &os; ppfis = &is;}
|
---|
[2698] | 33 |
|
---|
| 34 | inline PInPersist & InStream() { return *ppfis; }
|
---|
[2794] | 35 | inline POutPersist & OutStream() { return *ppfos; }
|
---|
[2698] | 36 | inline void SetInStream(PInPersist & is) { ppfis = &is; }
|
---|
| 37 | inline void SetOutStream(POutPersist & os) { ppfos = &os; }
|
---|
| 38 |
|
---|
| 39 | // Operateur = , on recopie les pointeurs des streams
|
---|
[2794] | 40 | inline PPFDataSwapper<T>& operator = (PPFDataSwapper<T> const & a)
|
---|
[2698] | 41 | { ppfis = a.ppfis; ppfos = a.ppfos; return *this; }
|
---|
| 42 |
|
---|
[2660] | 43 | virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false)
|
---|
| 44 | {
|
---|
[2863] | 45 | if (ppfos == NULL)
|
---|
| 46 | throw NotAvailableOperation("PPFDataSwapper<T>::WriteToSwap() - No POutPersist stream !");
|
---|
[2660] | 47 | int_8 tag = ppfos->WritePositionTag();
|
---|
| 48 | PPF_TPointer_IO<T>::Write(*ppfos, d, sz);
|
---|
| 49 | return tag;
|
---|
| 50 | }
|
---|
| 51 | virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
|
---|
| 52 | {
|
---|
[2863] | 53 | if (ppfis == NULL)
|
---|
| 54 | throw NotAvailableOperation("PPFDataSwapper<T>::ReadFromSwap() - No PInPersist stream !");
|
---|
[2660] | 55 | bool ok = ppfis->GotoPositionTag(swp);
|
---|
| 56 | PPF_TPointer_IO<T>::Read(*ppfis, d, sz);
|
---|
| 57 | return;
|
---|
| 58 | }
|
---|
[2863] | 59 | virtual DataSwapperInterface<T>* Clone()
|
---|
| 60 | {
|
---|
| 61 | PPFDataSwapper<T> * rsw = new PPFDataSwapper<T> ;
|
---|
| 62 | (*rsw) = *this;
|
---|
| 63 | return rsw;
|
---|
| 64 | }
|
---|
[2660] | 65 | protected:
|
---|
| 66 | POutPersist* ppfos;
|
---|
| 67 | PInPersist* ppfis;
|
---|
| 68 | };
|
---|
| 69 |
|
---|
| 70 | } // Fin du namespace
|
---|
| 71 |
|
---|
| 72 | #endif
|
---|