Crazy Eddies GUI System  0.7.0
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_