Crazy Eddie's GUI System 0.8.7
Event.h
1/************************************************************************
2 created: Tue Feb 28 2006
3 author: Paul D Turner <paul@cegui.org.uk>
4*************************************************************************/
5/***************************************************************************
6 * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 ***************************************************************************/
27#ifndef _CEGUIEvent_h_
28#define _CEGUIEvent_h_
29
30#include "CEGUI/String.h"
31#include "CEGUI/BoundSlot.h"
32#include "CEGUI/SubscriberSlot.h"
33#include "CEGUI/RefCounted.h"
34
35#include <map>
36
37#if defined(_MSC_VER)
38# pragma warning(push)
39# pragma warning(disable : 4251)
40#endif
41
42// Start of CEGUI namespace section
43namespace CEGUI
44{
57class CEGUIEXPORT Event :
58 public AllocatedObject<Event>
59{
60public:
69
77
84 typedef unsigned int Group;
85
92 {
93 public:
95
97 {
98 disconnect();
99 }
100
101 ScopedConnection(const Event::Connection& connection) :
102 d_connection(connection)
103 {}
104
105 ScopedConnection& operator=(const Event::Connection& connection)
106 {
107 d_connection = connection;
108 return *this;
109 }
110
111 bool connected() const
112 {
113 return d_connection.isValid() ? d_connection->connected() : false;
114 }
115
116 void disconnect()
117 {
118 if (d_connection.isValid()) d_connection->disconnect();
119 }
120
121 private:
122 Event::Connection d_connection;
123 };
124
129 Event(const String& name);
130
136 virtual ~Event();
137
145 const String& getName(void) const
146 {
147 return d_name;
148 }
149
165
186
201
202
203protected:
204 friend void CEGUI::BoundSlot::disconnect();
215 void unsubscribe(const BoundSlot& slot);
216
217 // Copy constructor and assignment are not allowed for events
218 Event(const Event&) {}
219 Event& operator=(const Event&)
220 {
221 return *this;
222 }
223
224 typedef std::multimap<Group, Connection, std::less<Group>
225 CEGUI_MULTIMAP_ALLOC(Group, Connection)> SlotContainer;
226 SlotContainer d_slots;
228};
229
230} // End of CEGUI namespace section
231
232#if defined(_MSC_VER)
233# pragma warning(pop)
234#endif
235
236#endif // end of guard _CEGUIEvent_h_
237
Definition: MemoryAllocatedObject.h:110
Class that tracks a SubscriberSlot, its group, and the Event to which it was subscribed....
Definition: BoundSlot.h:46
void disconnect()
Disconnects the slot. Once disconnected, the slot will no longer be called when the associated signal...
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:51
Event::Connection wrapper that automatically disconnects the connection when the object is deleted (o...
Definition: Event.h:92
Defines an 'event' which can be subscribed to by interested parties.
Definition: Event.h:59
virtual ~Event()
Destructor for Event objects. Note that this is non-virtual and so you should not sub-class Event.
CEGUI::SubscriberSlot Subscriber
Subscriber object type. This is now just a typedef to SubscriberSlot, the use of the name Event::Subs...
Definition: Event.h:76
void operator()(EventArgs &args)
Fires the event. All event subscribers get called in the appropriate sequence.
SlotContainer d_slots
Collection holding ref-counted bound slots.
Definition: Event.h:226
const String & getName(void) const
Return the name given to this Event object when it was created.
Definition: Event.h:145
const String d_name
Name of this event.
Definition: Event.h:227
RefCounted< BoundSlot > Connection
Connection object. This is a thin 'smart pointer' wrapper around the actual BoundSlot that represents...
Definition: Event.h:68
void unsubscribe(const BoundSlot &slot)
Disconnects and removes the given BoundSlot from the collection of bound slots attached to this Event...
Connection subscribe(Group group, const Subscriber &slot)
Subscribes some function or object to the Event.
Event(const String &name)
Constructs a new Event object with the specified name.
Connection subscribe(const Subscriber &slot)
Subscribes some function or object to the Event.
unsigned int Group
Type for a subscriber group. You can use the subscriber group to order calls to multiple subscribers....
Definition: Event.h:84
bool isValid() const
Return whether the wrapped pointer is valid. i.e. that it is not null.
Definition: RefCounted.h:165
String class used within the GUI system.
Definition: String.h:64
SubscriberSlot class which is used when subscribing to events.
Definition: SubscriberSlot.h:53
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1