michael@0: // OutBuffer.h michael@0: michael@0: #ifndef __OUTBUFFER_H michael@0: #define __OUTBUFFER_H michael@0: michael@0: #include "../IStream.h" michael@0: #include "../../Common/MyCom.h" michael@0: michael@0: #ifndef _NO_EXCEPTIONS michael@0: struct COutBufferException michael@0: { michael@0: HRESULT ErrorCode; michael@0: COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {} michael@0: }; michael@0: #endif michael@0: michael@0: class COutBuffer michael@0: { michael@0: protected: michael@0: Byte *_buffer; michael@0: UInt32 _pos; michael@0: UInt32 _limitPos; michael@0: UInt32 _streamPos; michael@0: UInt32 _bufferSize; michael@0: CMyComPtr _stream; michael@0: UInt64 _processedSize; michael@0: Byte *_buffer2; michael@0: bool _overDict; michael@0: michael@0: HRESULT FlushPart(); michael@0: void FlushWithCheck(); michael@0: public: michael@0: #ifdef _NO_EXCEPTIONS michael@0: HRESULT ErrorCode; michael@0: #endif michael@0: michael@0: COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {} michael@0: ~COutBuffer() { Free(); } michael@0: michael@0: bool Create(UInt32 bufferSize); michael@0: void Free(); michael@0: michael@0: void SetMemStream(Byte *buffer) { _buffer2 = buffer; } michael@0: void SetStream(ISequentialOutStream *stream); michael@0: void Init(); michael@0: HRESULT Flush(); michael@0: void ReleaseStream() { _stream.Release(); } michael@0: michael@0: void WriteByte(Byte b) michael@0: { michael@0: _buffer[_pos++] = b; michael@0: if(_pos == _limitPos) michael@0: FlushWithCheck(); michael@0: } michael@0: void WriteBytes(const void *data, size_t size) michael@0: { michael@0: for (size_t i = 0; i < size; i++) michael@0: WriteByte(((const Byte *)data)[i]); michael@0: } michael@0: michael@0: UInt64 GetProcessedSize() const; michael@0: }; michael@0: michael@0: #endif