#include <manager_impl.hpp>
Public Member Functions | |
event_handlers () | |
handler_list & | get_dynamic () |
Access to the handlers with varying event names. More... | |
const handler_queue_t & | get_active () const |
Read-only access to the active event handlers. More... | |
handler_queue_t & | get_active () |
pending_event_handler | add_event_handler (const std::string &name, const std::string &id, bool repeat, double priority=0., bool is_menu_item=false) |
Adds an event handler. More... | |
void | remove_event_handler (const std::string &id) |
Removes an event handler, identified by its ID. More... | |
void | clean_up_expired_handlers (const std::string &event_name) |
Removes all expired event handlers and any weak_ptrs to them. More... | |
const handler_ptr | get_event_handler_by_id (const std::string &id) |
Gets an event handler, identified by its ID. More... | |
std::size_t | size () const |
The number of active event handlers. More... | |
Static Public Member Functions | |
static std::string | standardize_name (const std::string &name) |
Utility to standardize the event names used in by_name_. More... | |
static bool | cmp (const handler_ptr &lhs, const handler_ptr &rhs) |
Compare function to sort event handlers by priority. More... | |
Private Types | |
using | handler_queue_t = std::deque< handler_ptr > |
using | map_t = std::unordered_map< std::string, handler_list > |
using | id_map_t = std::unordered_map< std::string, weak_handler_ptr > |
Private Member Functions | |
void | log_handlers () |
void | finish_adding_event_handler (const handler_ptr &new_handler) |
Private Attributes | |
handler_queue_t | active_ |
Active event handlers. More... | |
map_t | by_name_ |
Active event handlers with fixed event names, organized by event name. More... | |
handler_list | dynamic_ |
Active event handlers with variables in their event names. More... | |
id_map_t | id_map_ |
Allows quick locating of handlers by id. More... | |
friend | pending_event_handler |
Definition at line 55 of file manager_impl.hpp.
|
private |
Definition at line 58 of file manager_impl.hpp.
|
private |
Definition at line 60 of file manager_impl.hpp.
|
private |
Definition at line 59 of file manager_impl.hpp.
|
inline |
Definition at line 90 of file manager_impl.hpp.
pending_event_handler game_events::event_handlers::add_event_handler | ( | const std::string & | name, |
const std::string & | id, | ||
bool | repeat, | ||
double | priority = 0. , |
||
bool | is_menu_item = false |
||
) |
Adds an event handler.
An event with a nonempty ID will not be added if an event with that ID already exists.
Definition at line 89 of file manager_impl.cpp.
References ERR_EH, id_map_, lg::info(), LOG_EH, log_event_handler, lg::log_to_chat(), and wfl::msg().
void game_events::event_handlers::clean_up_expired_handlers | ( | const std::string & | event_name | ) |
Removes all expired event handlers and any weak_ptrs to them.
event_name | The event name from whose by-name queue to clean up handlers. |
Definition at line 192 of file manager_impl.cpp.
References active_, by_name_, dynamic_, utils::erase_if(), p, utils::split(), and standardize_name().
|
static |
Compare function to sort event handlers by priority.
Definition at line 79 of file manager_impl.cpp.
Referenced by finish_adding_event_handler().
|
private |
Definition at line 120 of file manager_impl.cpp.
References active_, by_name_, cmp(), DBG_EH, dynamic_, id, id_map_, log_handlers(), utils::might_contain_variables(), and names.
Referenced by game_events::pending_event_handler::~pending_event_handler().
|
inline |
Definition at line 110 of file manager_impl.hpp.
References active_.
|
inline |
Read-only access to the active event handlers.
Essentially gives all events.
Definition at line 105 of file manager_impl.hpp.
References active_.
|
inline |
Access to the handlers with varying event names.
Definition at line 99 of file manager_impl.hpp.
References dynamic_.
const handler_ptr game_events::event_handlers::get_event_handler_by_id | ( | const std::string & | id | ) |
Gets an event handler, identified by its ID.
Definition at line 211 of file manager_impl.cpp.
References id_map_.
|
private |
Definition at line 42 of file manager_impl.cpp.
References active_, DBG_EH, lg::debug(), h, and log_event_handler.
Referenced by finish_adding_event_handler(), and remove_event_handler().
void game_events::event_handlers::remove_event_handler | ( | const std::string & | id | ) |
Removes an event handler, identified by its ID.
Events with empty IDs cannot be removed.
Definition at line 163 of file manager_impl.cpp.
References DBG_EH, id, id_map_, and log_handlers().
|
inline |
The number of active event handlers.
Definition at line 133 of file manager_impl.hpp.
References active_.
|
static |
Utility to standardize the event names used in by_name_.
This means stripping leading and trailing spaces, and converting internal spaces to underscores.
Definition at line 66 of file manager_impl.cpp.
References utils::trim().
Referenced by clean_up_expired_handlers(), game_events::manager::execute_on_events(), and game_events::event_handler::names().
|
private |
Active event handlers.
Will not have elements removed unless the event_handlers is clear()ed. This is the only container that actually 'owns' any events in the form of shared_ptrs. The other three storage methods own weak_ptrs.
Definition at line 67 of file manager_impl.hpp.
Referenced by clean_up_expired_handlers(), finish_adding_event_handler(), get_active(), log_handlers(), and size().
|
private |
Active event handlers with fixed event names, organized by event name.
Definition at line 70 of file manager_impl.hpp.
Referenced by clean_up_expired_handlers(), and finish_adding_event_handler().
|
private |
Active event handlers with variables in their event names.
Definition at line 73 of file manager_impl.hpp.
Referenced by clean_up_expired_handlers(), finish_adding_event_handler(), and get_dynamic().
|
private |
Allows quick locating of handlers by id.
Definition at line 76 of file manager_impl.hpp.
Referenced by add_event_handler(), finish_adding_event_handler(), get_event_handler_by_id(), and remove_event_handler().
|
private |
Definition at line 80 of file manager_impl.hpp.