From 496c337cdfa593654018c171f6a74c28272265b5 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 1 Sep 2017 12:04:50 +0100 Subject: Replace ItemCallbacks with lambdas (#3948) --- src/UI/Window.cpp | 14 +++++++------- src/UI/Window.h | 10 ++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/UI') diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index 8bbc4f482..9fbc4d988 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -1,4 +1,4 @@ -#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Window.h" #include "WindowOwner.h" @@ -362,12 +362,12 @@ void cWindow::OwnerDestroyed() -bool cWindow::ForEachPlayer(cItemCallback & a_Callback) +bool cWindow::ForEachPlayer(const cPlayerListCallback & a_Callback) { cCSLock Lock(m_CS); - for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) + for (auto & Player : m_OpenedBy) { - if (a_Callback.Item(*itr)) + if (a_Callback(*Player)) { return false; } @@ -379,12 +379,12 @@ bool cWindow::ForEachPlayer(cItemCallback & a_Callback) -bool cWindow::ForEachClient(cItemCallback & a_Callback) +bool cWindow::ForEachClient(cClientHandleCallback & a_Callback) { cCSLock Lock(m_CS); - for (cPlayerList::iterator itr = m_OpenedBy.begin(), end = m_OpenedBy.end(); itr != end; ++itr) + for (auto & Player : m_OpenedBy) { - if (a_Callback.Item((*itr)->GetClientHandle())) + if (a_Callback(*Player->GetClientHandle())) { return false; } diff --git a/src/UI/Window.h b/src/UI/Window.h index d7a29dc47..f2023c731 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -1,4 +1,4 @@ - + // Window.h // Interfaces to the cWindow class representing a UI window for a specific block @@ -9,6 +9,7 @@ #pragma once +#include #include "../ItemGrid.h" @@ -31,7 +32,8 @@ class cWorld; typedef std::list cPlayerList; typedef std::vector cSlotAreas; - +using cPlayerListCallback = std::function; +using cClientHandleCallback = std::function; @@ -151,10 +153,10 @@ public: void OwnerDestroyed(void); /** Calls the callback safely for each player that has this window open; returns true if all players have been enumerated */ - bool ForEachPlayer(cItemCallback & a_Callback); + bool ForEachPlayer(const cPlayerListCallback & a_Callback); /** Calls the callback safely for each client that has this window open; returns true if all clients have been enumerated */ - bool ForEachClient(cItemCallback & a_Callback); + bool ForEachClient(cClientHandleCallback & a_Callback); /** Called on shift-clicking to distribute the stack into other areas; Modifies a_ItemStack as it is distributed! if a_ShouldApply is true, the changes are written into the slots; -- cgit v1.2.3