|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: event_handler.h 2163 2011-05-07 19:44:07Z hypereye $ 00005 // 00006 // Copyright (C) 2006-2010 by The Odamex Team. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // DESCRIPTION: 00019 // Handle Registration of C++ Class Member Event Handlers with Agar Events 00020 // 00021 // AUTHORS: 00022 // Michael Wood (mwoodj at huntsvegas dot org) 00023 // 00024 //----------------------------------------------------------------------------- 00025 00026 #ifndef _EVENT_HANDLER_H 00027 #define _EVENT_HANDLER_H 00028 00029 #include <list> 00030 00031 #include <agar/core.h> 00032 00039 namespace agOdalaunch { 00040 00041 #ifndef CALL_MEMBER_FN 00042 #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) 00043 #endif 00044 00045 class ODA_EventRegister; 00046 class EventHandler; 00047 00051 typedef void (ODA_EventRegister::*EVENT_FUNC_PTR)(AG_Event *); 00052 00060 void EventReceiver(AG_Event *event); 00061 00090 class ODA_EventRegister 00091 { 00092 public: 00099 ~ODA_EventRegister(); 00100 00113 EventHandler *RegisterEventHandler(EVENT_FUNC_PTR funcPtr); 00114 00125 bool DeleteEventHandler(EventHandler *handler); 00126 00127 private: 00128 std::list<EventHandler*> HandlerList; 00129 }; 00130 00138 class EventHandler 00139 { 00140 public: 00149 EventHandler(ODA_EventRegister *classPtr, EVENT_FUNC_PTR funcPtr) 00150 { ThisPtr = classPtr, FuncPtr = funcPtr; } 00151 00155 ~EventHandler() {}; 00156 00163 void Trigger(AG_Event *event) 00164 { CALL_MEMBER_FN(*ThisPtr, FuncPtr)(event); } 00165 00166 private: 00167 EVENT_FUNC_PTR FuncPtr; 00168 ODA_EventRegister *ThisPtr; 00169 }; 00170 00171 } // namespace 00172 00173 #endif