Adonthell  0.4
event_handler.h
Go to the documentation of this file.
1 /*
2  $Id: event_handler.h,v 1.5 2003/01/20 20:18:43 ksterker Exp $
3 
4  Copyright (C) 2000/2001/2002/2003 Kai Sterker <kaisterker@linuxgames.com>
5  Part of the Adonthell Project http://adonthell.linuxgames.com
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 
16 /**
17  * @file event_handler.h
18  * @author Kai Sterker <kaisterker@linuxgames.com>
19  *
20  * @brief Declares the event_handler class
21  *
22  */
23 
24 #ifndef EVENT_HANDLER_H__
25 #define EVENT_HANDLER_H__
26 
27 #include "event_handler_base.h"
28 #include "event_list.h"
29 
30 /**
31  * It ensures global access to the individual %event handlers.
32  */
34 {
35 public:
36  /**
37  * Instanciate the actual event handlers. Event handlers
38  * can be specific to a certain event, or take care of
39  * different events.
40  */
41  static void init ();
42 
43  /**
44  * Delete the %event handlers.
45  */
46  static void cleanup ();
47 
48  /**
49  * Unregister an %event.
50  *
51  * @param ev pointer to the %event to unregister.
52  */
53  static void remove_event (event* ev)
54  {
55  ev->set_registered (false);
56  Handler[ev->type ()]->remove_event (ev);
57  }
58 
59  /**
60  * Check if an %event corresponding to ev exists, and execute it.
61  *
62  * @param ev %event to raise.
63  */
64  static void raise_event (const event* ev)
65  {
66  Handler[ev->type ()]->raise_event (ev);
67  }
68 
69 protected:
70  /**
71  * Registers an %event.
72  *
73  * @param ev pointer to the %event to register.
74  */
75  static void register_event (event* ev)
76  {
77  ev->set_registered (true);
78  Handler[ev->type ()]->register_event (ev);
79  }
80 
81  /**
82  * Only %event_list is allowed to register events with the
83  * %event_handler.
84  */
85  friend void event_list::add_event (event* ev);
86 
87  /**
88  * As is event::resume.
89  */
90  friend void event::resume ();
91 
92 private:
93  /**
94  * A list of the actual %event handlers
95  */
96  static event_handler_base* Handler[MAX_EVENTS];
97 };
98 
99 #endif // EVENT_HANDLER_H__
static void raise_event(const event *ev)
Check if an event corresponding to ev exists, and execute it.
Definition: event_handler.h:64
This is the base class for actual event handlers.
virtual void remove_event(event *ev)=0
Unregister an event.
static void init()
Instanciate the actual event handlers.
Base class for events.
Definition: event.h:71
void add_event(event *ev)
Adds an event to this list.
Definition: event_list.cc:58
Declares the base class for event handlers.
void set_registered(bool reg)
Set whether the event is registered with the event handler.
Definition: event.h:139
virtual void resume()
Re-enable an event that has been paused.
Definition: event.cc:230
static void remove_event(event *ev)
Unregister an event.
Definition: event_handler.h:53
virtual void raise_event(const event *ev)=0
Check if an event corresponding to ev exists, and execute it.
static void cleanup()
Delete the event handlers.
static void register_event(event *ev)
Registers an event.
Definition: event_handler.h:75
virtual void register_event(event *ev)=0
Registers an event.
u_int8 type() const
Get the event&#39;s type.
Definition: event.h:98
It ensures global access to the individual event handlers.
Definition: event_handler.h:33
Declares the event_list class.