summaryrefslogtreecommitdiff
path: root/src/event.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2010-08-12 21:47:59 -0600
committerJared Adams <jaxad0127@gmail.com>2010-08-12 22:01:57 -0600
commiteb2c0cae1cb7a02b72c15de0f4e8f4a68a9fa53a (patch)
tree8b1fab9acbd0eb568d7f7e0b31f8fd4ac02b18a4 /src/event.cpp
parent2293b1c5ef0bb7378140bf73f1fef03a4504bdd2 (diff)
downloadmana-eb2c0cae1cb7a02b72c15de0f4e8f4a68a9fa53a.tar.gz
mana-eb2c0cae1cb7a02b72c15de0f4e8f4a68a9fa53a.tar.bz2
mana-eb2c0cae1cb7a02b72c15de0f4e8f4a68a9fa53a.tar.xz
mana-eb2c0cae1cb7a02b72c15de0f4e8f4a68a9fa53a.zip
Simplify working with the event system
EventManager has been merged into Event, with some new convinience methods added. Reviewed-by: Chuck Miller
Diffstat (limited to 'src/event.cpp')
-rw-r--r--src/event.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/event.cpp b/src/event.cpp
index dde04920..38213cd2 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -20,11 +20,14 @@
#include "event.h"
+#include "listener.h"
#include "variabledata.h"
namespace Mana
{
+ListenMap Event::mBindings;
+
Event::~Event()
{
VariableMap::iterator it = mData.begin();
@@ -144,4 +147,41 @@ bool Event::hasBool(const std::string &key) const
|| it->second->getType() != VariableData::DATA_BOOL);
}
+void Event::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 Event::bind(Listener *listener, const std::string &channel)
+{
+ mBindings[channel].insert(listener);
+}
+
+void Event::unbind(Listener *listener, const std::string &channel)
+{
+ mBindings[channel].erase(listener);
+}
+
+void Event::remove(Listener *listener)
+{
+ ListenMap::iterator it = mBindings.begin();
+ while (it != mBindings.end())
+ {
+ it->second.erase(listener);
+ it++;
+ }
+}
+
} // namespace Mana