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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // InBuffer.h
michael@0 2
michael@0 3 #ifndef __INBUFFER_H
michael@0 4 #define __INBUFFER_H
michael@0 5
michael@0 6 #include "../IStream.h"
michael@0 7 #include "../../Common/MyCom.h"
michael@0 8
michael@0 9 #ifndef _NO_EXCEPTIONS
michael@0 10 class CInBufferException
michael@0 11 {
michael@0 12 public:
michael@0 13 HRESULT ErrorCode;
michael@0 14 CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
michael@0 15 };
michael@0 16 #endif
michael@0 17
michael@0 18 class CInBuffer
michael@0 19 {
michael@0 20 Byte *_buffer;
michael@0 21 Byte *_bufferLimit;
michael@0 22 Byte *_bufferBase;
michael@0 23 CMyComPtr<ISequentialInStream> _stream;
michael@0 24 UInt64 _processedSize;
michael@0 25 UInt32 _bufferSize;
michael@0 26 bool _wasFinished;
michael@0 27
michael@0 28 bool ReadBlock();
michael@0 29 Byte ReadBlock2();
michael@0 30
michael@0 31 public:
michael@0 32 #ifdef _NO_EXCEPTIONS
michael@0 33 HRESULT ErrorCode;
michael@0 34 #endif
michael@0 35
michael@0 36 CInBuffer();
michael@0 37 ~CInBuffer() { Free(); }
michael@0 38
michael@0 39 bool Create(UInt32 bufferSize);
michael@0 40 void Free();
michael@0 41
michael@0 42 void SetStream(ISequentialInStream *stream);
michael@0 43 void Init();
michael@0 44 void ReleaseStream() { _stream.Release(); }
michael@0 45
michael@0 46 bool ReadByte(Byte &b)
michael@0 47 {
michael@0 48 if(_buffer >= _bufferLimit)
michael@0 49 if(!ReadBlock())
michael@0 50 return false;
michael@0 51 b = *_buffer++;
michael@0 52 return true;
michael@0 53 }
michael@0 54 Byte ReadByte()
michael@0 55 {
michael@0 56 if(_buffer >= _bufferLimit)
michael@0 57 return ReadBlock2();
michael@0 58 return *_buffer++;
michael@0 59 }
michael@0 60 void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
michael@0 61 {
michael@0 62 for(processedSize = 0; processedSize < size; processedSize++)
michael@0 63 if (!ReadByte(((Byte *)data)[processedSize]))
michael@0 64 return;
michael@0 65 }
michael@0 66 bool ReadBytes(void *data, UInt32 size)
michael@0 67 {
michael@0 68 UInt32 processedSize;
michael@0 69 ReadBytes(data, size, processedSize);
michael@0 70 return (processedSize == size);
michael@0 71 }
michael@0 72 UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
michael@0 73 bool WasFinished() const { return _wasFinished; }
michael@0 74 };
michael@0 75
michael@0 76 #endif

mercurial