Adonthell  0.4
event_list Class Reference

Base class for objects that want to register events. More...

#include <event_list.h>

Inheritance diagram for event_list:

Public Member Functions

 event_list ()
 Constructor - creates an empty, unpaused event_list. More...
 
virtual ~event_list ()
 Destructor - unregisters and deletes all events owned by this list. More...
 
void clear ()
 Unregisters and deletes all events owned by this list. More...
 
List Operations
void add_event (event *ev)
 Adds an event to this list. More...
 
void remove_event (event *ev)
 Removes an event from the list. More...
 
eventget_event (const string &id)
 Try to retrieve the event with given id from the list. More...
 
Pausing / Resuming execution
void pause ()
 Disable any events associated with this event_list. More...
 
void resume ()
 Re-enable the events associated with the event_list, thus 'awaking' the object to life again. More...
 
bool is_paused () const
 Check whether the event list is temporarily disabled or not. More...
 
Loading / Saving
void put_state (ogzstream &out) const
 Save the event_list to a file. More...
 
bool get_state (igzstream &in)
 Loads the event_list from a file and registers all loaded events. More...
 

Static Public Member Functions

static void register_event (u_int8 type, new_event e)
 Register an event for loading. More...
 

Protected Attributes

std::vector< event * > Events
 List of events. More...
 

Detailed Description

Base class for objects that want to register events.

It keeps track of all the events an object has registered with the event_handler and can automatically unregister them when the object is deallocated.

It also provides the functionality to load and save the states of events in its list.

Objects making use of events should use the event_list instead of handling events themselves.

Definition at line 52 of file event_list.h.

Constructor & Destructor Documentation

event_list::event_list ( )

Constructor - creates an empty, unpaused event_list.

Definition at line 32 of file event_list.cc.

event_list::~event_list ( )
virtual

Destructor - unregisters and deletes all events owned by this list.

Definition at line 38 of file event_list.cc.

Member Function Documentation

void event_list::clear ( )

Unregisters and deletes all events owned by this list.

Definition at line 44 of file event_list.cc.

void event_list::add_event ( event ev)

Adds an event to this list.

The event will be registered with the event_handler and the list will then take care of it's deletion.

Parameters
evpointer to the event to add.

Definition at line 58 of file event_list.cc.

void event_list::remove_event ( event ev)

Removes an event from the list.

This is usually called when an event is destroyed.

Parameters
evpointer to the event to remove.

Definition at line 71 of file event_list.cc.

event * event_list::get_event ( const string &  id)

Try to retrieve the event with given id from the list.

Returns
a pointer to the event, or NULL if it's not in the list.

Definition at line 83 of file event_list.cc.

void event_list::pause ( )

Disable any events associated with this event_list.

This will effectively stop all actions of the object the event_list belongs to, e.g. a NPC.

Definition at line 94 of file event_list.cc.

void event_list::resume ( )

Re-enable the events associated with the event_list, thus 'awaking' the object to life again.

Definition at line 102 of file event_list.cc.

bool event_list::is_paused ( ) const
inline

Check whether the event list is temporarily disabled or not.

Returns
true if it is paused, false otherwise.

Definition at line 120 of file event_list.h.

void event_list::register_event ( u_int8  type,
new_event  e 
)
static

Register an event for loading.

Before the event_list can load an event from file, it needs a callback function that returns a new instance of the event of the given type.

Parameters
typethe type of the event to register
ea callback returning a new instance of an event of the given type.
See also
get_state ()

Definition at line 110 of file event_list.cc.

void event_list::put_state ( ogzstream out) const

Save the event_list to a file.

Parameters
outfile where to save the event_list.

Definition at line 117 of file event_list.cc.

bool event_list::get_state ( igzstream in)

Loads the event_list from a file and registers all loaded events.

Warning
Before the event_list can load an event from file, it needs a callback function that returns a new instance of that event.
Parameters
infile to load the event_list from.
Returns
true if the event_list was loaded successfully, false otherwise.
See also
register_event ()

Definition at line 129 of file event_list.cc.

Member Data Documentation

std::vector<event*> event_list::Events
mutableprotected

List of events.

Definition at line 171 of file event_list.h.


The documentation for this class was generated from the following files: