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
9struct CCompressProgressWrap
10{
11  ICompressProgress p;
12  ICompressProgressInfo *Progress;
13  HRESULT Res;
14  CCompressProgressWrap(ICompressProgressInfo *progress);
15};
16
17struct CSeqInStreamWrap
18{
19  ISeqInStream p;
20  ISequentialInStream *Stream;
21  HRESULT Res;
22  CSeqInStreamWrap(ISequentialInStream *stream);
23};
24
25struct CSeekInStreamWrap
26{
27  ISeekInStream p;
28  IInStream *Stream;
29  HRESULT Res;
30  CSeekInStreamWrap(IInStream *stream);
31};
32
33struct CSeqOutStreamWrap
34{
35  ISeqOutStream p;
36  ISequentialOutStream *Stream;
37  HRESULT Res;
38  UInt64 Processed;
39  CSeqOutStreamWrap(ISequentialOutStream *stream);
40};
41
42HRESULT SResToHRESULT(SRes res);
43
44struct 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();
57  ~CByteInBufWrap() { Free();  }
58  void Free();
59  bool Alloc(UInt32 size);
60  void Init()
61  {
62    Lim = Cur = Buf;
63    Processed = 0;
64    Extra = false;
65    Res = S_OK;
66  }
67  UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
68  Byte ReadByteFromNewBlock();
69  Byte ReadByte()
70  {
71    if (Cur != Lim)
72      return *Cur++;
73    return ReadByteFromNewBlock();
74  }
75};
76
77struct 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();
89  ~CByteOutBufWrap() { Free();  }
90  void Free();
91  bool Alloc(size_t size);
92  void Init()
93  {
94    Cur = Buf;
95    Lim = Buf + Size;
96    Processed = 0;
97    Res = S_OK;
98  }
99  UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
100  HRESULT Flush();
101  void WriteByte(Byte b)
102  {
103    *Cur++ = b;
104    if (Cur == Lim)
105      Flush();
106  }
107};
108
109#endif
110