source: Sophya/trunk/SophyaLib/BaseTools/ppfswapper.h@ 4059

Last change on this file since 4059 was 2863, checked in by ansari, 20 years ago

Correction bug latent ds SwSegDataBlock<T> (operateur = et constructeur de copie) par ajout / appel methode Clone() dans DataSwapperInterface<T> - Reza 2 Jan 2006

File size: 2.3 KB
Line 
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
24namespace SOPHYA {
25
26template <class T>
27class PPFDataSwapper : public DataSwapperInterface<T> {
28public:
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)
46 throw NotAvailableOperation("PPFDataSwapper<T>::WriteToSwap() - No POutPersist stream !");
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 {
53 if (ppfis == NULL)
54 throw NotAvailableOperation("PPFDataSwapper<T>::ReadFromSwap() - No PInPersist stream !");
55 bool ok = ppfis->GotoPositionTag(swp);
56 PPF_TPointer_IO<T>::Read(*ppfis, d, sz);
57 return;
58 }
59 virtual DataSwapperInterface<T>* Clone()
60 {
61 PPFDataSwapper<T> * rsw = new PPFDataSwapper<T> ;
62 (*rsw) = *this;
63 return rsw;
64 }
65protected:
66 POutPersist* ppfos;
67 PInPersist* ppfis;
68};
69
70} // Fin du namespace
71
72#endif
Note: See TracBrowser for help on using the repository browser.