Mercurial > vba-linux
annotate src/win32/7zip/7z/CPP/7zip/Common/OutBuffer.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
rev | line source |
---|---|
rlm@1 | 1 // OutBuffer.h |
rlm@1 | 2 |
rlm@1 | 3 #ifndef __OUTBUFFER_H |
rlm@1 | 4 #define __OUTBUFFER_H |
rlm@1 | 5 |
rlm@1 | 6 #include "../IStream.h" |
rlm@1 | 7 #include "../../Common/MyCom.h" |
rlm@1 | 8 #include "../../Common/MyException.h" |
rlm@1 | 9 |
rlm@1 | 10 #ifndef _NO_EXCEPTIONS |
rlm@1 | 11 struct COutBufferException: public CSystemException |
rlm@1 | 12 { |
rlm@1 | 13 COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} |
rlm@1 | 14 }; |
rlm@1 | 15 #endif |
rlm@1 | 16 |
rlm@1 | 17 class COutBuffer |
rlm@1 | 18 { |
rlm@1 | 19 protected: |
rlm@1 | 20 Byte *_buffer; |
rlm@1 | 21 UInt32 _pos; |
rlm@1 | 22 UInt32 _limitPos; |
rlm@1 | 23 UInt32 _streamPos; |
rlm@1 | 24 UInt32 _bufferSize; |
rlm@1 | 25 CMyComPtr<ISequentialOutStream> _stream; |
rlm@1 | 26 UInt64 _processedSize; |
rlm@1 | 27 Byte *_buffer2; |
rlm@1 | 28 bool _overDict; |
rlm@1 | 29 |
rlm@1 | 30 HRESULT FlushPart(); |
rlm@1 | 31 public: |
rlm@1 | 32 #ifdef _NO_EXCEPTIONS |
rlm@1 | 33 HRESULT ErrorCode; |
rlm@1 | 34 #endif |
rlm@1 | 35 |
rlm@1 | 36 COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {} |
rlm@1 | 37 ~COutBuffer() { Free(); } |
rlm@1 | 38 |
rlm@1 | 39 bool Create(UInt32 bufferSize); |
rlm@1 | 40 void Free(); |
rlm@1 | 41 |
rlm@1 | 42 void SetMemStream(Byte *buffer) { _buffer2 = buffer; } |
rlm@1 | 43 void SetStream(ISequentialOutStream *stream); |
rlm@1 | 44 void Init(); |
rlm@1 | 45 HRESULT Flush(); |
rlm@1 | 46 void FlushWithCheck(); |
rlm@1 | 47 void ReleaseStream() { _stream.Release(); } |
rlm@1 | 48 |
rlm@1 | 49 void WriteByte(Byte b) |
rlm@1 | 50 { |
rlm@1 | 51 _buffer[_pos++] = b; |
rlm@1 | 52 if(_pos == _limitPos) |
rlm@1 | 53 FlushWithCheck(); |
rlm@1 | 54 } |
rlm@1 | 55 void WriteBytes(const void *data, size_t size) |
rlm@1 | 56 { |
rlm@1 | 57 for (size_t i = 0; i < size; i++) |
rlm@1 | 58 WriteByte(((const Byte *)data)[i]); |
rlm@1 | 59 } |
rlm@1 | 60 |
rlm@1 | 61 UInt64 GetProcessedSize() const; |
rlm@1 | 62 }; |
rlm@1 | 63 |
rlm@1 | 64 #endif |