~ubuntu-branches/ubuntu/trusty/advancecomp/trusty

« back to all changes in this revision

Viewing changes to 7z/WindowIn.h

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ozarowski
  • Date: 2006-05-13 21:15:49 UTC
  • Revision ID: james.westby@ubuntu.com-20060513211549-2vu7peis643ojcm5
Tags: upstream-1.15
ImportĀ upstreamĀ versionĀ 1.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __STREAM_WINDOWIN_H
 
2
#define __STREAM_WINDOWIN_H
 
3
 
 
4
#include "IInOutStreams.h"
 
5
 
 
6
#include <stdio.h>
 
7
 
 
8
namespace NStream {
 
9
namespace NWindow {
 
10
 
 
11
class CIn
 
12
{
 
13
  BYTE  *m_BufferBase; // pointer to buffer with data
 
14
  ISequentialInStream* m_Stream;
 
15
  INT m_PosLimit;  // offset (from m_Buffer) of first byte when new block reading must be done
 
16
  bool m_StreamEndWasReached; // if (true) then m_StreamPos shows real end of stream
 
17
 
 
18
  const BYTE *m_PointerToLastSafePosition;
 
19
 
 
20
protected:
 
21
  BYTE  *m_Buffer;   // Pointer to virtual Buffer begin
 
22
  INT m_BlockSize;  // Size of Allocated memory block
 
23
  INT m_Pos;             // offset (from m_Buffer) of curent byte
 
24
  INT m_KeepSizeBefore;  // how many BYTEs must be kept in buffer before m_Pos
 
25
  INT m_KeepSizeAfter;   // how many BYTEs must be kept buffer after m_Pos
 
26
  INT m_KeepSizeReserv;  // how many BYTEs must be kept as reserv
 
27
  INT m_StreamPos;   // offset (from m_Buffer) of first not read byte from Stream
 
28
 
 
29
  virtual void BeforeMoveBlock() {};
 
30
  virtual void AfterMoveBlock() {};
 
31
  void MoveBlock();
 
32
  virtual HRESULT ReadBlock();
 
33
  void Free();
 
34
public:
 
35
  CIn();
 
36
  void Create(INT aKeepSizeBefore, INT aKeepSizeAfter, 
 
37
      INT aKeepSizeReserv = (1<<17));
 
38
  virtual ~CIn();
 
39
 
 
40
  HRESULT Init(ISequentialInStream *aStream);
 
41
 
 
42
  BYTE *GetBuffer() const { return m_Buffer; }
 
43
 
 
44
  const BYTE *GetPointerToCurrentPos() const { return m_Buffer + m_Pos; }
 
45
 
 
46
  HRESULT MovePos()
 
47
  {
 
48
    m_Pos++;
 
49
    if (m_Pos > m_PosLimit)
 
50
    {
 
51
      const BYTE *aPointerToPostion = m_Buffer + m_Pos;
 
52
      if(aPointerToPostion > m_PointerToLastSafePosition)
 
53
        MoveBlock();
 
54
      return ReadBlock();
 
55
    }
 
56
    else
 
57
      return S_OK;
 
58
  }
 
59
  // BYTE GetCurrentByte()const;
 
60
  BYTE GetIndexByte(INT anIndex)const
 
61
    {  return m_Buffer[m_Pos + anIndex]; }
 
62
 
 
63
  // INT GetCurPos()const { return m_Pos;};
 
64
  // BYTE *GetBufferBeg()const { return m_Buffer;};
 
65
 
 
66
  // aIndex + aLimit have not to exceed m_KeepSizeAfter;
 
67
  INT GetMatchLen(INT aIndex, INT aBack, INT aLimit) const
 
68
  {  
 
69
    if(m_StreamEndWasReached)
 
70
      if ((m_Pos + aIndex) + aLimit > m_StreamPos)
 
71
        aLimit = m_StreamPos - (m_Pos + aIndex);
 
72
      aBack++;
 
73
      BYTE *pby = m_Buffer + m_Pos + aIndex;
 
74
      INT i;
 
75
      for(i = 0; i < aLimit && pby[i] == pby[i - aBack]; i++);
 
76
      return i;
 
77
  }
 
78
 
 
79
  INT GetNumAvailableBytes() const { return m_StreamPos - m_Pos; }
 
80
 
 
81
  void ReduceOffsets(INT aSubValue)
 
82
  {
 
83
    m_Buffer += aSubValue;
 
84
    m_PosLimit -= aSubValue;
 
85
    m_Pos -= aSubValue;
 
86
    m_StreamPos -= aSubValue;
 
87
  }
 
88
 
 
89
};
 
90
 
 
91
}}
 
92
 
 
93
#endif