Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / other-licenses / 7zstub / src / 7zip / Common / MSBFDecoder.h
blobdad00ecab62c6b0d71b382d03813e6b526fa9a67
1 // MSBFDecoder.h
2 // the Most Significant Bit of byte is First
4 #ifndef __STREAM_MSBFDECODER_H
5 #define __STREAM_MSBFDECODER_H
7 #include "../../Common/Types.h"
8 #include "../IStream.h"
10 namespace NStream {
11 namespace NMSBF {
13 const int kNumBigValueBits = 8 * 4;
14 const int kNumValueBytes = 3;
15 const int kNumValueBits = 8 * kNumValueBytes;
17 const UInt32 kMask = (1 << kNumValueBits) - 1;
19 template<class TInByte>
20 class CDecoder
22 UInt32 m_BitPos;
23 UInt32 m_Value;
24 public:
25 TInByte m_Stream;
26 bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
27 void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
28 void ReleaseStream() { m_Stream.ReleaseStream();}
30 void Init()
32 m_Stream.Init();
33 m_BitPos = kNumBigValueBits;
34 Normalize();
37 UInt64 GetProcessedSize() const
38 { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
39 UInt32 GetBitPosition() const { return (m_BitPos & 7); }
41 void Normalize()
43 for (;m_BitPos >= 8; m_BitPos -= 8)
44 m_Value = (m_Value << 8) | m_Stream.ReadByte();
47 UInt32 GetValue(UInt32 numBits) const
49 // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
50 return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
53 void MovePos(UInt32 numBits)
55 m_BitPos += numBits;
56 Normalize();
59 UInt32 ReadBits(UInt32 numBits)
61 UInt32 res = GetValue(numBits);
62 MovePos(numBits);
63 return res;
69 #endif