other-licenses/7zstub/src/7zip/Common/LSBFEncoder.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 // Stream/LSBFEncoder.h
     3 #ifndef __STREAM_LSBFENCODER_H
     4 #define __STREAM_LSBFENCODER_H
     6 #include "../IStream.h"
     7 #include "OutBuffer.h"
     9 namespace NStream {
    10 namespace NLSBF {
    12 class CEncoder
    13 {
    14   COutBuffer m_Stream;
    15   int m_BitPos;
    16   Byte m_CurByte;
    17 public:
    18   bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
    19   void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
    20   void ReleaseStream() { m_Stream.ReleaseStream(); }
    21   void Init()
    22   {
    23     m_Stream.Init();
    24     m_BitPos = 8; 
    25     m_CurByte = 0;
    26   }
    27   HRESULT Flush()
    28   {
    29     FlushByte();
    30     return m_Stream.Flush();
    31   }
    33   void FlushByte()
    34   {
    35     if(m_BitPos < 8)
    36       m_Stream.WriteByte(m_CurByte);
    37     m_BitPos = 8; 
    38     m_CurByte = 0;
    39   }
    41   void WriteBits(UInt32 value, int numBits);
    42   UInt32 GetBitPosition() const {  return (8 - m_BitPos); }
    43   UInt64 GetProcessedSize() const { 
    44       return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
    45   void WriteByte(Byte b) { m_Stream.WriteByte(b);}
    46 };
    49 }}
    51 #endif

mercurial