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

📄 cbqueue.h

📁 linux下的一款播放器
💻 H
📖 第 1 页 / 共 2 页
字号:
	*					out of the queue.	*	nItemCount		Number of items we want to dequeue.	*	*  DESCRIPTION:	*	One of our primary operations.	*	The client can redefine this function, but it is NOT necessary	*	as the default implementation will suffice for most cases.	*	In particular this method will remain valid even across changes	*	of object size in subclasses.	*	The client will only NEED to imlement an override if they need	*	to perform additional processing besides the block move of	*	bits.	*	*  RETURNS:	*	Number of bytes read out of the queue.	*/	virtual UINT16 DeQueue( void *pOutBuffer, UINT16 nItemCount )	{		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );		HX_ASSERT( pOutBuffer );		if (GetElementSize() > 1)		{			return( Base_DeQueueBytes( pOutBuffer, nItemCount * GetElementSize() ) );		}		else		{			return( Base_DeQueueBytes( pOutBuffer, nItemCount ) );		}	}   /*	** UINT16 EnQueue( pInBuffer, nItemCount )	*	*  PARAMETERS:	*	pInBuffer		Pointer to bytes we want to enqueue.	*	nItemCount		Number of items we want to enqueue.	*	*  DESCRIPTION:    *	One of our primary operations.	*	The client can redefine this function, but it is NOT necessary	*	as the default implementation will suffice for most cases.	*	In particular this method will remain valid even across changes	*	of object size in subclasses.	*	The client will only NEED to imlement an override if they need	*	to perform additional processing besides the block move of	*	bits.	*	*  RETURNS:	*	0			If there was not enough room to EnQueue() all the items 	*				specified.	*	Non-Zero 	To indicate that all items specified were enqueue'd.	*	*/	virtual UINT16 EnQueue( void *pInBuffer, UINT16 nItemCount )	{		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );		HX_ASSERT( pInBuffer );		if (GetElementSize() > 1)		{			return( Base_EnQueueBytes( pInBuffer, nItemCount * GetElementSize() ) );		}		else		{			return( Base_EnQueueBytes( pInBuffer, nItemCount ) );		}	}	/*	 * Grow the queue to twice its size or at least big enough to hold n more,	 * whichever is greater.  Returns 1 for good, 0 for bad.	 */	int Grow(UINT16 nItems);	void SetMaxSize(UINT16 ulMax);	/* *	Protected primitives for accessing the buffer and it's  *	pointers directly. *	These methods are available to our subclasses, but NOT to our *	clients. */protected:   /*	** UINT16 Base_GetBufferSize()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:    *	Returns the actual allocated size of the buffer.	*	*  RETURNS:	*	Size of the allocated buffer.	*/	UINT16 Base_GetBufferSize() const	{		HX_ASSERT( this );		return( m_nSize );	}   /*	** UINT16 Base_GetMaxBufferSize()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Returns the max size of the queue.	*	*  RETURNS:	*	Returns the max size of the queue.	*/	UINT16 Base_GetMaxBufferSize() const	{		HX_ASSERT( this );		return( m_nMaxSize );	}   /*	** UINT16 Base_GetUsedByteCount()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Returns the actual number of bytes we've enqueued.	*	*  RETURNS:	*	Number of bytes in USE in the queue.	*/	UINT16 Base_GetUsedByteCount() const	{		LONG32		iItemCount;		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );    		iItemCount = (LONG32)(m_pTail - m_pHead);		//	If iItemCount < 0 then we need to add m_nSize		iItemCount += (iItemCount < 0) ? Base_GetBufferSize() : 0;		HX_ASSERT(iItemCount <= (LONG32)Base_GetBufferSize());		return( (UINT16)iItemCount );	}   /*	** UINT16 Base_GetAvailableBytes()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Returns the number of bytes we can enqueue w/o failing.	*	*  RETURNS:	*	Returns the number of bytes we can enqueue w/o failing.	*/	UINT16 Base_GetAvailableBytes() const	{		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );    		return( Base_GetBufferSize() - Base_GetUsedByteCount() - 1 );	}   /*	** UINT16 Base_GetMaxAvailableBytes()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Returns the number of bytes we can enqueue w/o failing AFTER	*	the queue has been grown to its maximum capacity.	*	*  RETURNS:	*	Returns the number of bytes we can enqueue w/o failing.	*/	UINT16 Base_GetMaxAvailableBytes() const	{		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );    		return( Base_GetMaxBufferSize() - Base_GetUsedByteCount() - 1 );	}   /*	** UINT16 Base_EnQueueBytes( pInBuffer, nByteCount )	*	*  PARAMETERS:	*	pInBuffer		Pointer to bytes to enqueue.	*	nByteCount		Number of bytes to enqueue.	*	*  DESCRIPTION:	*	Enqueue's a stream of bytes.	*	(Puts bytes INTO the queue)	*	*  RETURNS:	*	0 if there was insufficient room to enqueue nByteCount bytes.	*	Number of bytes enqueued.	*	*/	UINT16 Base_EnQueueBytes( void *pInBuffer, UINT16 nByteCount );   /*	** UINT16 Base_DeQueueBytes( pOutBuffer, nByteCount )	*	*  PARAMETERS:	*	pOutBuffer		Pointer to buffer to receive bytes from queue.	*	nByteCount		Number of bytes to remove from queue.	*	*  DESCRIPTION:	*	DeQueue's a stream of bytes.	*	(Takes bytes OUT of the queue)	*	*  RETURNS:	*	The number of bytes dequeued from the queue.	*/	UINT16 Base_DeQueueBytes( void *pOutBuffer, UINT16 nByteCount );/* *	Private Implementation data.  We don't share this stuff w/ our subclasses. *	this way we can enforce our public and protected interface. */private:	UCHAR	*m_pData;   // the actual buffer pointer.	UCHAR	*m_pHead;	// points one byte before the next bytes to be						//	dequeue'd() from the queue (if !Empty).	UCHAR	*m_pTail;	// points at last byte of valid data in queue.						//	actually one byte before the next byte to receive new queue'd data	UCHAR	*m_pMax;	// pointer to one position beyond what we've allocated						//	helps us limit check m_pHead & mpTail.	UINT16		m_nSize;	// # of bytes in alloacated buffer		UINT16		m_nGranularity;		//	For our subclasses it's the size of an element								//	We'll make our buffer a multiple of this	UINT16		m_nMaxSize;		// if set, max size queue can grow to.	enum	{		FILLER_BYTE = 0xCC	};								   /*	** void Base_SetEmpty()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Instantly empty the queue.	*	*  RETURNS:	*	*/	void Base_SetEmpty()	{		HX_ASSERT( this );		m_pTail = m_pHead = m_pMax - 1;	}	   /*	** PBYTE Base_Normalize( pBuffer )	*	*  PARAMETERS:	*	pBuffer		Pointer to our buffer that we want to normalize.	*	*  DESCRIPTION:	*	Used to keep buffer pointer elements (m_pHead & m_pTail) in range 	*	of m_pData to m_pMax-1.	*	Basically this method helps us implement the mod function except	*	we work w/ pointers, and we don't actually divide.	*	*  RETURNS:	*	Normalized pointer.	*/	UCHAR * Base_Normalize( UCHAR * pBuffer, UINT16 offset ) const	{		HX_ASSERT( this );		HX_ASSERT( IsQueueValid() );		HX_ASSERT( pBuffer );#if defined(_WINDOWS) && !defined(_WIN32)		ULONG32 nNewBufferOffset = (((ULONG32)(UCHAR far*)pBuffer & 0x0000FFFF) + (ULONG32)(UCHAR far*)offset);				// wrap-up the buffer pointer		if ( nNewBufferOffset > 0xFFFF)		{				pBuffer = m_pData + (offset - (m_pMax - pBuffer));		}		else		{#endif		pBuffer += offset;		while (pBuffer >= m_pMax)		{			pBuffer -= m_nSize;		}#if defined(_WINDOWS) && !defined(_WIN32)		}		#endif		return( pBuffer );	}   /*	** UINT16 Base_GranulatedSize( nSize, nGranularity )	*	*  PARAMETERS:	*	nSize			A "proposed" size for our buffer.	*	nGranularity	The multiplier (for subclasses this is the size	*					of one of our elements).	*	*  DESCRIPTION:	*	Performs calcs to ensure our size is a multiple of our granularity.	*	This is done by rounding UP to the next even multiple of nGranularity	*	that is >= nSize.	*	*  RETURNS:	*	A rounded up quantity.	*/	static UINT16 Base_GranulatedSize( UINT16 nSize, UINT16 nGranularity = 1 )	{		if (nGranularity == 1)		{			return( nSize );		}		else		{			return( ((nSize + nGranularity - 1) / nGranularity) * nGranularity );		}	}   /*	** CByteQueue()	*	*  PARAMETERS:	*	void	*	*  DESCRIPTION:	*	Default constructor:  We hide this guy because we want to enforce	*	the parameterized constructor.	*	We might at some later time relax that restriction and allow	*	a two step creation process, but not for now.	*	*  RETURNS:	*	void	*/	CByteQueue()	{}   /*	** UINT16 Base_PeekBuff( pOutBuffer, nByteCount )	*	*  PARAMETERS:	*	pOutBuffer		Pointer to buffer to receive bytes.	*	nByteCount		Desired max bytes to copy out of queue.	*	*  DESCRIPTION:	*	Copies bytes (nByteCount) from the Queue head to pOutBuffer.	*	returns the number of bytess actually copied into pOutBuffer.	*	This function does NOT modify the queue.  It is strictly a 	*	peek of the queue bytes specified.	*	Our limiting factor is:	*		 min( nByteCount, Base_GetUsedByteCount() ).	*	*  RETURNS:	*	Number of bytes copied into pOutBuffer.	*/	UINT16 Base_PeekBuff( void *pOutBuffer, UINT16 nByteCount ) const;};	//	class CByteQueue#endif	//	if !defined( _CBQUEUE_H )

⌨️ 快捷键说明

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