📄 cbqueue.h
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: cbqueue.h,v 1.1.1.1.50.3 2004/07/09 01:45:50 hubbe Exp $ * * Portions Copyright (c) 1995-2004 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 (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (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. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * 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: CBQueue.h * * CLASS: * CByteQueue 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 * functionality. * * NOTES: * See the CPQueue.h file for an example of a minimal subclass * that changes the size of the queue'd items. * * The only time a subclass MUST provide a virtual override * is for the GetElementSize() method when the subclass changes * the size of queued elements. All other virtual methods * provide fully functional default behavior that will ramain * functional even when the ElementSize changes. * * The assignment operator is one of the few cases where a * subclass will need to provide new functionality by virtue of * inheriting from the base. Subclasses should use the base * method for assigning the bits of the base class prior to * performing their own assignment related operations. * *******************************************************************/#if !defined( _CBQUEUE_H )#define _CBQUEUE_H #include "hxtypes.h"#include "hxassert.h"#if !defined( NULL )#define NULL 0#endif#if !defined( FALSE )#define FALSE 0#endif // !defined( FALSE )#if !defined( TRUE )#define TRUE !FALSE#endif // !defined( TRUE )class CByteQueue{/* * Our public interface. * These are the methods we export to the world. * These methods are primarily used by our clients. */public: /* ** CByteQueue( nSize, nGranularity ) * * PARAMETERS: * nSize Size of the bytequeue in bytes. * nGranularity For subclasses we ensure our size is a multiple of this. * * DESCRIPTION: * Parameterized constructor. * This is the primary means of creating an instance of CByteQueue. * * RETURNS: * void */ CByteQueue( UINT16 nSize, UINT16 nGranularity = 1); /* ** CByteQueue( rReferent ) * * PARAMETERS: * rReferent Constant reference to another CByteQueue object. * * DESCRIPTION: * Copy constructor (ctor). Copies a CByteQueue into * another CByteQueue that is under construction. * This guy is called in construction situations like this: * CByteQueue rQueueOrig( 10 ); // Call param ctor * CByteQueue rQueueCopy = rQueueOrig; // Call copy ctor * * RETURNS: * void */ CByteQueue( const CByteQueue &rReferent ); /********************************************************* * Here are are non-virtual methods that provide * primitive functionality to all queues. *********************************************************/ /* ** GetQueuedItemCount() * * PARAMETERS: * void * * DESCRIPTION: * Returns a count of the items we have queue'd up. * This function is accurate even in subclasses with * elements that are a different size from a UCHAR. * * RETURNS: * Returns the number of ITEMS we have queued up. * */ UINT16 GetQueuedItemCount() const { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); return( Base_GetUsedByteCount() / GetElementSize() ); } /* ** UINT16 GetAvailableElements() * * PARAMETERS: * void * * DESCRIPTION: * Returns the number of ITEMS we can EnQueue w/o failing. * * RETURNS: * 0 if the queue is full * non-zero to indicate how many ITEMS we can EnQueue. */ UINT16 GetAvailableElements() const { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); return( Base_GetAvailableBytes() / GetElementSize() ); } /* ** UINT16 GetMaxAvailableElements() * * PARAMETERS: * void * * DESCRIPTION: * Returns the number of ITEMS we can EnQueue w/o failing AFTER * we have grown the queue to its Maximum size. * * RETURNS: * 0 if the queue is full AND there is no more room to grow * beyond the max size * non-zero to indicate how many ITEMS we can EnQueue. */ UINT16 GetMaxAvailableElements() const { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); return( Base_GetMaxAvailableBytes() / GetElementSize() ); } /* ** BOOL IsEmpty() * * PARAMETERS: * void * * DESCRIPTION: * Tells us if the queue is empty. * * RETURNS: * Returns TRUE if the queue is empty. * */ BOOL IsEmpty() const { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); return( m_pTail == m_pHead ); } /* ** CByteQueue &operator=( rReferent ) * * PARAMETERS: * Constant reference to the CByteQueue object we are assigning from * (the rValue). * * DESCRIPTION: * Assignment operator. * This guy gets called when we assign a CByteQueue. * This guy creates a fully functional copy of the source queue. * * Subclasses that want an assignment operator SHOULD redefine * this guy, but they should use the base method to copy the * bits of the base class. * * RETURNS: * A reference to the object we are assigning into. */ CByteQueue &operator=( const CByteQueue &rReferent ); /* ** UINT16 PeekAt( nIndex, pOutBuffer ) * * PARAMETERS: * nIndex The nIndex'th object from the head of the queue * that we are interested in. * pOutBuffer Pointer to the buffer to receive the contents of the * element. * * DESCRIPTION: * Peeks at a particular index off of the first element in the queue. * The index is 0 based, hence an index of 0 will indicate the queue * Head element. * Will copy the element of size GetElementSize() into the pOutBuffer. * *pbIsValid is set to FALSE if the element is not valid data. * Notice that the client needn't redifine this guy if the default * is satisfactory. * In particular this method will remain valid even across changes * of object size in the subclass. * The client will only NEED to imlement an override if they need * to provide another level of indirection. * * RETURNS: * Returns the number of bytes copied into pOutBuffer. * 0 if nIndex specifies an invalid position in the queue. * (for instance if nIndex is 3, but there are only 2 elements * queued up we wil return 0) */ UINT16 PeekAt( UINT16 nIndex, void *pOutBuffer ) const; /* ** FlushQueue() * * PARAMETERS: * void * * DESCRIPTION: * Instantly flush all elements from the queue. * * RETURNS: * void */ void FlushQueue() { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); Base_SetEmpty(); } /********************************************************* * The rest of these public methods are virtual. * * HOWEVER, the default behavior is will remain fully * functional across all changes in object size. * * The only reason to provide overrides in subclasses * is to provide additional behavior. If you do * implement an override make sure it calls the base * virtual method. *********************************************************/ /* ** UINT16 GetElementSize() * * PARAMETERS: * void * * DESCRIPTION: * Subclasses that redefine the element size MUST provide * an implementation for this. * * RETURNS: * The queue element size. * For a queue of pointers we'd return sizeof( void * ). */ virtual UINT16 GetElementSize() const { HX_ASSERT( this ); HX_ASSERT( IsQueueValid() ); return( sizeof( UCHAR ) ); } /* ** ~CByteQueue() * * PARAMETERS: * void * * DESCRIPTION: * Destructor * Notice that this is a virtual destructor. * The base class CByteQueue will delete the buffer. * The subclass need only implement on override if they * need additional cleanup besides the buffer. * * RETURNS: * void */ virtual ~CByteQueue(); /* ** BOOL IsQueueValid() * * PARAMETERS: * void * * DESCRIPTION: * This method allows the client to test the queue object for * validity. The base class implements default behavior that * tests it's internal buffer pointers. * The subclass will only need to implement an override if they * have additional validity checks. * * Any override of this funcion MUST return the logical AND of * it's validity checks and the checks of the base method. * Sort of like: * return( CByteQueue::IsQueueValid() && CSubClass::IsQueueValid() ) * * RETURNS: * TRUE If the queue is valid. * FALSE If there is an error in the queue members. */ virtual BOOL IsQueueValid() const; /* ** UINT16 DeQueue( pOutBuffer, nItemCount ) * * PARAMETERS: * pOutBuffer Pointer to buffer to receive bytes we're pulling
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -