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 
15   CCompressProgressWrap(ICompressProgressInfo *progress) throw();
16 };
17 
18 struct CSeqInStreamWrap
19 {
20   ISeqInStream p;
21   ISequentialInStream *Stream;
22   HRESULT Res;
23   UInt64 Processed;
24 
25   CSeqInStreamWrap(ISequentialInStream *stream) throw();
26 };
27 
28 struct CSeekInStreamWrap
29 {
30   ISeekInStream p;
31   IInStream *Stream;
32   HRESULT Res;
33 
34   CSeekInStreamWrap(IInStream *stream) throw();
35 };
36 
37 struct CSeqOutStreamWrap
38 {
39   ISeqOutStream p;
40   ISequentialOutStream *Stream;
41   HRESULT Res;
42   UInt64 Processed;
43 
44   CSeqOutStreamWrap(ISequentialOutStream *stream) throw();
45 };
46 
47 HRESULT SResToHRESULT(SRes res) throw();
48 
49 struct CByteInBufWrap
50 {
51   IByteIn p;
52   const Byte *Cur;
53   const Byte *Lim;
54   Byte *Buf;
55   UInt32 Size;
56   ISequentialInStream *Stream;
57   UInt64 Processed;
58   bool Extra;
59   HRESULT Res;
60 
61   CByteInBufWrap();
~CByteInBufWrapCByteInBufWrap62   ~CByteInBufWrap() { Free(); }
63   void Free() throw();
64   bool Alloc(UInt32 size) throw();
InitCByteInBufWrap65   void Init()
66   {
67     Lim = Cur = Buf;
68     Processed = 0;
69     Extra = false;
70     Res = S_OK;
71   }
GetProcessedCByteInBufWrap72   UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
73   Byte ReadByteFromNewBlock() throw();
ReadByteCByteInBufWrap74   Byte ReadByte()
75   {
76     if (Cur != Lim)
77       return *Cur++;
78     return ReadByteFromNewBlock();
79   }
80 };
81 
82 struct CByteOutBufWrap
83 {
84   IByteOut p;
85   Byte *Cur;
86   const Byte *Lim;
87   Byte *Buf;
88   size_t Size;
89   ISequentialOutStream *Stream;
90   UInt64 Processed;
91   HRESULT Res;
92 
93   CByteOutBufWrap() throw();
~CByteOutBufWrapCByteOutBufWrap94   ~CByteOutBufWrap() { Free(); }
95   void Free() throw();
96   bool Alloc(size_t size) throw();
InitCByteOutBufWrap97   void Init()
98   {
99     Cur = Buf;
100     Lim = Buf + Size;
101     Processed = 0;
102     Res = S_OK;
103   }
GetProcessedCByteOutBufWrap104   UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
105   HRESULT Flush() throw();
WriteByteCByteOutBufWrap106   void WriteByte(Byte b)
107   {
108     *Cur++ = b;
109     if (Cur == Lim)
110       Flush();
111   }
112 };
113 
114 #endif
115