Crazy Eddie's GUI System
0.8.4
|
00001 /************************************************************************ 00002 created: Tue Feb 28 2006 00003 author: Paul D Turner <paul@cegui.org.uk> 00004 *************************************************************************/ 00005 /*************************************************************************** 00006 * Copyright (C) 2004 - 2010 Paul D Turner & The CEGUI Development Team 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining 00009 * a copy of this software and associated documentation files (the 00010 * "Software"), to deal in the Software without restriction, including 00011 * without limitation the rights to use, copy, modify, merge, publish, 00012 * distribute, sublicense, and/or sell copies of the Software, and to 00013 * permit persons to whom the Software is furnished to do so, subject to 00014 * the following conditions: 00015 * 00016 * The above copyright notice and this permission notice shall be 00017 * included in all copies or substantial portions of the Software. 00018 * 00019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00020 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00022 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00023 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00024 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00025 * OTHER DEALINGS IN THE SOFTWARE. 00026 ***************************************************************************/ 00027 #ifndef _CEGUIEvent_h_ 00028 #define _CEGUIEvent_h_ 00029 00030 #include "CEGUI/String.h" 00031 #include "CEGUI/BoundSlot.h" 00032 #include "CEGUI/SubscriberSlot.h" 00033 #include "CEGUI/RefCounted.h" 00034 00035 #include <map> 00036 00037 #if defined(_MSC_VER) 00038 # pragma warning(push) 00039 # pragma warning(disable : 4251) 00040 #endif 00041 00042 // Start of CEGUI namespace section 00043 namespace CEGUI 00044 { 00057 class CEGUIEXPORT Event : 00058 public AllocatedObject<Event> 00059 { 00060 public: 00068 typedef RefCounted<BoundSlot> Connection; 00069 00076 typedef CEGUI::SubscriberSlot Subscriber; 00077 00084 typedef unsigned int Group; 00085 00091 class ScopedConnection : public Connection 00092 { 00093 public: 00094 ScopedConnection() {} 00095 00096 ~ScopedConnection() 00097 { 00098 disconnect(); 00099 } 00100 00101 ScopedConnection(const Event::Connection& connection) : 00102 d_connection(connection) 00103 {} 00104 00105 ScopedConnection& operator=(const Event::Connection& connection) 00106 { 00107 d_connection = connection; 00108 return *this; 00109 } 00110 00111 bool connected() const 00112 { 00113 return d_connection.isValid() ? d_connection->connected() : false; 00114 } 00115 00116 void disconnect() 00117 { 00118 if (d_connection.isValid()) d_connection->disconnect(); 00119 } 00120 00121 private: 00122 Event::Connection d_connection; 00123 }; 00124 00129 Event(const String& name); 00130 00136 virtual ~Event(); 00137 00145 const String& getName(void) const 00146 { 00147 return d_name; 00148 } 00149 00164 Connection subscribe(const Subscriber& slot); 00165 00185 Connection subscribe(Group group, const Subscriber& slot); 00186 00200 void operator()(EventArgs& args); 00201 00202 00203 protected: 00204 friend void CEGUI::BoundSlot::disconnect(); 00215 void unsubscribe(const BoundSlot& slot); 00216 00217 // Copy constructor and assignment are not allowed for events 00218 Event(const Event&) {} 00219 Event& operator=(const Event&) 00220 { 00221 return *this; 00222 } 00223 00224 typedef std::multimap<Group, Connection, std::less<Group> 00225 CEGUI_MULTIMAP_ALLOC(Group, Connection)> SlotContainer; 00226 SlotContainer d_slots; 00227 const String d_name; 00228 }; 00229 00230 } // End of CEGUI namespace section 00231 00232 #if defined(_MSC_VER) 00233 # pragma warning(pop) 00234 #endif 00235 00236 #endif // end of guard _CEGUIEvent_h_ 00237