• Main Page
  • Related Pages
  • Classes
  • Files
  • File List
  • File Members

event_handler.h

Go to the documentation of this file.
00001 /*
00002    $Id: event_handler.h,v 1.5 2003/01/20 20:18:43 ksterker Exp $
00003 
00004    Copyright (C) 2000/2001/2002/2003 Kai Sterker <kaisterker@linuxgames.com>
00005    Part of the Adonthell Project http://adonthell.linuxgames.com
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License.
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY.
00011 
00012    See the COPYING file for more details.
00013 */
00014 
00015 
00016 /**
00017  * @file   event_handler.h
00018  * @author Kai Sterker <kaisterker@linuxgames.com>
00019  * 
00020  * @brief  Declares the event_handler class
00021  * 
00022  */
00023 
00024 #ifndef EVENT_HANDLER_H__
00025 #define EVENT_HANDLER_H__
00026 
00027 #include "event_handler_base.h"
00028 #include "event_list.h"
00029 
00030 /**
00031  * It ensures global access to the individual %event handlers.
00032  */
00033 class event_handler
00034 {
00035 public:
00036     /**
00037      * Instanciate the actual event handlers. Event handlers
00038      * can be specific to a certain event, or take care of
00039      * different events.
00040      */
00041     static void init ();
00042 
00043     /**
00044      * Delete the %event handlers.
00045      */
00046     static void cleanup ();
00047 
00048     /** 
00049      * Unregister an %event.
00050      * 
00051      * @param ev pointer to the %event to unregister.
00052      */
00053     static void remove_event (event* ev)
00054     {
00055         ev->set_registered (false);
00056         Handler[ev->type ()]->remove_event (ev);
00057     }
00058 
00059     /** 
00060      * Check if an %event corresponding to ev exists, and execute it. 
00061      * 
00062      * @param ev %event to raise.
00063      */
00064     static void raise_event (const event* ev)
00065     {
00066         Handler[ev->type ()]->raise_event (ev);
00067     }
00068 
00069 protected:
00070     /** 
00071      * Registers an %event.
00072      * 
00073      * @param ev pointer to the %event to register.
00074      */
00075     static void register_event (event* ev)
00076     {
00077         ev->set_registered (true);
00078         Handler[ev->type ()]->register_event (ev);
00079     }
00080 
00081     /**
00082      * Only %event_list is allowed to register events with the
00083      * %event_handler.
00084      */
00085     friend void event_list::add_event (event* ev);
00086 
00087     /**
00088      * As is event::resume.
00089      */
00090     friend void event::resume ();
00091     
00092 private:
00093     /**
00094      * A list of the actual %event handlers
00095      */
00096     static event_handler_base* Handler[MAX_EVENTS];
00097 };
00098 
00099 #endif // EVENT_HANDLER_H__

Generated on Fri Mar 18 2011 for Adonthell by  doxygen 1.7.1