Debian Codegraph @

utils/lzma/SRC/7zip/Common/OutBuffer.h

raw
1 // OutBuffer.h
2
3 #ifndef __OUTBUFFER_H
4 #define __OUTBUFFER_H
5
6 #include "../IStream.h"
7 #include "../../Common/MyCom.h"
8
9 #ifndef _NO_EXCEPTIONS
10 struct COutBufferException
11 {
12 HRESULT ErrorCode;
13 COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
14 };
15 #endif
16
17 class COutBuffer
18 {
19 Byte *_buffer;
20 UInt32 _pos;
21 UInt32 _bufferSize;
22 CMyComPtr<ISequentialOutStream> _stream;
23 UInt64 _processedSize;
24
25 void WriteBlock();
26 public:
27 #ifdef _NO_EXCEPTIONS
28 HRESULT ErrorCode;
29 #endif
30
31 COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
32 ~COutBuffer() { Free(); }
33
34 bool Create(UInt32 bufferSize);
35 void Free();
36
37 void SetStream(ISequentialOutStream *stream);
38 void Init();
39 HRESULT Flush();
40 void ReleaseStream() { _stream.Release(); }
41
42 /*
43 void *GetBuffer(UInt32 &sizeAvail)
44 {
45 sizeAvail = _bufferSize - _pos;
46 return _buffer + _pos;
47 }
48 void MovePos(UInt32 num)
49 {
50 _pos += num;
51 if(_pos >= _bufferSize)
52 WriteBlock();
53 }
54 */
55
56 void WriteByte(Byte b)
57 {
58 _buffer[_pos++] = b;
59 if(_pos >= _bufferSize)
60 WriteBlock();
61 }
62 void WriteBytes(const void *data, size_t size)
63 {
64 for (size_t i = 0; i < size; i++)
65 WriteByte(((const Byte *)data)[i]);
66 }
67
68 UInt64 GetProcessedSize() const { return _processedSize + _pos; }
69 };
70
71 #endif