Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions include/EventEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>
#include <typeinfo>
#include <typeindex>
#include <string>

namespace medooze
{
Expand Down Expand Up @@ -48,19 +49,19 @@ class EventEmitter
template<typename Type>
void emit(Type& type)
{
auto it = listeners.find(typeid(type));
auto it = listeners.find(typeid(Type).name());
if (it!=listeners.end())
static_cast<Listener<Type>*>(it->second.get())->emit(type);
}

template<typename Type>
EventEmitter& on(const std::function<void (Type&)> &callback)
{
listeners[typeid(Type)] = std::unique_ptr<BaseListener>(new Listener<Type>(callback));
listeners[typeid(Type).name()] = std::unique_ptr<BaseListener>(new Listener<Type>(callback));
return *this;
}
private:
std::map<std::type_index,std::unique_ptr<BaseListener>> listeners;
std::map<std::string,std::unique_ptr<BaseListener>> listeners;
};

}; // namespace medooze
Expand Down