3 #ifndef __LZ_IN_WINDOW_H
\r
4 #define __LZ_IN_WINDOW_H
\r
6 #include "../../IStream.h"
\r
10 Byte *_bufferBase; // pointer to buffer with data
\r
11 ISequentialInStream *_stream;
\r
12 UInt32 _posLimit; // offset (from _buffer) when new block reading must be done
\r
13 bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
\r
14 const Byte *_pointerToLastSafePosition;
\r
16 Byte *_buffer; // Pointer to virtual Buffer begin
\r
17 UInt32 _blockSize; // Size of Allocated memory block
\r
18 UInt32 _pos; // offset (from _buffer) of curent byte
\r
19 UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
\r
20 UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
\r
21 UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
\r
24 HRESULT ReadBlock();
\r
27 CLZInWindow(): _bufferBase(0) {}
\r
28 virtual ~CLZInWindow() { Free(); }
\r
30 // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
\r
31 bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
\r
33 void SetStream(ISequentialInStream *stream);
\r
35 // void ReleaseStream();
\r
37 Byte *GetBuffer() const { return _buffer; }
\r
39 const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
\r
44 if (_pos > _posLimit)
\r
46 const Byte *pointerToPostion = _buffer + _pos;
\r
47 if(pointerToPostion > _pointerToLastSafePosition)
\r
54 Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; }
\r
56 // index + limit have not to exceed _keepSizeAfter;
\r
57 // -2G <= index < 2G
\r
58 UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
\r
60 if(_streamEndWasReached)
\r
61 if ((_pos + index) + limit > _streamPos)
\r
62 limit = _streamPos - (_pos + index);
\r
64 const Byte *pby = _buffer + (size_t)_pos + index;
\r
66 for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
\r
70 UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
\r
72 void ReduceOffsets(Int32 subValue)
\r
74 _buffer += subValue;
\r
75 _posLimit -= subValue;
\r
77 _streamPos -= subValue;
\r
80 bool NeedMove(UInt32 numCheckBytes)
\r
82 UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);
\r
83 return (reserv <= numCheckBytes);
\r