1// OutBuffer.h 2 3#ifndef ZIP7_INC_OUT_BUFFER_H 4#define ZIP7_INC_OUT_BUFFER_H 5 6#include "../IStream.h" 7#include "../../Common/MyCom.h" 8#include "../../Common/MyException.h" 9 10#ifndef Z7_NO_EXCEPTIONS 11struct COutBufferException: public CSystemException 12{ 13 COutBufferException(HRESULT errorCode): CSystemException(errorCode) {} 14}; 15#endif 16 17class COutBuffer 18{ 19protected: 20 Byte *_buf; 21 UInt32 _pos; 22 UInt32 _limitPos; 23 UInt32 _streamPos; 24 UInt32 _bufSize; 25 ISequentialOutStream *_stream; 26 UInt64 _processedSize; 27 Byte *_buf2; 28 bool _overDict; 29 30 HRESULT FlushPart() throw(); 31public: 32 #ifdef Z7_NO_EXCEPTIONS 33 HRESULT ErrorCode; 34 #endif 35 36 COutBuffer(): _buf(NULL), _pos(0), _stream(NULL), _buf2(NULL) {} 37 ~COutBuffer() { Free(); } 38 39 bool Create(UInt32 bufSize) throw(); 40 void Free() throw(); 41 42 void SetMemStream(Byte *buf) { _buf2 = buf; } 43 void SetStream(ISequentialOutStream *stream) { _stream = stream; } 44 void Init() throw(); 45 HRESULT Flush() throw(); 46 void FlushWithCheck(); 47 48 void WriteByte(Byte b) 49 { 50 UInt32 pos = _pos; 51 _buf[pos] = b; 52 pos++; 53 _pos = pos; 54 if (pos == _limitPos) 55 FlushWithCheck(); 56 } 57 void WriteBytes(const void *data, size_t size) 58 { 59 for (size_t i = 0; i < size; i++) 60 WriteByte(((const Byte *)data)[i]); 61 } 62 63 UInt64 GetProcessedSize() const throw(); 64}; 65 66#endif 67