00001 //############################################################################################################################################### 00002 // 00003 // Meta and Builder Object Network V2.0 for GME 00004 // Events.h 00005 // 00006 //############################################################################################################################################### 00007 00008 /* 00009 Copyright (c) Vanderbilt University, 2000-2004 00010 ALL RIGHTS RESERVED 00011 00012 Vanderbilt University disclaims all warranties with regard to this 00013 software, including all implied warranties of merchantability 00014 and fitness. In no event shall Vanderbilt University be liable for 00015 any special, indirect or consequential damages or any damages 00016 whatsoever resulting from loss of use, data or profits, whether 00017 in an action of contract, negligence or other tortious action, 00018 arising out of or in connection with the use or performance of 00019 this software. 00020 */ 00021 00022 #ifndef Events_h 00023 #define Events_h 00024 00025 #include "MON.h" 00026 #include "BON.h" 00027 00028 namespace BON 00029 { 00030 00031 //############################################################################################################################################### 00032 // 00033 // C L A S S : BON::Event 00034 // 00035 //############################################################################################################################################### 00036 00037 class Event 00038 { 00039 // Member Variables 00040 private : 00041 MON::ObjectEventType m_eType; 00042 Object m_context; 00043 00044 // Construction and Destruction 00045 public : 00046 Event( MON::ObjectEventType eType, const Object& context ); 00047 Event( const Event& event ); 00048 Event& operator = ( const Event& event ); 00049 public : 00050 virtual ~Event() { } 00051 00052 // Get Operations 00053 public : 00054 MON::ObjectEventType getType() const; 00055 Object getContext() const; 00056 std::string getInfoString( Util::InfoOptions usOptions = Util::IO_None ) const; 00057 std::string getInfoString( std::set<Util::InfoOption> setOptions ) const; 00058 }; 00059 00060 //############################################################################################################################################### 00061 // 00062 // C L A S S : BON::EventListener 00063 // 00064 //############################################################################################################################################### 00065 00066 class EventListener 00067 { 00068 // Construction and Destruction 00069 public : 00070 EventListener() 00071 { 00072 } 00073 00074 virtual ~EventListener() 00075 { 00076 } 00077 00078 // Interface 00079 public : 00080 virtual void eventPerformed( const Event& event ) 00081 { 00082 } 00083 00084 virtual MON::ObjectEventTypes getAssignments() const 00085 { 00086 return MON::OET_All; 00087 } 00088 00089 virtual bool isActive() const 00090 { 00091 return true; 00092 } 00093 }; 00094 00095 //############################################################################################################################################### 00096 // 00097 // C L A S S : BON::EventListenerPool 00098 // 00099 //############################################################################################################################################### 00100 00101 class EventListenerPool 00102 { 00103 // Type definitions 00104 private : 00105 typedef std::vector<EventListener*> ListenerVector; 00106 typedef std::map<MON::ObjectEventType,ListenerVector> ListenerMap; 00107 00108 // Member Variables 00109 private : 00110 ListenerMap m_mapListeners; 00111 00112 // Construction and Destruction 00113 public : 00114 EventListenerPool() 00115 { 00116 } 00117 00118 virtual ~EventListenerPool() 00119 { 00120 } 00121 00122 // Interface 00123 public : 00124 void performEvent( const Event& event ); 00125 00126 void addListener( EventListener* pListener ); 00127 void removeListener( EventListener* pListener ); 00128 00129 }; 00130 00131 }; // namespace BON 00132 00133 #endif Events_h