⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbbqueue.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

/*******************************************************************
 *
 *	NAME:	cbbqueue.h
 *
 *	CLASS:
 *		CBigByteQueue class declaration.
 *
 *	DESCRIPTION:
 *		Class declaration for a 'Queue of bytes' object.
 *		This object is meant to serve the needs of either clients as
 *		an abstract object, or of subclasses as a base object.
 *
 *		That is a client may use this instances of this class directly,
 *		or they may inherit from the class and provide expanded
 *
 *	NOTES:
 *		This is a re-implementation of CBigByteQueue using 32-bit pointers
 *
 *******************************************************************/

#include "cbbqueue.h"

#include "hlxclib/string.h"		//	for memcpy()

#include "hxassert.h"

#if defined( _WINDOWS ) || defined( _WIN32 )
#include <stdlib.h>		//	for __min()
#endif
#if !defined( __min )
#define __min(a,b)  (((a) < (b)) ? (a) : (b))
#endif	//	!defined( __min )

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif									 

 /*
 ** CBigByteQueue::CBigByteQueue( ulSize, ulElementSize )
 *
 *  PARAMETERS:
 *		ulSize			Number of bytes we want to be able to put in queue
 *		ulElementSize		Make our buffer a multiple of this size.
 *							(for subclasses)
 *
 *  DESCRIPTION:
 *		Parameterized constructor.
 *
 *  RETURNS:
 *		void
 */
CBigByteQueue::CBigByteQueue( UINT32 ulSize, UINT32 ulElementSize ) :
	m_pData( 0 ),
	m_pTail( 0 ),
	m_pHead( 0 ),
	m_pMax( 0 ),
	m_ulMaxSize(0),
	m_ulElementSize( ulElementSize )
{
	HX_ASSERT( this );

	//	We add one here because the queue MUST maintain at least one byte
	//	free in the allocated buffer (to distinguish full from empty states).
	m_ulSize = CBigByteQueue::Base_GranulatedSize( ulSize, ulElementSize ) + 1;
	m_pData = new UCHAR[m_ulSize];
	if (!m_pData)
	{
		//	If we used exceptions, now would be a good time
		//	to throw one.
		m_ulSize = 0;
		HX_ASSERT( 0 );
		return;
	}
	else
	{
		m_pMax = m_pData + Base_GetBufferSize();
		Base_SetEmpty();
#if defined( _DEBUG )
		HX_ASSERT( IsQueueValid() );
		//	Init our buffer w/ known garbage
		memset( m_pData, 0xfc, Base_GetBufferSize() );
#endif	//	_DEBUG
	}
	return;
}	//	CBigByteQueue() - Parameterized constructor


/*
 ** CBigByteQueue::CBigByteQueue( const CBigByteQueue &rReferent )
 *
 *  PARAMETERS:
 *		rReferent		A constant reference to the object we want to copy.
 *
 *  DESCRIPTION:
 *		Copy constructor.
 *
 *  RETURNS:
 *		void
 */
CBigByteQueue::CBigByteQueue( const CBigByteQueue &rReferent ) :
	m_pData( 0 ),
	m_pTail( 0 ),
	m_pHead( 0 ),
	m_pMax( 0 ),
	m_ulSize( 0 ),
	m_ulElementSize( 0 ),
	m_ulMaxSize(0)
{
	HX_ASSERT( this );

	//	Are we copying ourselves?  It's a nop if we are.
	if (&rReferent == this)
	{
		return;
	}

	//	Ok, figure out how large a buffer to get and allocate it
	m_pData = new UCHAR[rReferent.Base_GetBufferSize()];
	if (!m_pData)
	{
		//	If we had exceptions, now would be a good time
		//	to throw one.
		m_ulSize = 0;
		HX_ASSERT( 0 );
		return;
	}
	else
	{
		m_ulSize = rReferent.Base_GetBufferSize();
		m_pMax = m_pData + Base_GetBufferSize();
		m_ulElementSize = rReferent.m_ulElementSize;

		//	Get a copy of the referent's data into our buffer
		rReferent.Base_PeekBuff( m_pData + 1, Base_GetBufferSize() );
		m_pHead = m_pData;
		m_pTail = m_pData + rReferent.Base_GetUsedByteCount();
	}
	return;
}	//	CBigByteQueue() - Copy constructor


