Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Event.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 - 2010 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 "CEGUI/String.h"
32 #include "CEGUI/BoundSlot.h"
33 #include "CEGUI/SubscriberSlot.h"
34 #include "CEGUI/RefCounted.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  public AllocatedObject<Event>
60 {
61 public:
70 
78 
85  typedef unsigned int Group;
86 
93  {
94  public:
95  ScopedConnection() {}
96 
98  {
99  disconnect();
100  }
101 
102  ScopedConnection(const Event::Connection& connection) :
103  d_connection(connection)
104  {}
105 
106  ScopedConnection& operator=(const Event::Connection& connection)
107  {
108  d_connection = connection;
109  return *this;
110  }
111 
112  bool connected() const
113  {
114  return d_connection.isValid() ? d_connection->connected() : false;
115  }
116 
117  void disconnect()
118  {
119  if (d_connection.isValid()) d_connection->disconnect();
120  }
121 
122  private:
123  Event::Connection d_connection;
124  };
125 
130  Event(const String& name);
131 
137  virtual ~Event();
138 
146  const String& getName(void) const
147  {
148  return d_name;
149  }
150 
165  Connection subscribe(const Subscriber& slot);
166 
186  Connection subscribe(Group group, const Subscriber& slot);
187 
201  void operator()(EventArgs& args);
202 
203 
204 protected:
205  friend void CEGUI::BoundSlot::disconnect();
216  void unsubscribe(const BoundSlot& slot);
217 
218  // Copy constructor and assignment are not allowed for events
219  Event(const Event&) {}
220  Event& operator=(const Event&)
221  {
222  return *this;
223  }
224 
225  typedef std::multimap<Group, Connection, std::less<Group>
226  CEGUI_MULTIMAP_ALLOC(Group, Connection)> SlotContainer;
227  SlotContainer d_slots;
228  const String d_name;
229 };
230 
231 } // End of CEGUI namespace section
232 
233 #if defined(_MSC_VER)
234 # pragma warning(pop)
235 #endif
236 
237 #endif // end of guard _CEGUIEvent_h_
238