diff options
author | Chuck Miller <shadowmil@gmail.com> | 2010-07-12 21:45:50 -0400 |
---|---|---|
committer | Chuck Miller <shadowmil@gmail.com> | 2010-07-13 17:31:00 -0400 |
commit | 7ae52ac5392607f5cb56dffa9ae45ae5a2f14bd1 (patch) | |
tree | d07c53931d0fe987caa19378c9ed14d381749736 /src/eventmanager.cpp | |
parent | c8aa6f18406459426fe0914d23181eb1e61f0137 (diff) | |
download | Mana-7ae52ac5392607f5cb56dffa9ae45ae5a2f14bd1.tar.gz Mana-7ae52ac5392607f5cb56dffa9ae45ae5a2f14bd1.tar.bz2 Mana-7ae52ac5392607f5cb56dffa9ae45ae5a2f14bd1.tar.xz Mana-7ae52ac5392607f5cb56dffa9ae45ae5a2f14bd1.zip |
Add the foundation for the event system
Diffstat (limited to 'src/eventmanager.cpp')
-rw-r--r-- | src/eventmanager.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/eventmanager.cpp b/src/eventmanager.cpp new file mode 100644 index 00000000..ec589bbf --- /dev/null +++ b/src/eventmanager.cpp @@ -0,0 +1,67 @@ +/* + * The Mana Client + * Copyright (C) 2010 The Mana Developers + * + * This file is part of The Mana Client. + * + * 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 + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "eventmanager.h" + +#include "listener.h" + +namespace Mana +{ + +ListenMap EventManager::mBindings; + +void EventManager::trigger(const std::string &channel, const Event &event) +{ + ListenMap::iterator it = mBindings.find(channel); + + // Make sure something is listening + if (it == mBindings.end()) + return; + + // Loop though all listeners + ListenerSet::iterator lit = it->second.begin(); + while (lit != it->second.end()) + { + (*lit)->event(channel, event); + lit++; + } +} + +void EventManager::remove(Listener *listener) +{ + ListenMap::iterator it = mBindings.begin(); + while (it != mBindings.end()) + { + it->second.erase(listener); + it++; + } +} + +void EventManager::bind(Listener *listener, const std::string &channel) +{ + mBindings[channel].insert(listener); +} + +void EventManager::unbind(Listener *listener, const std::string &channel) +{ + mBindings[channel].erase(listener); +} + +}; // namespace Mana |