1
0

implement xsofts recommendations

This commit is contained in:
Tycho Bickerstaff 2014-01-03 11:22:01 +00:00
parent ea6f94f6cb
commit 6f3c5b806e

View File

@ -5,15 +5,18 @@
#pragma once #pragma once
#include <list>
/* /*
Items can be added multiple times to a queue, there are two functions for
adding, EnqueueItem() and EnqueueItemIfNotPresent(). The first one always
enqueues the specified item, the second one checks if the item is already
present and only queues it if it isn't.
Usage: Usage:
To use the callback functions Delete and Combine create a class with the two To create a queue of type T, instantiate a cQueue<T> object. You can also
methods and pass it as a second template parameter to cQueue. The class does modify the behavior of the queue when deleting items and when adding items
not need to inherit cQueueFuncs but you do so to document the classes purpose. that are already in the queue by providing a second parameter, a class that
The second template parmeter is optional if not overriding the callback implements the functions Delete() and Combine(). An example is given in
functions cQueueFuncs and is used as the default behavior.
*/ */
// this empty struct allows for the callback functions to be inlined // this empty struct allows for the callback functions to be inlined
@ -25,7 +28,7 @@ struct cQueueFuncs
static void Delete(T) {}; static void Delete(T) {};
// Called when an Item is inserted with EnqueueItemIfNotPresent and // Called when an Item is inserted with EnqueueItemIfNotPresent and
// there is another equal value already inserted // there is another equal value already inserted
static void Combine(T& a_existing, const T a_new) {}; static void Combine(T& a_existing, const T& a_new) {};
}; };
template<class ItemType, class Funcs = cQueueFuncs<ItemType> > template<class ItemType, class Funcs = cQueueFuncs<ItemType> >
@ -73,7 +76,10 @@ public:
bool TryDequeueItem(ItemType& item) bool TryDequeueItem(ItemType& item)
{ {
cCSLock Lock(m_CS); cCSLock Lock(m_CS);
if (m_contents.size() == 0) return false; if (m_contents.size() == 0)
{
return false;
}
item = m_contents.front(); item = m_contents.front();
m_contents.pop_front(); m_contents.pop_front();
m_evtRemoved.Set(); m_evtRemoved.Set();