#include <WOscPriorityQueue.h>
Inherited by WOscReceiver [private]
.
Public Member Functions | |
WOscPriorityQueue (int initialCapacity) | |
virtual | ~WOscPriorityQueue () |
void | InsertItem (WOscQueueItem *item) |
WOscQueueItem * | RemoveEarliestItem () |
WOscTimeTag | GetEarliestTimeTag () |
int | GetNumItems () |
Sorts queue-items by their time tag when inserted. The earliest items can be queried and/or removed.
Definition at line 115 of file WOscPriorityQueue.h.
WOscPriorityQueue::WOscPriorityQueue | ( | int | initialCapacity | ) |
Constructor. Constructs an empty priority queue with a capacity of "initialCapacity".
initialCapacity | The initial capacity (how many items can be inserted until doubleCapacity() will be called. |
Definition at line 58 of file WOscPriorityQueue.cpp.
00059 { 00060 00061 /* allocate list (queue) */ 00062 m_listCapacity = initialCapacity; 00063 m_list = new WOscQueueItem*[initialCapacity]; 00064 00065 /* reset list (no items) */ 00066 for( int i = 0; i < initialCapacity; i++ ) 00067 m_list[i] = NULL; 00068 m_itemsInList = 0; 00069 00070 }
WOscPriorityQueue::~WOscPriorityQueue | ( | ) | [virtual] |
Destructor. All elements which are not removed from the priority-queue get deleted automatically.
Definition at line 77 of file WOscPriorityQueue.cpp.
References GetNumItems(), and RemoveEarliestItem().
00078 { 00079 00080 /* empty queue as long there are items in the queue*/ 00081 while( GetNumItems() > 0 ) 00082 delete RemoveEarliestItem(); 00083 00084 delete [] m_list; 00085 }
WOscTimeTag WOscPriorityQueue::GetEarliestTimeTag | ( | ) |
Returns the timetag of the earliest item. Searches by linearly traversing the queue.
Definition at line 143 of file WOscPriorityQueue.cpp.
References WOscTimeTag::GetLargestTimeTag().
Referenced by WOscReceiver::ManagePriorityQueue().
00144 { 00145 00146 WOscTimeTag smallest = WOscTimeTag::GetLargestTimeTag(); 00147 00148 for ( int i = 0; i < m_itemsInList; i++ ) 00149 if ( *m_list[i] < smallest ) 00150 smallest = *m_list[i]; 00151 00152 return smallest; 00153 }
int WOscPriorityQueue::GetNumItems | ( | ) |
Returns the number of items in the queue.
Definition at line 216 of file WOscPriorityQueue.cpp.
Referenced by WOscReceiver::ManagePriorityQueue(), and ~WOscPriorityQueue().
void WOscPriorityQueue::InsertItem | ( | WOscQueueItem * | item | ) |
Inserts an item into the queue. Items are simply inserted and not ordered.
Definition at line 96 of file WOscPriorityQueue.cpp.
WOscQueueItem * WOscPriorityQueue::RemoveEarliestItem | ( | ) |
Removes the earliest item from the queue and returns it.
WOscException | When trying to remove from an empty queue. |
Definition at line 187 of file WOscPriorityQueue.cpp.
References ERR_REMOVE_FROM_EMPTY_QUEUE.
Referenced by WOscReceiver::ManagePriorityQueue(), and ~WOscPriorityQueue().
00188 { 00189 00190 WOscQueueItem* result; 00191 00192 int smallestIdx = 0; 00193 00194 if ( m_itemsInList == 0 ) 00195 throw WOscException(ERR_REMOVE_FROM_EMPTY_QUEUE, __FILE__, __LINE__); 00196 00197 /* traverse the queue and */ 00198 for ( int i = 0; i < m_itemsInList; i++ ) 00199 /* compare time-tags */ 00200 if ( *m_list[smallestIdx] > *m_list[i] ) 00201 smallestIdx = i; 00202 00203 /* save pointer before removing it */ 00204 result = m_list[smallestIdx]; 00205 00206 RemoveItem(smallestIdx); 00207 00208 return result; 00209 }