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) of first byte 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 _keepSizeReserv
; // how many BYTEs must be kept as reserv
22 UInt32 _streamPos
; // offset (from _buffer) of first not read byte from Stream
24 virtual void BeforeMoveBlock() {};
25 virtual void AfterMoveBlock() {};
27 virtual HRESULT
ReadBlock();
30 CLZInWindow(): _bufferBase(0) {}
31 virtual ~CLZInWindow() { Free(); }
33 bool Create(UInt32 keepSizeBefore
, UInt32 keepSizeAfter
,
34 UInt32 keepSizeReserv
= (1<<17));
36 HRESULT
Init(ISequentialInStream
*stream
);
37 // void ReleaseStream();
39 Byte
*GetBuffer() const { return _buffer
; }
41 const Byte
*GetPointerToCurrentPos() const { return _buffer
+ _pos
; }
48 const Byte
*pointerToPostion
= _buffer
+ _pos
;
49 if(pointerToPostion
> _pointerToLastSafePosition
)
56 Byte
GetIndexByte(Int32 index
)const
57 { return _buffer
[(size_t)_pos
+ index
]; }
59 // index + limit have not to exceed _keepSizeAfter;
60 UInt32
GetMatchLen(Int32 index
, UInt32 distance
, UInt32 limit
) const
62 if(_streamEndWasReached
)
63 if ((_pos
+ index
) + limit
> _streamPos
)
64 limit
= _streamPos
- (_pos
+ index
);
66 Byte
*pby
= _buffer
+ (size_t)_pos
+ index
;
68 for(i
= 0; i
< limit
&& pby
[i
] == pby
[(size_t)i
- distance
]; i
++);
72 UInt32
GetNumAvailableBytes() const { return _streamPos
- _pos
; }
74 void ReduceOffsets(Int32 subValue
)
77 _posLimit
-= subValue
;
79 _streamPos
-= subValue
;