From 73df5edac616ab2ee7ba7ef5c41728eda4c0ea49d9665c8833eac358be21f033 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 9 Aug 2025 11:30:10 -0400 Subject: [PATCH] Another `List` bites the dust... --- dw/fltkplatform.cc | 32 ++++++++++---------------------- dw/fltkplatform.hh | 2 +- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/dw/fltkplatform.cc b/dw/fltkplatform.cc index d532c7d..8411ab0 100644 --- a/dw/fltkplatform.cc +++ b/dw/fltkplatform.cc @@ -453,7 +453,6 @@ FltkPlatform::FltkPlatform () DBG_OBJ_CREATE ("dw::fltk::FltkPlatform"); layout = NULL; - idleQueue = new container::typed::List (true); idleFuncRunning = false; idleFuncId = 0; @@ -467,7 +466,6 @@ FltkPlatform::~FltkPlatform () { if (idleFuncRunning) Fl::remove_idle (generalStaticIdle, (void*)this); - delete idleQueue; delete resources; DBG_OBJ_DELETE (); @@ -623,18 +621,16 @@ void FltkPlatform::generalStaticIdle (void *data) void FltkPlatform::generalIdle () { - IdleFunc *idleFunc; - - if (!idleQueue->isEmpty ()) { + if (!idleQueue.empty ()) { /* Execute the first function in the list. */ - idleFunc = idleQueue->getFirst (); + auto &idleFunc = idleQueue.front(); (layout->*(idleFunc->func)) (); /* Remove this function. */ - idleQueue->removeRef(idleFunc); + idleQueue.remove(idleFunc); } - if (idleQueue->isEmpty()) { + if (idleQueue.empty()) { idleFuncRunning = false; Fl::remove_idle (generalStaticIdle, (void*)this); } @@ -656,29 +652,21 @@ int FltkPlatform::addIdle (void (core::Layout::*func) ()) idleFuncId++; - IdleFunc *idleFunc = new IdleFunc(); + auto idleFunc = std::make_unique< IdleFunc >(); idleFunc->id = idleFuncId; idleFunc->func = func; - idleQueue->append (idleFunc); + idleQueue.push_back( std::move( idleFunc ) ); return idleFuncId; } void FltkPlatform::removeIdle (int idleId) { - bool found; - container::typed::Iterator it; - IdleFunc *idleFunc; + const auto found= std::find_if( begin( idleQueue ), end( idleQueue ), + [&]( const auto &idleFunc ) { return idleFunc->id == idleId; } ); + if( found != end( idleQueue ) ) idleQueue.erase( found ); - for (found = false, it = idleQueue->iterator(); !found && it.hasNext(); ) { - idleFunc = it.getNext(); - if (idleFunc->id == idleId) { - idleQueue->removeRef (idleFunc); - found = true; - } - } - - if (idleFuncRunning && idleQueue->isEmpty()) + if (idleFuncRunning && idleQueue.empty()) Fl::remove_idle (generalStaticIdle, (void*)this); } diff --git a/dw/fltkplatform.hh b/dw/fltkplatform.hh index 0e79031..7b984b2 100644 --- a/dw/fltkplatform.hh +++ b/dw/fltkplatform.hh @@ -133,7 +133,7 @@ private: core::Layout *layout; - lout::container::typed::List *idleQueue; + std::list< std::unique_ptr< IdleFunc > > idleQueue; bool idleFuncRunning; int idleFuncId;