1 // CWrappers.h
2 
3 #ifndef __C_WRAPPERS_H
4 #define __C_WRAPPERS_H
5 
6 #include "../ICoder.h"
7 #include "../../Common/MyCom.h"
8 
9 struct CCompressProgressWrap
10 {
11   ICompressProgress p;
12   ICompressProgressInfo *Progress;
13   HRESULT Res;
14   CCompressProgressWrap(ICompressProgressInfo *progress);
15 };
16 
17 struct CSeqInStreamWrap
18 {
19   ISeqInStream p;
20   ISequentialInStream *Stream;
21   HRESULT Res;
22   CSeqInStreamWrap(ISequentialInStream *stream);
23 };
24 
25 struct CSeekInStreamWrap
26 {
27   ISeekInStream p;
28   IInStream *Stream;
29   HRESULT Res;
30   CSeekInStreamWrap(IInStream *stream);
31 };
32 
33 struct CSeqOutStreamWrap
34 {
35   ISeqOutStream p;
36   ISequentialOutStream *Stream;
37   HRESULT Res;
38   UInt64 Processed;
39   CSeqOutStreamWrap(ISequentialOutStream *stream);
40 };
41 
42 HRESULT SResToHRESULT(SRes res);
43 
44 struct CByteInBufWrap
45 {
46   IByteIn p;
47   const Byte *Cur;
48   const Byte *Lim;
49   Byte *Buf;
50   UInt32 Size;
51   ISequentialInStream *Stream;
52   UInt64 Processed;
53   bool Extra;
54   HRESULT Res;
55 
56   CByteInBufWrap();
~CByteInBufWrapCByteInBufWrap57   ~CByteInBufWrap() { Free();  }
58   void Free();
59   bool Alloc(UInt32 size);
InitCByteInBufWrap60   void Init()
61   {
62     Lim = Cur = Buf;
63     Processed = 0;
64     Extra = false;
65     Res = S_OK;
66   }
GetProcessedCByteInBufWrap67   UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
68   Byte ReadByteFromNewBlock();
ReadByteCByteInBufWrap69   Byte ReadByte()
70   {
71     if (Cur != Lim)
72       return *Cur++;
73     return ReadByteFromNewBlock();
74   }
75 };
76 
77 struct CByteOutBufWrap
78 {
79   IByteOut p;
80   Byte *Cur;
81   const Byte *Lim;
82   Byte *Buf;
83   size_t Size;
84   ISequentialOutStream *Stream;
85   UInt64 Processed;
86   HRESULT Res;
87 
88   CByteOutBufWrap();
~CByteOutBufWrapCByteOutBufWrap89   ~CByteOutBufWrap() { Free();  }
90   void Free();
91   bool Alloc(size_t size);
InitCByteOutBufWrap92   void Init()
93   {
94     Cur = Buf;
95     Lim = Buf + Size;
96     Processed = 0;
97     Res = S_OK;
98   }
GetProcessedCByteOutBufWrap99   UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
100   HRESULT Flush();
WriteByteCByteOutBufWrap101   void WriteByte(Byte b)
102   {
103     *Cur++ = b;
104     if (Cur == Lim)
105       Flush();
106   }
107 };
108 
109 #endif
110