From db486eae2e0743677a3849f858198a20b984d0a1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 11 Nov 2022 00:32:26 +0100 Subject: [PATCH] Replace StateEventProcessor used in wxWebRequest code with lambda No real changes, just simplify the code now that we can use C++11. This commit is best viewed with Git --color-moved option. --- include/wx/private/webrequest.h | 17 ++++++++--------- src/common/webrequest.cpp | 27 ++++----------------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/include/wx/private/webrequest.h b/include/wx/private/webrequest.h index 4f502b9af5..88f2ed1fef 100644 --- a/include/wx/private/webrequest.h +++ b/include/wx/private/webrequest.h @@ -106,15 +106,6 @@ public: wxEvtHandler* GetHandler() const { return m_handler; } - // Called to notify about the state change in the main thread by SetState() - // (which can itself be called from a different one). - // - // It also releases a reference added when switching to the active state by - // SetState() when leaving it. - // - // TODO-C++11: make private when we don't need StateEventProcessor any more. - void ProcessStateEvent(wxWebRequest::State state, const wxString& failMsg); - protected: wxString m_method; wxWebRequest::Storage m_storage; @@ -138,6 +129,14 @@ private: // Called from public Cancel() at most once per object. virtual void DoCancel() = 0; + // Called to notify about the state change in the main thread by SetState() + // (which can itself be called from a different one). + // + // It also releases a reference added when switching to the active state by + // SetState() when leaving it. + void ProcessStateEvent(wxWebRequest::State state, const wxString& failMsg); + + wxWebSession& m_session; wxEvtHandler* const m_handler; const int m_id; diff --git a/src/common/webrequest.cpp b/src/common/webrequest.cpp index ef54507f80..ccb1c22dd7 100644 --- a/src/common/webrequest.cpp +++ b/src/common/webrequest.cpp @@ -165,28 +165,6 @@ wxFileOffset wxWebRequestImpl::GetBytesExpectedToReceive() const namespace { -// Functor used with CallAfter() below. -// -// TODO-C++11: Replace with a lambda. -struct StateEventProcessor -{ - StateEventProcessor(wxWebRequestImpl& request, - wxWebRequest::State state, - const wxString& failMsg) - : m_request(request), m_state(state), m_failMsg(failMsg) - { - } - - void operator()() - { - m_request.ProcessStateEvent(m_state, m_failMsg); - } - - wxWebRequestImpl& m_request; - const wxWebRequest::State m_state; - const wxString m_failMsg; -}; - #if wxUSE_LOG_TRACE // Tiny helper to log states as strings rather than meaningless numbers. @@ -242,7 +220,10 @@ void wxWebRequestImpl::SetState(wxWebRequest::State state, const wxString & fail } else { - m_handler->CallAfter(StateEventProcessor(*this, state, failMsg)); + m_handler->CallAfter([this, state, failMsg]() + { + ProcessStateEvent(state, failMsg); + }); } }