Crazy Eddies GUI System 0.7.5

CEGUIEvent.h

00001 /************************************************************************
00002     filename:   CEGUIEvent.h
00003     created:    Tue Feb 28 2006
00004     author:     Paul D Turner <paul@cegui.org.uk>
00005 *************************************************************************/
00006 /***************************************************************************
00007  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00008  *
00009  *   Permission is hereby granted, free of charge, to any person obtaining
00010  *   a copy of this software and associated documentation files (the
00011  *   "Software"), to deal in the Software without restriction, including
00012  *   without limitation the rights to use, copy, modify, merge, publish,
00013  *   distribute, sublicense, and/or sell copies of the Software, and to
00014  *   permit persons to whom the Software is furnished to do so, subject to
00015  *   the following conditions:
00016  *
00017  *   The above copyright notice and this permission notice shall be
00018  *   included in all copies or substantial portions of the Software.
00019  *
00020  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00023  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00024  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00025  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00026  *   OTHER DEALINGS IN THE SOFTWARE.
00027  ***************************************************************************/
00028 #ifndef _CEGUIEvent_h_
00029 #define _CEGUIEvent_h_
00030 
00031 #include "CEGUIString.h"
00032 #include "CEGUIBoundSlot.h"
00033 #include "CEGUISubscriberSlot.h"
00034 #include "CEGUIRefCounted.h"
00035 
00036 #include <map>
00037 
00038 #if defined(_MSC_VER)
00039 #       pragma warning(push)
00040 #       pragma warning(disable : 4251)
00041 #endif
00042 
00043 // Start of CEGUI namespace section
00044 namespace CEGUI
00045 {
00058 class CEGUIEXPORT 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             { disconnect(); }
00098 
00099         ScopedConnection(const Event::Connection& connection) :
00100             d_connection(connection)
00101         {}
00102 
00103         ScopedConnection& operator=(const Event::Connection& connection)
00104         {
00105             d_connection = connection;
00106             return *this;
00107         }
00108 
00109         bool connected() const
00110             { return d_connection.isValid() ? d_connection->connected() : false; }
00111 
00112         void disconnect()
00113             { if (d_connection.isValid()) d_connection->disconnect(); }
00114 
00115     private:
00116         Event::Connection d_connection;
00117     };
00118 
00123     Event(const String& name);
00124 
00130     ~Event();
00131 
00139     const String& getName(void) const
00140         { return d_name; }
00141 
00156     Connection subscribe(const Subscriber& slot);
00157 
00177     Connection subscribe(Group group, const Subscriber& slot);
00178 
00192     void operator()(EventArgs& args);
00193 
00194 
00195 private:
00196     friend void CEGUI::BoundSlot::disconnect();
00207     void unsubscribe(const BoundSlot& slot);
00208 
00209     // Copy constructor and assignment are not allowed for events
00210     Event(const Event&) {}
00211     Event& operator=(const Event&)  {return *this;}
00212 
00213     typedef std::multimap<Group, Connection> SlotContainer;
00214     SlotContainer d_slots;  
00215     const String d_name;    
00216 };
00217 
00218 } // End of  CEGUI namespace section
00219 
00220 #if defined(_MSC_VER)
00221 #       pragma warning(pop)
00222 #endif
00223 
00224 #endif  // end of guard _CEGUIEvent_h_