Adonthell  0.4
time_event_handler.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002 Kai Sterker <kai.sterker@gmail.com>
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 /**
20  * @file time_event_handler.h
21  *
22  * @author Kai Sterker
23  * @brief Declares the time_event_handler class.
24  */
25 
26 #ifndef TIME_EVENT_HANDLER_H__
27 #define TIME_EVENT_HANDLER_H__
28 
29 #include <vector>
30 #include "event_handler_base.h"
31 
32 using std::vector;
33 
34 /**
35  * This class keeps track of time events, i.e. events that are raised
36  * at a certain point in (%game) time. All registered events are
37  * sorted by the time they need to be raised, so that only one
38  * comparison decides upon whether an %event is to be raised.
39  */
41 {
42 public:
43  /**
44  * Register a time %event with the %event handler. It is inserted
45  * into the vector of registered events depending on its "alarm"
46  * time. The %event needs to be removed before it can be safely
47  * deleted.
48  *
49  * @param evnt Pointer to the %event to be registered.
50  */
51  void register_event (event *evnt);
52 
53  /**
54  * Removes the given %event from the %event handler. Once it is
55  * no longer needed, it can be freed.
56  *
57  * @param evnt Pointer to the %event to be removed.
58  */
59  void remove_event (event *evnt);
60 
61  /**
62  * Raise one or more events in case the given time matches their
63  * "alarm" time. When they need to be repeated, they are
64  * re-inserted into the %event-vector.
65  *
66  * @param evnt An %event structure with the current %game time in
67  * minutes.
68  */
69  void raise_event (const event *evnt);
70 
71 private:
72  // storage for registered time events.
73  vector<event*> Events;
74 };
75 
76 #endif // TIME_EVENT_HANDLER_H__
This is the base class for actual event handlers.
void remove_event(event *evnt)
Removes the given event from the event handler.
Base class for events.
Definition: event.h:75
Declares the base class for event handlers.
void raise_event(const event *evnt)
Raise one or more events in case the given time matches their "alarm" time.
void register_event(event *evnt)
Register a time event with the event handler.
This class keeps track of time events, i.e.