[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 | namespace SOPHYA {
|
---|
| 15 | /*!
|
---|
| 16 | \class SOPHYA::PPFDataSwapper
|
---|
| 17 | \ingroup BaseTools
|
---|
| 18 | Implementation of SOPHYA::DataSwapperInterface interface on PPF streams
|
---|
| 19 | (POutPersist , PInPersist) to be used with SOPHYA::SwSegDataBlock classes.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | template <class T>
|
---|
| 23 | class PPFDataSwapper : public DataSwapperInterface<T> {
|
---|
| 24 | public:
|
---|
[2695] | 25 | PPFDataSwapper() { ppfos = NULL; ppfis = NULL;}
|
---|
[2660] | 26 | PPFDataSwapper(POutPersist & os) { ppfos = &os; ppfis = NULL;}
|
---|
| 27 | PPFDataSwapper(PInPersist & is) { ppfos = NULL; ppfis = &is;}
|
---|
| 28 | PPFDataSwapper(PInPersist & is, POutPersist & os) { ppfos = &os; ppfis = &is;}
|
---|
[2698] | 29 |
|
---|
| 30 | inline PInPersist & InStream() { return *ppfis; }
|
---|
| 31 | inline PInPersist & OutStream() { return *ppfos; }
|
---|
| 32 | inline void SetInStream(PInPersist & is) { ppfis = &is; }
|
---|
| 33 | inline void SetOutStream(POutPersist & os) { ppfos = &os; }
|
---|
| 34 |
|
---|
| 35 | // Operateur = , on recopie les pointeurs des streams
|
---|
| 36 | inline PPFDataSwapper& operator = (PPFDataSwapper const & a)
|
---|
| 37 | { ppfis = a.ppfis; ppfos = a.ppfos; return *this; }
|
---|
| 38 |
|
---|
[2660] | 39 | virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false)
|
---|
| 40 | {
|
---|
| 41 | if (ppfos == NULL) throw NotAvailableOperation("PPFDataSwapper<T>::WriteToSwap() - No POutPersist stream !");
|
---|
| 42 | int_8 tag = ppfos->WritePositionTag();
|
---|
| 43 | PPF_TPointer_IO<T>::Write(*ppfos, d, sz);
|
---|
| 44 | return tag;
|
---|
| 45 | }
|
---|
| 46 | virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
|
---|
| 47 | {
|
---|
| 48 | if (ppfis == NULL) throw NotAvailableOperation("PPFDataSwapper<T>::ReadFromSwap() - No PInPersist stream !");
|
---|
| 49 | bool ok = ppfis->GotoPositionTag(swp);
|
---|
| 50 | PPF_TPointer_IO<T>::Read(*ppfis, d, sz);
|
---|
| 51 | return;
|
---|
| 52 | }
|
---|
| 53 | protected:
|
---|
| 54 | POutPersist* ppfos;
|
---|
| 55 | PInPersist* ppfis;
|
---|
| 56 | };
|
---|
| 57 |
|
---|
| 58 | } // Fin du namespace
|
---|
| 59 |
|
---|
| 60 | #endif
|
---|