4
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

58 lines
1.1 KiB

#include "IBufferStream.h"
IBufferStream::IBufferStream()
:streamBuf(NULL), flags(0)
{
}
IBufferStream::IBufferStream(const IBufferStream & rhs)
{
// explicitly not supporting copy constructor for self-owned buffers
ASSERT((flags & kFlag_OwnedBuf) == 0);
}
IBufferStream::IBufferStream(void * buf, UInt64 inLength)
:streamBuf(NULL), flags(0)
{
SetBuffer(buf, inLength);
}
IBufferStream::~IBufferStream()
{
if(flags & kFlag_OwnedBuf)
{
delete [] streamBuf;
}
}
IBufferStream & IBufferStream::operator=(IBufferStream & rhs)
{
// explicitly not supporting copying for self-owned buffers
ASSERT((flags & kFlag_OwnedBuf) == 0);
streamBuf = rhs.streamBuf;
flags = rhs.flags;
return *this;
}
void IBufferStream::SetBuffer(void * buf, UInt64 inLength)
{
streamBuf = (UInt8 *)buf;
streamLength = inLength;
Rewind();
}
void IBufferStream::ReadBuf(void * buf, UInt32 inLength)
{
memcpy(buf, &streamBuf[streamOffset], inLength);
streamOffset += inLength;
}
void IBufferStream::WriteBuf(const void * buf, UInt32 inLength)
{
memcpy(&streamBuf[streamOffset], buf, inLength);
streamOffset += inLength;
}