Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CEGUIEvent.h
1 /************************************************************************
2  filename: CEGUIEvent.h
3  created: Tue Feb 28 2006
4  author: Paul D Turner <paul@cegui.org.uk>
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIEvent_h_
29 #define _CEGUIEvent_h_
30 
31 #include "CEGUIString.h"
32 #include "CEGUIBoundSlot.h"
33 #include "CEGUISubscriberSlot.h"
34 #include "CEGUIRefCounted.h"
35 
36 #include <map>
37 
38 #if defined(_MSC_VER)
39 # pragma warning(push)
40 # pragma warning(disable : 4251)
41 #endif
42 
43 // Start of CEGUI namespace section
44 namespace CEGUI
45 {
58 class CEGUIEXPORT Event
59 {
60 public:
69 
77 
84  typedef unsigned int Group;
85 
92  {
93  public:
94  ScopedConnection() {}
95 
97  { disconnect(); }
98 
99  ScopedConnection(const Event::Connection& connection) :
100  d_connection(connection)
101  {}
102 
103  ScopedConnection& operator=(const Event::Connection& connection)
104  {
105  d_connection = connection;
106  return *this;
107  }
108 
109  bool connected() const
110  { return d_connection.isValid() ? d_connection->connected() : false; }
111 
112  void disconnect()
113  { if (d_connection.isValid()) d_connection->disconnect(); }
114 
115  private:
116  Event::Connection d_connection;
117  };
118 
123  Event(const String& name);
124 
130  ~Event();
131 
139  const String& getName(void) const
140  { return d_name; }
141 
156  Connection subscribe(const Subscriber& slot);
157 
177  Connection subscribe(Group group, const Subscriber& slot);
178 
192  void operator()(EventArgs& args);
193 
194 
195 private:
196  friend void CEGUI::BoundSlot::disconnect();
207  void unsubscribe(const BoundSlot& slot);
208 
209  // Copy constructor and assignment are not allowed for events
210  Event(const Event&) {}
211  Event& operator=(const Event&) {return *this;}
212 
213  typedef std::multimap<Group, Connection> SlotContainer;
214  SlotContainer d_slots;
215  const String d_name;
216 };
217 
218 } // End of CEGUI namespace section
219 
220 #if defined(_MSC_VER)
221 # pragma warning(pop)
222 #endif
223 
224 #endif // end of guard _CEGUIEvent_h_
const String & getName(void) const
Return the name given to this Event object when it was created.
Definition: CEGUIEvent.h:139
Event::Connection wrapper that automatically disconnects the connection when the object is deleted (o...
Definition: CEGUIEvent.h:91
Base class used as the argument to all subscribers Event object.
Definition: CEGUIEventArgs.h:52
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: CEGUIBoundSlot.h:45
SubscriberSlot class which is used when subscribing to events.
Definition: CEGUISubscriberSlot.h:52
CEGUI::SubscriberSlot Subscriber
Subscriber object type. This is now just a typedef to SubscriberSlot, the use of the name Event::Subs...
Definition: CEGUIEvent.h:76
RefCounted< BoundSlot > Connection
Connection object. This is a thin &#39;smart pointer&#39; wrapper around the actual BoundSlot that represents...
Definition: CEGUIEvent.h:68
Defines an &#39;event&#39; which can be subscribed to by interested parties.
Definition: CEGUIEvent.h:58
unsigned int Group
Type for a subscriber group. You can use the subscriber group to order calls to multiple subscribers...
Definition: CEGUIEvent.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: CEGUIString.h:57
bool isValid() const
Return whether the wrapped pointer is valid. i.e. that it is not null.
Definition: CEGUIRefCounted.h:162