/*
 ** CBigByteQueue::~CBigByteQueue()
 *
 *  PARAMETERS:
 *		void
 *
 *  DESCRIPTION:
 *		Virtual destructor for the base class.
 *
 *  RETURNS:
 *		void
 */
CBigByteQueue::~CBigByteQueue()
{
	HX_ASSERT( this );

	if (m_pData)
	{
		HX_ASSERT( IsQueueValid() );    
		delete [] m_pData;
	}
	m_pData = NULL;
	m_pTail = NULL;
	m_pHead = NULL;
	m_pMax = NULL;
	m_ulSize = 0;
	m_ulElementSize = 0;

#if defined( _DEBUG )
	memset( this, FILLER_BYTE, sizeof( *this ) );
#endif

}	//	~CBigByteQueue() - Destructor


/*
 ** CBigByteQueue & CBigByteQueue::operator=( const CBigByteQueue &rReferent )
 *
 *  PARAMETERS:
 *		rReferant		Constant reference to an object to assign from (rValue).
 *
 *  DESCRIPTION:
 *		This is our assignment operator.  It assigns from rReferent to
 *		an existing object.
 *
 *  RETURNS:
 *		A reference to ourselves.
 */
CBigByteQueue & CBigByteQueue::operator=( const CBigByteQueue &rReferent )
{
	HX_ASSERT( this );
	HX_ASSERT( rReferent.IsQueueValid() );
	HX_ASSERT( &rReferent );

	//	Do we need to allocate a new buffer?
	if (rReferent.Base_GetBufferSize() != Base_GetBufferSize())
	{
		//	Yes, Allocate the new buffer & copy into it.
		UCHAR *	pByte;

		//	Ok, figure out how large a buffer to get and allocate it
		pByte = new UCHAR[rReferent.Base_GetBufferSize()];
		if (pByte)
		{
			if (m_pData)
			{
				delete [] m_pData;
			}
			m_pData = NULL;
			m_pData = pByte;
		}
		else
		{
			//	Failed buffer allocataion request....
			//	It would be nice if we could fail gracefully or throw
			//	an exception.
			HX_ASSERT( 0 );
			return( *this );
		}
	}

	//	Now need to copy over all of the other elements
	//	Or at least set our elements to the correct data
	m_ulSize = rReferent.Base_GetBufferSize();
	m_pMax = m_pData + m_ulSize;
	m_ulElementSize = rReferent.m_ulElementSize;

	//	Get a copy of the referent's data into our buffer
	rReferent.Base_PeekBuff( m_pData + 1, Base_GetBufferSize() );
	m_pHead = m_pData;
	m_pTail = m_pData + rReferent.Base_GetUsedByteCount();

	HX_ASSERT( IsQueueValid() );    
	return( *this );
}	//	operator=()


/*
 ** BOOL CBigByteQueue::IsQueueValid()
 *
 *  PARAMETERS:
 *		void
 *
 *  DESCRIPTION:
 *		This is meant to validate our queue either for debugging
 *		purposes, or to ensure a queue was correctly created.
 *		(A memory allocation at create time didn't occur).
 *
 *  RETURNS:
 *		void
 */
BOOL 
CBigByteQueue::IsQueueValid() const
{
	HX_ASSERT( this );

	//	Ensure we have no NULL pointers & we have a size
	if (!m_pData || !m_pTail || !m_pHead || !m_pMax || !m_ulSize ||
	 !m_ulElementSize)
	{
		return( FALSE );
	}
	//	Ensure m_pTail is in range
	if (m_pTail < m_pData || m_pTail >= m_pMax)
	{
		return( FALSE );
	}
	//	Ensure m_pHead is in range
	if (m_pHead < m_pData || m_pHead >= m_pMax)
	{
		return( FALSE );
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -