1 |
/* |
/* |
2 |
$Id$ |
$Id$ |
3 |
|
|
4 |
Copyright (C) 2000/2001/2002/2003/2004 Kai Sterker <kaisterker@linuxgames.com> |
Copyright (C) 2000/2001/2002/2003/2004 Kai Sterker <kaisterker@linuxgames.com> |
5 |
Part of the Adonthell Project http://adonthell.linuxgames.com |
Part of the Adonthell Project http://adonthell.linuxgames.com |
6 |
|
|
7 |
Adonthell is free software; you can redistribute it and/or modify |
Adonthell is free software; you can redistribute it and/or modify |
8 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
9 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
10 |
(at your option) any later version. |
(at your option) any later version. |
11 |
|
|
12 |
Adonthell is distributed in the hope that it will be useful, |
Adonthell is distributed in the hope that it will be useful, |
13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
18 |
along with Adonthell; if not, write to the Free Software |
along with Adonthell; if not, write to the Free Software |
19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
*/ |
*/ |
21 |
|
|
22 |
|
|
23 |
/** |
/** |
24 |
* @file event/manager.h |
* @file event/manager.h |
25 |
* @author Kai Sterker <kaisterker@linuxgames.com> |
* @author Kai Sterker <kaisterker@linuxgames.com> |
26 |
* |
* |
27 |
* @brief Declares the %event %manager class |
* @brief Declares the %event %manager class |
28 |
* |
* |
29 |
*/ |
*/ |
30 |
|
|
31 |
#ifndef EVENT_MANAGER_H |
#ifndef EVENT_MANAGER_H |
32 |
#define EVENT_MANAGER_H |
#define EVENT_MANAGER_H |
33 |
|
|
34 |
#include "event/types.h" |
#include "event/types.h" |
35 |
#include "event/factory.h" |
#include "event/factory.h" |
36 |
#include "event/manager_base.h" |
#include "event/manager_base.h" |
37 |
|
|
38 |
namespace events |
namespace events |
39 |
{ |
{ |
40 |
/** |
/** |
41 |
* It ensures global access to the individual %event managers. |
* It ensures global access to the individual %event managers. |
42 |
*/ |
*/ |
43 |
class manager |
class manager |
44 |
{ |
{ |
45 |
public: |
public: |
46 |
/** |
/** |
47 |
* Unregister an %event %listener. |
* Unregister an %event %listener. |
48 |
* |
* |
49 |
* @param li pointer to the %listener to unregister. |
* @param li pointer to the %listener to unregister. |
50 |
*/ |
*/ |
51 |
static void remove (listener* li) |
static void remove (listener* li) |
52 |
{ |
{ |
53 |
manager_base *manager = event_type::get_manager (li->type ()); |
manager_base *manager = event_type::get_manager (li->type ()); |
54 |
if (manager != NULL) |
if (manager != NULL) |
55 |
{ |
{ |
56 |
li->set_registered (false); |
li->set_registered (false); |
57 |
manager->remove (li); |
manager->remove (li); |
58 |
} |
} |
59 |
} |
} |
60 |
|
|
61 |
/** |
/** |
62 |
* Check if an %event corresponding to ev exists, and execute it. |
* Check if an %event corresponding to ev exists, and execute it. |
63 |
* |
* |
64 |
* @param ev %event to raise. |
* @param ev %event to raise. |
65 |
*/ |
*/ |
66 |
static void raise_event (const event* ev) |
static void raise_event (const event* ev) |
67 |
{ |
{ |
68 |
manager_base *manager = event_type::get_manager (((event *) ev)->type ()); |
manager_base *manager = event_type::get_manager (((event *) ev)->type ()); |
69 |
if (manager != NULL) |
if (manager != NULL) |
70 |
{ |
{ |
71 |
manager->raise_event (ev); |
manager->raise_event (ev); |
72 |
} |
} |
73 |
} |
} |
74 |
|
|
75 |
protected: |
protected: |
76 |
/** |
/** |
77 |
* Registers an %event %listener. |
* Registers an %event %listener. |
78 |
* |
* |
79 |
* @param li pointer to the %listener to register. |
* @param li pointer to the %listener to register. |
80 |
*/ |
*/ |
81 |
static void add (listener* li) |
static void add (listener* li) |
82 |
{ |
{ |
83 |
manager_base *manager = event_type::get_manager (li->type ()); |
manager_base *manager = event_type::get_manager (li->type ()); |
84 |
if (manager != NULL) |
if (manager != NULL) |
85 |
{ |
{ |
86 |
li->set_registered (true); |
li->set_registered (true); |
87 |
manager->add (li); |
manager->add (li); |
88 |
} |
} |
89 |
} |
} |
90 |
|
|
91 |
/** |
/** |
92 |
* Only %event %factory is allowed to register events with the |
* Only %event %factory is allowed to register events with the |
93 |
* %event %manager. |
* %event %manager. |
94 |
*/ |
*/ |
95 |
friend class factory; |
friend class factory; |
96 |
|
|
97 |
/** |
/** |
98 |
* As is %listener::resume |
* As is %listener::resume |
99 |
*/ |
*/ |
100 |
friend void listener::resume (); |
friend void listener::resume (); |
101 |
}; |
}; |
102 |
} |
} |
103 |
#endif // EVENT_MANAGER_H |
#endif // EVENT_MANAGER_H |