Click here to Skip to main content
15,885,876 members
Articles / Desktop Programming / MFC

CleanZipAndGo

Rate me:
Please Sign up or sign in to vote.
4.29/5 (7 votes)
20 May 20031 min read 70.8K   870   21  
Utility to quickly archive any project to a Zip file.
// AutoBuffer.cpp: implementation of the CAutoBuffer class.
//
////////////////////////////////////////////////////////////////////////////////
//  Copyright (C) 2000 Tadeusz Dracz.
////////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AutoBuffer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CAutoBuffer::CAutoBuffer()
{
	m_iSize = 0;
	m_pBuffer = NULL;	
}

CAutoBuffer::CAutoBuffer(DWORD iSize, bool bZeroMemory)
{
	m_iSize = 0;
	m_pBuffer = NULL;
	Allocate(iSize, bZeroMemory);
}

CAutoBuffer::~CAutoBuffer()
{
	Release();
}

bool CAutoBuffer::IsAllocated()
{
	return (m_pBuffer != NULL);
}


DWORD CAutoBuffer::GetSize()
{
	return m_iSize;
}

void CAutoBuffer::Release()
{
	if (m_pBuffer)
	{
		delete [] m_pBuffer;
		m_iSize = 0;
		m_pBuffer = NULL;
	}
}

char* CAutoBuffer::Allocate(DWORD iSize, bool bZeroMemory)
{
	if (iSize != m_iSize)
		Release();
	else
	{
		if (bZeroMemory)
			memset(m_pBuffer, 0, iSize); // zerowanie bufora
		return m_pBuffer;
	}

	if (iSize > 0)
	{
// 		try
// 		{
			m_pBuffer = new char [iSize];


			m_iSize = iSize;
// 		}
// 		catch (CMemoryException *e)
// 		{
// 			e->Delete();
// 			return NULL;
// 		}
	}
	else 
		m_pBuffer = NULL;

	return m_pBuffer;
}

CAutoBuffer::operator char*()
{
	return m_pBuffer;
}

CAutoBuffer::CAutoBuffer(CAutoBuffer& buffer)
{
	m_pBuffer = NULL;
	m_iSize = 0;

	if (buffer.m_pBuffer)
	{
		Allocate(buffer.m_iSize);
		memcpy(m_pBuffer, buffer.m_pBuffer, buffer.m_iSize);
	}	
}
CAutoBuffer& CAutoBuffer::operator=(const CAutoBuffer& buffer)
{
	if (this == &buffer)
		return *this;
	Release();
	if (buffer.m_pBuffer)
	{
		Allocate(buffer.m_iSize);
		memcpy(m_pBuffer, buffer.m_pBuffer, buffer.m_iSize);
	}
	return *this;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions