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