This commit is contained in:
Igor Pavlov
2010-03-15 00:00:00 +00:00
committed by Kornel Lesiński
parent db5eb6d638
commit 993daef9cb
74 changed files with 5177 additions and 1736 deletions
+99
View File
@@ -2,6 +2,8 @@
#include "StdAfx.h"
#include "../../../C/Alloc.h"
#include "CWrappers.h"
#include "StreamUtils.h"
@@ -125,3 +127,100 @@ CSeekInStreamWrap::CSeekInStreamWrap(IInStream *stream)
p.Seek = InStreamWrap_Seek;
Res = S_OK;
}
/* ---------- CByteInBufWrap ---------- */
void CByteInBufWrap::Free()
{
::MidFree(Buf);
Buf = 0;
}
bool CByteInBufWrap::Alloc(UInt32 size)
{
if (Buf == 0 || size != Size)
{
Free();
Lim = Cur = Buf = (Byte *)::MidAlloc((size_t)size);
Size = size;
}
return (Buf != 0);
}
Byte CByteInBufWrap::ReadByteFromNewBlock()
{
if (Res == S_OK)
{
UInt32 avail;
Processed += (Cur - Buf);
Res = Stream->Read(Buf, Size, &avail);
Cur = Buf;
Lim = Buf + avail;
if (avail != 0)
return *Cur++;
}
Extra = true;
return 0;
}
extern "C" static Byte Wrap_ReadByte(void *pp)
{
CByteInBufWrap *p = (CByteInBufWrap *)pp;
if (p->Cur != p->Lim)
return *p->Cur++;
return p->ReadByteFromNewBlock();
}
CByteInBufWrap::CByteInBufWrap(): Buf(0)
{
p.Read = Wrap_ReadByte;
}
/* ---------- CByteOutBufWrap ---------- */
void CByteOutBufWrap::Free()
{
::MidFree(Buf);
Buf = 0;
}
bool CByteOutBufWrap::Alloc(size_t size)
{
if (Buf == 0 || size != Size)
{
Free();
Buf = (Byte *)::MidAlloc(size);
Size = size;
}
return (Buf != 0);
}
HRESULT CByteOutBufWrap::Flush()
{
if (Res == S_OK)
{
size_t size = (Cur - Buf);
Res = WriteStream(Stream, Buf, size);
if (Res == S_OK)
Processed += size;
Cur = Buf;
}
return Res;
}
extern "C" static void Wrap_WriteByte(void *pp, Byte b)
{
CByteOutBufWrap *p = (CByteOutBufWrap *)pp;
Byte *dest = p->Cur;
*dest = b;
p->Cur = ++dest;
if (dest == p->Lim)
p->Flush();
}
CByteOutBufWrap::CByteOutBufWrap(): Buf(0)
{
p.Write = Wrap_WriteByte;
}
+65 -2
View File
@@ -3,8 +3,6 @@
#ifndef __C_WRAPPERS_H
#define __C_WRAPPERS_H
#include "../../../C/Types.h"
#include "../ICoder.h"
#include "../../Common/MyCom.h"
@@ -43,4 +41,69 @@ struct CSeqOutStreamWrap
HRESULT SResToHRESULT(SRes res);
struct CByteInBufWrap
{
IByteIn p;
const Byte *Cur;
const Byte *Lim;
Byte *Buf;
UInt32 Size;
ISequentialInStream *Stream;
UInt64 Processed;
bool Extra;
HRESULT Res;
CByteInBufWrap();
~CByteInBufWrap() { Free(); }
void Free();
bool Alloc(UInt32 size);
void Init()
{
Lim = Cur = Buf;
Processed = 0;
Extra = false;
Res = S_OK;
}
UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
Byte ReadByteFromNewBlock();
Byte ReadByte()
{
if (Cur != Lim)
return *Cur++;
return ReadByteFromNewBlock();
}
};
struct CByteOutBufWrap
{
IByteOut p;
Byte *Cur;
const Byte *Lim;
Byte *Buf;
size_t Size;
ISequentialOutStream *Stream;
UInt64 Processed;
HRESULT Res;
CByteOutBufWrap();
~CByteOutBufWrap() { Free(); }
void Free();
bool Alloc(size_t size);
void Init()
{
Cur = Buf;
Lim = Buf + Size;
Processed = 0;
Res = S_OK;
}
UInt64 GetProcessed() const { return Processed + (Cur - Buf); }
HRESULT Flush();
void WriteByte(Byte b)
{
*Cur++ = b;
if (Cur == Lim)
Flush();
}
};
#endif