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