ifw  0.0.1-dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dispatcher.hpp
Go to the documentation of this file.
1 
9 #ifndef RAD_DISPATCHER_HPP
10 #define RAD_DISPATCHER_HPP
11 
12 #include <unordered_map>
13 #include <functional>
14 
15 #include <rad/AnyEvent.hpp>
16 
17 namespace rad {
18 
22 class Dispatcher {
23 public:
24  using handler_t = std::function<void(AnyEvent const&)>;
25  using token_t = std::unordered_multimap<std::string, handler_t>::iterator;
26 
33  Dispatcher() = default;
34 
41  token_t registerHandler(char const* eventId, handler_t handler);
42 
47  void unregisterHandler(token_t token);
48 
56  void dispatch(AnyEvent const& e) const;
57 
58 private:
59  std::unordered_multimap<std::string, handler_t> m_handlers;
60 };
61 
62 } // namespace rad
63 
64 #endif
Dispatcher()=default
std::unordered_multimap< std::string, handler_t >::iterator token_t
Definition: Dispatcher.hpp:25
Definition: Dispatcher.hpp:22
void unregisterHandler(token_t token)
Definition: Dispatcher.cpp:18
Definition: AnyEvent.hpp:55
void dispatch(AnyEvent const &e) const
Definition: Dispatcher.cpp:24
def handler
Definition: test_dispatcher.py:11
std::function< void(AnyEvent const &)> handler_t
Definition: Dispatcher.hpp:24
token_t registerHandler(char const *eventId, handler_t handler)
Definition: Dispatcher.cpp:12