www.pudn.com > voado.zip > VOString.cpp


// VOString.cpp: implementation of the CVOString class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "VOString.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CVOString::CVOString(LPCTSTR pcszValue) 
{ 
	m_pBuffer = NULL; 
	m_dwBufferSize = 0; 
 
	*this = pcszValue; 
} 
 
// Copy Constructor 
CVOString::CVOString(const CVOString &rSrc) 
{ 
	m_pBuffer = NULL; 
	m_dwBufferSize = 0; 
 
	*this = rSrc.m_pBuffer; 
} 
 
CVOString::~CVOString() 
{ 
	if(m_pBuffer) 
		delete m_pBuffer; 
} 
 
CVOString::operator = (LPCTSTR pcszValue) 
{ 
 
	m_dwLength = _tcslen(pcszValue); 
 
	SetMinBufferSize(m_dwLength); 
	_tcscpy(m_pBuffer, pcszValue); 
} 
 
BOOL CVOString::operator == (LPCTSTR pcszValue) 
{ 
	return(_tcscmp(pcszValue, m_pBuffer) == 0); 
} 
 
LPCTSTR CVOString::operator += (LPCTSTR pcszAppend) 
{ 
	SetMinBufferSize(GetLength() + _tcslen(pcszAppend)); 
 
	_tcscat(m_pBuffer, pcszAppend); 
	return *this; 
} 
 
BOOL CVOString::SetMinBufferSize(DWORD dwChars) 
{ 
	if(m_dwBufferSize < dwChars + 1) 
	{ 
		TCHAR*	pNewBuffer; 
		DWORD	dwNewBufferSize = dwChars + 256; 
 
		pNewBuffer = new TCHAR[dwNewBufferSize]; 
 
		if(m_pBuffer) 
		{ 
			memmove(pNewBuffer, m_pBuffer, m_dwBufferSize); 
			delete m_pBuffer; 
		} 
 
		m_pBuffer = pNewBuffer; 
		m_dwBufferSize = dwNewBufferSize; 
	} 
 
	return TRUE; 
}