From bc3fe4851905039396e4de675e7f2eaee89ccb6d Mon Sep 17 00:00:00 2001 From: Dmitry Fleytman Date: Thu, 6 Mar 2014 11:23:54 +0200 Subject: [PATCH] UsbDk: Make lists return indication of whether iteration was stopped Signed-off-by: Dmitry Fleytman --- UsbDk/UsbDkUtil.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/UsbDk/UsbDkUtil.h b/UsbDk/UsbDkUtil.h index 19090c6..02d6b01 100644 --- a/UsbDk/UsbDkUtil.h +++ b/UsbDk/UsbDkUtil.h @@ -123,39 +123,40 @@ public: } template - void ForEachDetached(TFunctor Functor) + bool ForEachDetached(TFunctor Functor) { CLockedContext LockedContext(*this); while (!IsListEmpty(&m_List)) { if (!Functor(Pop_LockLess())) { - return; + return false; } } + return true; } template - void ForEachDetachedIf(TPredicate Predicate, TFunctor Functor) + bool ForEachDetachedIf(TPredicate Predicate, TFunctor Functor) { - ForEachPrepareIf(Predicate, [](PLIST_ENTRY Entry){ RemoveEntryList(Entry); }, Functor); + return ForEachPrepareIf(Predicate, [](PLIST_ENTRY Entry){ RemoveEntryList(Entry); }, Functor); } template - void ForEach(TFunctor Functor) + bool ForEach(TFunctor Functor) { - ForEachPrepareIf([](TEntryType*) { return true; }, [](PLIST_ENTRY){}, Functor); + return ForEachPrepareIf([](TEntryType*) { return true; }, [](PLIST_ENTRY){}, Functor); } template - void ForEachIf(TPredicate Predicate, TFunctor Functor) + bool ForEachIf(TPredicate Predicate, TFunctor Functor) { - ForEachPrepareIf(Predicate, [](PLIST_ENTRY){}, Functor); + return ForEachPrepareIf(Predicate, [](PLIST_ENTRY){}, Functor); } private: template - void ForEachPrepareIf(TPredicate Predicate, TPrepareFunctor Prepare, TFunctor Functor) + bool ForEachPrepareIf(TPredicate Predicate, TPrepareFunctor Prepare, TFunctor Functor) { CLockedContext LockedContext(*this); @@ -171,10 +172,12 @@ private: Prepare(CurrEntry); if (!Functor(Object)) { - return; + return false; } } } + + return true; } TEntryType *Pop_LockLess()