// $Header: G:/SwDev/WDM/Video/bt848/rcs/Queue.h 1.5 1998/05/08 18:18:52 tomz Exp $ #ifndef __QUEUE_H #define __QUEUE_h const QueSize = 200; /* Class: VidBufQueue * Purpose: Queue of buffers to be sent to BtPisces */ template class Queue { private: T Data [QueSize]; T Dummy; unsigned items; unsigned left; unsigned right; unsigned size; public: bool IsFull(); bool IsEmpty(); unsigned Prev( unsigned index ) const; unsigned Next( unsigned index ) const; T Get(); T GetRight(); void Put( const T& t ); T PeekLeft(); T PeekRight(); void Flush(); int GetNumOfItems(); Queue(); ~Queue(); }; template bool Queue::IsFull() { return right == Prev( left ); } template bool Queue::IsEmpty() { return !items; } template int Queue::GetNumOfItems() { return items; } template unsigned Queue::Prev( unsigned index ) const { if ( index == 0 ) index = size; return --index; } template unsigned Queue::Next( unsigned index ) const { index++; if ( index == size ) index = 0; return index; } template T Queue::Get() { if(!items){ DebugOut((0, "Queue::Get called on empty queue!!!\n")); // DEBUG_BREAKPOINT(); return Dummy; } T t = Data [left]; Data [left] = T(); left = Next( left ); items--; return t; } /* Method: Queue::GetRight * Purpose: Gets the next element * Note: Extreme caution must be used when calling this function. The caller must * make sure the queue is not empty before calling it. Otherwise bogus data * will be returned */ template T Queue::GetRight() { if(!items){ DebugOut((0, "Queue::GetRight called on empty queue!!!\n")); // DEBUG_BREAKPOINT(); return Dummy; } right = Prev( right ); T t = Data [right]; Data[right] = T(); items--; return t; } template void Queue::Flush() { if(items){ DebugOut((0, "Queue::Flush called on non-empty queue, %d items lost!!!\n", items)); // DEBUG_BREAKPOINT(); } items = left = right = 0; } template void Queue::Put( const T& t ) { if ( items >= size ){ DebugOut((0, "Queue::Put called on Full queue!!!\n")); // DEBUG_BREAKPOINT(); return; } Data [right] = t; right = Next( right ); items++; } template Queue::Queue() : Data(), Dummy(), items( 0 ), left( 0 ), right( 0 ), size( QueSize ) { } template T Queue::PeekLeft() { if(!items){ DebugOut((0, "Queue::PeekLeft called on empty queue!!!\n")); // DEBUG_BREAKPOINT(); return Dummy; } return Data [left]; } template T Queue::PeekRight() { if(!items){ DebugOut((0, "Queue::PeekRight called on empty queue!!!\n")); // DEBUG_BREAKPOINT(); return Dummy; } return Data [Prev( right )]; } template Queue::~Queue() { } typedef Queue SRBQueue; #endif