RT-AC66 3.0.0.4.374.130 core
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / C / 7zip / Common / OutBuffer.h
blob37eefbdfcd5bb6668c1f9a111d492f5d52a9cc2d
1 // OutBuffer.h
3 #ifndef __OUTBUFFER_H
4 #define __OUTBUFFER_H
6 #include "../IStream.h"
7 #include "../../Common/MyCom.h"
9 #ifndef _NO_EXCEPTIONS
10 struct COutBufferException
12 HRESULT ErrorCode;
13 COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
15 #endif
17 class COutBuffer
19 protected:
20 Byte *_buffer;
21 UInt32 _pos;
22 UInt32 _limitPos;
23 UInt32 _streamPos;
24 UInt32 _bufferSize;
25 CMyComPtr<ISequentialOutStream> _stream;
26 UInt64 _processedSize;
27 Byte *_buffer2;
28 bool _overDict;
30 HRESULT FlushPart();
31 void FlushWithCheck();
32 public:
33 #ifdef _NO_EXCEPTIONS
34 HRESULT ErrorCode;
35 #endif
37 COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
38 ~COutBuffer() { Free(); }
40 bool Create(UInt32 bufferSize);
41 void Free();
43 void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
44 void SetStream(ISequentialOutStream *stream);
45 void Init();
46 HRESULT Flush();
47 void ReleaseStream() { _stream.Release(); }
49 void WriteByte(Byte b)
51 _buffer[_pos++] = b;
52 if(_pos == _limitPos)
53 FlushWithCheck();
55 void WriteBytes(const void *data, size_t size)
57 for (size_t i = 0; i < size; i++)
58 WriteByte(((const Byte *)data)[i]);
61 UInt64 GetProcessedSize() const;
64 #endif