This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -1,39 +1,48 @@
// InBuffer.h
// #pragma once
#ifndef __INBUFFER_H
#define __INBUFFER_H
#include "../IStream.h"
#include "../../Common/MyCom.h"
#ifndef _NO_EXCEPTIONS
class CInBufferException
{
public:
HRESULT ErrorCode;
CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
};
#endif
class CInBuffer
{
UINT64 _processedSize;
BYTE *_bufferBase;
UINT32 _bufferSize;
BYTE *_buffer;
BYTE *_bufferLimit;
ISequentialInStream *_stream;
bool _streamWasExhausted;
UInt64 _processedSize;
Byte *_bufferBase;
UInt32 _bufferSize;
Byte *_buffer;
Byte *_bufferLimit;
CMyComPtr<ISequentialInStream> _stream;
bool _wasFinished;
bool ReadBlock();
public:
CInBuffer(UINT32 bufferSize = 0x100000);
~CInBuffer();
void Init(ISequentialInStream *stream);
// void ReleaseStream() { _stream.Release(); }
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
bool ReadByte(BYTE &b)
CInBuffer();
~CInBuffer() { Free(); }
bool Create(UInt32 bufferSize);
void Free();
void SetStream(ISequentialInStream *stream);
void Init();
void ReleaseStream() { _stream.Release(); }
bool ReadByte(Byte &b)
{
if(_buffer >= _bufferLimit)
if(!ReadBlock())
@@ -41,26 +50,27 @@ public:
b = *_buffer++;
return true;
}
BYTE ReadByte()
Byte ReadByte()
{
if(_buffer >= _bufferLimit)
if(!ReadBlock())
return 0x0;
return 0xFF;
return *_buffer++;
}
void ReadBytes(void *data, UINT32 size, UINT32 &processedSize)
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
{
for(processedSize = 0; processedSize < size; processedSize++)
if (!ReadByte(((BYTE *)data)[processedSize]))
if (!ReadByte(((Byte *)data)[processedSize]))
return;
}
bool ReadBytes(void *data, UINT32 size)
bool ReadBytes(void *data, UInt32 size)
{
UINT32 processedSize;
UInt32 processedSize;
ReadBytes(data, size, processedSize);
return (processedSize == size);
}
UINT64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
bool WasFinished() const { return _wasFinished; }
};
#endif