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