1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/7zip/Common/InBuffer.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +// InBuffer.h 1.5 + 1.6 +#ifndef __INBUFFER_H 1.7 +#define __INBUFFER_H 1.8 + 1.9 +#include "../IStream.h" 1.10 +#include "../../Common/MyCom.h" 1.11 + 1.12 +#ifndef _NO_EXCEPTIONS 1.13 +class CInBufferException 1.14 +{ 1.15 +public: 1.16 + HRESULT ErrorCode; 1.17 + CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {} 1.18 +}; 1.19 +#endif 1.20 + 1.21 +class CInBuffer 1.22 +{ 1.23 + Byte *_buffer; 1.24 + Byte *_bufferLimit; 1.25 + Byte *_bufferBase; 1.26 + CMyComPtr<ISequentialInStream> _stream; 1.27 + UInt64 _processedSize; 1.28 + UInt32 _bufferSize; 1.29 + bool _wasFinished; 1.30 + 1.31 + bool ReadBlock(); 1.32 + Byte ReadBlock2(); 1.33 + 1.34 +public: 1.35 + #ifdef _NO_EXCEPTIONS 1.36 + HRESULT ErrorCode; 1.37 + #endif 1.38 + 1.39 + CInBuffer(); 1.40 + ~CInBuffer() { Free(); } 1.41 + 1.42 + bool Create(UInt32 bufferSize); 1.43 + void Free(); 1.44 + 1.45 + void SetStream(ISequentialInStream *stream); 1.46 + void Init(); 1.47 + void ReleaseStream() { _stream.Release(); } 1.48 + 1.49 + bool ReadByte(Byte &b) 1.50 + { 1.51 + if(_buffer >= _bufferLimit) 1.52 + if(!ReadBlock()) 1.53 + return false; 1.54 + b = *_buffer++; 1.55 + return true; 1.56 + } 1.57 + Byte ReadByte() 1.58 + { 1.59 + if(_buffer >= _bufferLimit) 1.60 + return ReadBlock2(); 1.61 + return *_buffer++; 1.62 + } 1.63 + void ReadBytes(void *data, UInt32 size, UInt32 &processedSize) 1.64 + { 1.65 + for(processedSize = 0; processedSize < size; processedSize++) 1.66 + if (!ReadByte(((Byte *)data)[processedSize])) 1.67 + return; 1.68 + } 1.69 + bool ReadBytes(void *data, UInt32 size) 1.70 + { 1.71 + UInt32 processedSize; 1.72 + ReadBytes(data, size, processedSize); 1.73 + return (processedSize == size); 1.74 + } 1.75 + UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); } 1.76 + bool WasFinished() const { return _wasFinished; } 1.77 +}; 1.78 + 1.79 +#endif