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