EventSystem.hpp
Go to the documentation of this file.
1 //
3 // Thor C++ Library
4 // Copyright (c) 2011-2015 Jan Haller
5 //
6 // This software is provided 'as-is', without any express or implied
7 // warranty. In no event will the authors be held liable for any damages
8 // arising from the use of this software.
9 //
10 // Permission is granted to anyone to use this software for any purpose,
11 // including commercial applications, and to alter it and redistribute it
12 // freely, subject to the following restrictions:
13 //
14 // 1. The origin of this software must not be misrepresented; you must not
15 // claim that you wrote the original software. If you use this software
16 // in a product, an acknowledgment in the product documentation would be
17 // appreciated but is not required.
18 //
19 // 2. Altered source versions must be plainly marked as such, and must not be
20 // misrepresented as being the original software.
21 //
22 // 3. This notice may not be removed or altered from any source distribution.
23 //
25 
28 
29 #ifndef THOR_EVENTSYSTEM_HPP
30 #define THOR_EVENTSYSTEM_HPP
31 
32 #include <Thor/Input/Detail/EventListener.hpp>
33 
34 #include <Aurora/Tools/NonCopyable.hpp>
35 
36 
37 namespace thor
38 {
39 
42 
50 template <typename Event, typename EventId = Event>
51 class EventSystem : private aurora::NonCopyable
52 {
53  // ---------------------------------------------------------------------------------------------------------------------------
54  // Public member functions
55  public:
58  EventSystem();
59 
62  void triggerEvent(const Event& event);
63 
73  Connection connect(const EventId& trigger, std::function<void(const Event&)> unaryListener);
74 
84  Connection connect0(const EventId& trigger, std::function<void()> nullaryListener);
85 
88  void clearConnections(EventId identifier);
89 
92  void clearAllConnections();
93 
94 
95  // ---------------------------------------------------------------------------------------------------------------------------
96  // Private types
97  private:
98  // Container type
99  typedef detail::ListenerMap<EventId, const Event&> EventListenerMap;
100 
101 
102  // ---------------------------------------------------------------------------------------------------------------------------
103  // Private variables
104  private:
105  EventListenerMap mListeners;
106 };
107 
109 
110 } // namespace thor
111 
112 #include <Thor/Input/Detail/EventSystem.inl>
113 #endif // THOR_EVENTSYSTEM_HPP
void clearAllConnections()
Disconnects all listeners.
Connection connect0(const EventId &trigger, std::function< void()> nullaryListener)
Connects an event to the specified nullary listener.
Definition: Animator.hpp:42
Connection connect(const EventId &trigger, std::function< void(const Event &)> unaryListener)
Connects an event to the specified unary listener.
void clearConnections(EventId identifier)
Disconnects listeners associated with a given event type.
void triggerEvent(const Event &event)
Fires an event.
EventSystem()
Default constructor.