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
43 namespace CEGUI
44 {
57 class CEGUIEXPORT Event :
58  public AllocatedObject<Event>
59 {
60 public:
69 
77 
84  typedef unsigned int Group;
85 
91  class ScopedConnection : public Connection
92  {
93  public:
94  ScopedConnection() {}
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 
164  Connection subscribe(const Subscriber& slot);
165 
185  Connection subscribe(Group group, const Subscriber& slot);
186 
200  void operator()(EventArgs& args);
201 
202 
203 protected:
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;
227  const String d_name;
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 
const String & getName(void) const
Return the name given to this Event object when it was created.
Definition: Event.h:145
SlotContainer d_slots
Collection holding ref-counted bound slots.
Definition: Event.h:226
Definition: MemoryAllocatedObject.h:109
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1
Event::Connection wrapper that automatically disconnects the connection when the object is deleted (o...
Definition: Event.h:91
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:49
Class that tracks a SubscriberSlot, its group, and the Event to which it was subscribed. This is effectively what gets returned from the calls to the Event::subscribe members, though BoundSlot is always wrapped in a reference counted pointer. When a BoundSlot is deleted, the connection is unsubscribed and the SubscriberSlot is deleted.
Definition: BoundSlot.h:44
SubscriberSlot class which is used when subscribing to events.
Definition: SubscriberSlot.h:51
const String d_name
Name of this event.
Definition: Event.h:227
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
RefCounted< BoundSlot > Connection
Connection object. This is a thin 'smart pointer' wrapper around the actual BoundSlot that represents...
Definition: Event.h:68
Defines an 'event' which can be subscribed to by interested parties.
Definition: Event.h:57
unsigned int Group
Type for a subscriber group. You can use the subscriber group to order calls to multiple subscribers...
Definition: Event.h:84
void disconnect()
Disconnects the slot. Once disconnected, the slot will no longer be called when the associated signal...
String class used within the GUI system.
Definition: String.h:62
bool isValid() const
Return whether the wrapped pointer is valid. i.e. that it is not null.
Definition: RefCounted.h:165