3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef EVENT_MANAGER_HEADER
21 #define EVENT_MANAGER_HEADER
27 class EventManager: public MtEventManager
29 static void receiverReceive(MtEvent *e, void *data)
31 MtEventReceiver *r = (MtEventReceiver*)data;
37 FuncSpec(event_receive_func f, void *d):
42 std::list<FuncSpec> funcs;
44 std::map<std::string, Dest> m_dest;
52 std::map<std::string, Dest>::iterator i = m_dest.find(e->getType());
53 if(i != m_dest.end()){
54 std::list<FuncSpec> &funcs = i->second.funcs;
55 for(std::list<FuncSpec>::iterator i = funcs.begin();
56 i != funcs.end(); i++){
62 void reg(const char *type, event_receive_func f, void *data)
64 std::map<std::string, Dest>::iterator i = m_dest.find(type);
65 if(i != m_dest.end()){
66 i->second.funcs.push_back(FuncSpec(f, data));
68 std::list<FuncSpec> funcs;
70 dest.funcs.push_back(FuncSpec(f, data));
74 void dereg(const char *type, event_receive_func f, void *data)
77 std::map<std::string, Dest>::iterator i = m_dest.find(type);
78 if(i != m_dest.end()){
79 std::list<FuncSpec> &funcs = i->second.funcs;
80 std::list<FuncSpec>::iterator j = funcs.begin();
81 while(j != funcs.end()){
82 bool remove = (j->f == f && (!data || j->d == data));
90 for(std::map<std::string, Dest>::iterator
91 i = m_dest.begin(); i != m_dest.end(); i++){
92 std::list<FuncSpec> &funcs = i->second.funcs;
93 std::list<FuncSpec>::iterator j = funcs.begin();
94 while(j != funcs.end()){
95 bool remove = (j->f == f && (!data || j->d == data));
104 void reg(MtEventReceiver *r, const char *type)
106 reg(type, EventManager::receiverReceive, r);
108 void dereg(MtEventReceiver *r, const char *type)
110 dereg(type, EventManager::receiverReceive, r);