misc/libphysfs/lzma/CPP/7zip/Compress/LZ/LZOutWindow.h
branchui-scaling
changeset 15283 c4fd2813b127
parent 13390 0135e64c6c66
parent 15279 7ab5cf405686
child 15663 d92eeb468dad
equal deleted inserted replaced
13390:0135e64c6c66 15283:c4fd2813b127
     1 // LZOutWindow.h
       
     2 
       
     3 #ifndef __LZ_OUT_WINDOW_H
       
     4 #define __LZ_OUT_WINDOW_H
       
     5 
       
     6 #include "../../IStream.h"
       
     7 #include "../../Common/OutBuffer.h"
       
     8 
       
     9 #ifndef _NO_EXCEPTIONS
       
    10 typedef COutBufferException CLZOutWindowException;
       
    11 #endif
       
    12 
       
    13 class CLZOutWindow: public COutBuffer
       
    14 {
       
    15 public:
       
    16   void Init(bool solid = false);
       
    17   
       
    18   // distance >= 0, len > 0, 
       
    19   bool CopyBlock(UInt32 distance, UInt32 len)
       
    20   {
       
    21     UInt32 pos = _pos - distance - 1;
       
    22     if (distance >= _pos)
       
    23     {
       
    24       if (!_overDict || distance >= _bufferSize)
       
    25         return false;
       
    26       pos += _bufferSize;
       
    27     }
       
    28     if (_limitPos - _pos > len && _bufferSize - pos > len)
       
    29     {
       
    30       const Byte *src = _buffer + pos;
       
    31       Byte *dest = _buffer + _pos;
       
    32       _pos += len;
       
    33       do
       
    34         *dest++ = *src++;
       
    35       while(--len != 0);
       
    36     }
       
    37     else do
       
    38     {
       
    39       if (pos == _bufferSize)
       
    40         pos = 0;
       
    41       _buffer[_pos++] = _buffer[pos++];
       
    42       if (_pos == _limitPos)
       
    43         FlushWithCheck();  
       
    44     }
       
    45     while(--len != 0);
       
    46     return true;
       
    47   }
       
    48   
       
    49   void PutByte(Byte b)
       
    50   {
       
    51     _buffer[_pos++] = b;
       
    52     if (_pos == _limitPos)
       
    53       FlushWithCheck();  
       
    54   }
       
    55   
       
    56   Byte GetByte(UInt32 distance) const
       
    57   {
       
    58     UInt32 pos = _pos - distance - 1;
       
    59     if (pos >= _bufferSize)
       
    60       pos += _bufferSize;
       
    61     return _buffer[pos]; 
       
    62   }
       
    63 };
       
    64 
       
    65 #endif