Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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 
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