From 2ab8d2bd98004e40a915e1c9eca764d32115d6c5 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Tue, 9 Dec 2014 10:43:40 +0100 Subject: Added a RemoveIf() function to cQueue --- src/OSSupport/Queue.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/OSSupport/Queue.h b/src/OSSupport/Queue.h index 8d096fe29..82f221453 100644 --- a/src/OSSupport/Queue.h +++ b/src/OSSupport/Queue.h @@ -163,6 +163,29 @@ public: return false; } + + /** Removes all items for which the predicate returns true. */ + template + void RemoveIf(Predicate a_Predicate) + { + cCSLock Lock(m_CS); + for (auto itr = m_Contents.begin(); itr != m_Contents.end();) + { + if (a_Predicate(*itr)) + { + auto itr2 = itr; + ++itr2; + m_Contents.erase(itr); + m_evtRemoved.Set(); + itr = itr2; + } + else + { + ++itr; + } + } // for itr - m_Contents[] + } + private: /// The contents of the queue QueueType m_Contents; -- cgit v1.2.3