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 SRes HRESULT_To_SRes(HRESULT res, SRes defaultRes) throw(); 10 HRESULT SResToHRESULT(SRes res) throw(); 11 12 struct CCompressProgressWrap 13 { 14 ICompressProgress vt; 15 ICompressProgressInfo *Progress; 16 HRESULT Res; 17 18 void Init(ICompressProgressInfo *progress) throw(); 19 }; 20 21 22 struct CSeqInStreamWrap 23 { 24 ISeqInStream vt; 25 ISequentialInStream *Stream; 26 HRESULT Res; 27 UInt64 Processed; 28 29 void Init(ISequentialInStream *stream) throw(); 30 }; 31 32 33 struct CSeekInStreamWrap 34 { 35 ISeekInStream vt; 36 IInStream *Stream; 37 HRESULT Res; 38 39 void Init(IInStream *stream) throw(); 40 }; 41 42 43 struct CSeqOutStreamWrap 44 { 45 ISeqOutStream vt; 46 ISequentialOutStream *Stream; 47 HRESULT Res; 48 UInt64 Processed; 49 50 void Init(ISequentialOutStream *stream) throw(); 51 }; 52 53 54 struct CByteInBufWrap 55 { 56 IByteIn vt; 57 const Byte *Cur; 58 const Byte *Lim; 59 Byte *Buf; 60 UInt32 Size; 61 ISequentialInStream *Stream; 62 UInt64 Processed; 63 bool Extra; 64 HRESULT Res; 65 66 CByteInBufWrap(); ~CByteInBufWrapCByteInBufWrap67 ~CByteInBufWrap() { Free(); } 68 void Free() throw(); 69 bool Alloc(UInt32 size) throw(); InitCByteInBufWrap70 void Init() 71 { 72 Lim = Cur = Buf; 73 Processed = 0; 74 Extra = false; 75 Res = S_OK; 76 } GetProcessedCByteInBufWrap77 UInt64 GetProcessed() const { return Processed + (Cur - Buf); } 78 Byte ReadByteFromNewBlock() throw(); ReadByteCByteInBufWrap79 Byte ReadByte() 80 { 81 if (Cur != Lim) 82 return *Cur++; 83 return ReadByteFromNewBlock(); 84 } 85 }; 86 87 88 struct CByteOutBufWrap 89 { 90 IByteOut vt; 91 Byte *Cur; 92 const Byte *Lim; 93 Byte *Buf; 94 size_t Size; 95 ISequentialOutStream *Stream; 96 UInt64 Processed; 97 HRESULT Res; 98 99 CByteOutBufWrap() throw(); ~CByteOutBufWrapCByteOutBufWrap100 ~CByteOutBufWrap() { Free(); } 101 void Free() throw(); 102 bool Alloc(size_t size) throw(); InitCByteOutBufWrap103 void Init() 104 { 105 Cur = Buf; 106 Lim = Buf + Size; 107 Processed = 0; 108 Res = S_OK; 109 } GetProcessedCByteOutBufWrap110 UInt64 GetProcessed() const { return Processed + (Cur - Buf); } 111 HRESULT Flush() throw(); WriteByteCByteOutBufWrap112 void WriteByte(Byte b) 113 { 114 *Cur++ = b; 115 if (Cur == Lim) 116 Flush(); 117 } 118 }; 119 120 #endif 121