X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fevent_manager.h;h=f64d05869ab80dfabb93e0cc0e3888abc86a3668;hb=90e7d42375918636bf65fd6273675a576530778d;hp=9492a2fd978281d047921f5d3d3f4c95885a9069;hpb=04085cad3cc154a48c72127ef816bf25ca636f74;p=dragonfireclient.git diff --git a/src/event_manager.h b/src/event_manager.h index 9492a2fd9..f64d05869 100644 --- a/src/event_manager.h +++ b/src/event_manager.h @@ -1,24 +1,23 @@ /* -Minetest-c55 -Copyright (C) 2012 celeron55, Perttu Ahola +Minetest +Copyright (C) 2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef EVENT_MANAGER_HEADER -#define EVENT_MANAGER_HEADER +#pragma once #include "event.h" #include @@ -44,17 +43,15 @@ class EventManager: public MtEventManager std::map m_dest; public: - ~EventManager() - { - } + ~EventManager() = default; + void put(MtEvent *e) { std::map::iterator i = m_dest.find(e->getType()); if(i != m_dest.end()){ std::list &funcs = i->second.funcs; - for(std::list::iterator i = funcs.begin(); - i != funcs.end(); i++){ - (*(i->f))(e, i->d); + for (FuncSpec &func : funcs) { + (*(func.f))(e, func.d); } } delete e; @@ -63,11 +60,11 @@ class EventManager: public MtEventManager { std::map::iterator i = m_dest.find(type); if(i != m_dest.end()){ - i->second.funcs.push_back(FuncSpec(f, data)); + i->second.funcs.emplace_back(f, data); } else{ std::list funcs; Dest dest; - dest.funcs.push_back(FuncSpec(f, data)); + dest.funcs.emplace_back(f, data); m_dest[type] = dest; } } @@ -83,20 +80,19 @@ class EventManager: public MtEventManager if(remove) funcs.erase(j++); else - j++; + ++j; } } } else{ - for(std::map::iterator - i = m_dest.begin(); i != m_dest.end(); i++){ - std::list &funcs = i->second.funcs; + for (auto &dest : m_dest) { + std::list &funcs = dest.second.funcs; std::list::iterator j = funcs.begin(); while(j != funcs.end()){ bool remove = (j->f == f && (!data || j->d == data)); if(remove) funcs.erase(j++); else - j++; + ++j; } } } @@ -110,6 +106,3 @@ class EventManager: public MtEventManager dereg(type, EventManager::receiverReceive, r); } }; - -#endif -