diff options
Diffstat (limited to 'src/event.cpp')
-rw-r--r-- | src/event.cpp | 40 |
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 |