LZOutWindow.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // LZOutWindow.h
  2. #ifndef __LZ_OUT_WINDOW_H
  3. #define __LZ_OUT_WINDOW_H
  4. #include "../../IStream.h"
  5. #include "../../Common/OutBuffer.h"
  6. #ifndef _NO_EXCEPTIONS
  7. typedef COutBufferException CLZOutWindowException;
  8. #endif
  9. class CLZOutWindow: public COutBuffer
  10. {
  11. public:
  12. void Init(bool solid = false);
  13. // distance >= 0, len > 0,
  14. bool CopyBlock(UInt32 distance, UInt32 len)
  15. {
  16. UInt32 pos = _pos - distance - 1;
  17. if (distance >= _pos)
  18. {
  19. if (!_overDict || distance >= _bufferSize)
  20. return false;
  21. pos += _bufferSize;
  22. }
  23. if (_limitPos - _pos > len && _bufferSize - pos > len)
  24. {
  25. const Byte *src = _buffer + pos;
  26. Byte *dest = _buffer + _pos;
  27. _pos += len;
  28. do
  29. *dest++ = *src++;
  30. while(--len != 0);
  31. }
  32. else do
  33. {
  34. if (pos == _bufferSize)
  35. pos = 0;
  36. _buffer[_pos++] = _buffer[pos++];
  37. if (_pos == _limitPos)
  38. FlushWithCheck();
  39. }
  40. while(--len != 0);
  41. return true;
  42. }
  43. void PutByte(Byte b)
  44. {
  45. _buffer[_pos++] = b;
  46. if (_pos == _limitPos)
  47. FlushWithCheck();
  48. }
  49. Byte GetByte(UInt32 distance) const
  50. {
  51. UInt32 pos = _pos - distance - 1;
  52. if (pos >= _bufferSize)
  53. pos += _bufferSize;
  54. return _buffer[pos];
  55. }
  56. };
  57. #endif