]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/event_manager.h
Don't try to craft a non-existent item
[dragonfireclient.git] / src / event_manager.h
index 9492a2fd978281d047921f5d3d3f4c95885a9069..f64d05869ab80dfabb93e0cc0e3888abc86a3668 100644 (file)
@@ -1,24 +1,23 @@
 /*
-Minetest-c55
-Copyright (C) 2012 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
 
 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 <list>
@@ -44,17 +43,15 @@ class EventManager: public MtEventManager
        std::map<std::string, Dest> m_dest;
 
 public:
-       ~EventManager()
-       {
-       }
+       ~EventManager() = default;
+
        void put(MtEvent *e)
        {
                std::map<std::string, Dest>::iterator i = m_dest.find(e->getType());
                if(i != m_dest.end()){
                        std::list<FuncSpec> &funcs = i->second.funcs;
-                       for(std::list<FuncSpec>::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<std::string, Dest>::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<FuncSpec> 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<std::string, Dest>::iterator
-                                       i = m_dest.begin(); i != m_dest.end(); i++){
-                               std::list<FuncSpec> &funcs = i->second.funcs;
+                       for (auto &dest : m_dest) {
+                               std::list<FuncSpec> &funcs = dest.second.funcs;
                                std::list<FuncSpec>::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
-