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.
|
---|
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.
|
---|
22 | */
|
---|
23 |
|
---|
24 | namespace SOPHYA {
|
---|
25 |
|
---|
26 | template <class T>
|
---|
27 | class PPFDataSwapper : public DataSwapperInterface<T> {
|
---|
28 | public:
|
---|
29 | PPFDataSwapper() { ppfos = NULL; ppfis = NULL;}
|
---|
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;}
|
---|
33 |
|
---|
34 | inline PInPersist & InStream() { return *ppfis; }
|
---|
35 | inline POutPersist & OutStream() { return *ppfos; }
|
---|
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
|
---|
40 | inline PPFDataSwapper<T>& operator = (PPFDataSwapper<T> const & a)
|
---|
41 | { ppfis = a.ppfis; ppfos = a.ppfos; return *this; }
|
---|
42 |
|
---|
43 | virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false)
|
---|
44 | {
|
---|
45 | if (ppfos == NULL) throw NotAvailableOperation("PPFDataSwapper<T>::WriteToSwap() - No POutPersist stream !");
|
---|
46 | int_8 tag = ppfos->WritePositionTag();
|
---|
47 | PPF_TPointer_IO<T>::Write(*ppfos, d, sz);
|
---|
48 | return tag;
|
---|
49 | }
|
---|
50 | virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
|
---|
51 | {
|
---|
52 | if (ppfis == NULL) throw NotAvailableOperation("PPFDataSwapper<T>::ReadFromSwap() - No PInPersist stream !");
|
---|
53 | bool ok = ppfis->GotoPositionTag(swp);
|
---|
54 | PPF_TPointer_IO<T>::Read(*ppfis, d, sz);
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | protected:
|
---|
58 | POutPersist* ppfos;
|
---|
59 | PInPersist* ppfis;
|
---|
60 | };
|
---|
61 |
|
---|
62 | } // Fin du namespace
|
---|
63 |
|
---|
64 | #endif
|
---|