#include "stdafx.h"
#include "ByteArray.h"

CByteArray::CByteArray()
{
	iBufferSize = 0;
	byBuffer = NULL;
	boSetBufferSize = TRUE;
}

CByteArray::~CByteArray()
{
	if (byBuffer)
	{
		delete []byBuffer;
	}
}

BYTE* CByteArray::GetData()
{
	return byBuffer;
}

int CByteArray::GetSize()
{
	return iBufferSize;
}

BOOL CByteArray::SetSize(int _iSize)
{
	BOOL boSetBufferSize = TRUE;
	BYTE *pTemp;
	int vSize;
	try
	{
		vSize = iBufferSize;
		if (vSize > 0)
		{
			pTemp = new BYTE[vSize];
			memcpy(pTemp,byBuffer,vSize);
			delete []byBuffer;
			byBuffer = NULL;
		}
		if (_iSize > 0)
		{
			byBuffer = new BYTE[_iSize];
			if (vSize > _iSize)
				vSize = _iSize;
			memcpy(byBuffer,pTemp,vSize);
			iBufferSize = _iSize;
			boSetBufferSize = TRUE;
		}
	}
	catch (...)
	{//+FIXME
		boSetBufferSize = FALSE;
	}
	return boSetBufferSize;
}