The Battle for Wesnoth  1.19.7+dev
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
game_events::event_handlers Class Reference

#include <manager_impl.hpp>

Public Member Functions

 event_handlers ()
 
handler_listget_dynamic ()
 Access to the handlers with varying event names. More...
 
const handler_queue_tget_active () const
 Read-only access to the active event handlers. More...
 
handler_queue_tget_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
 

Detailed Description

Definition at line 55 of file manager_impl.hpp.

Member Typedef Documentation

◆ handler_queue_t

Definition at line 58 of file manager_impl.hpp.

◆ id_map_t

using game_events::event_handlers::id_map_t = std::unordered_map<std::string, weak_handler_ptr>
private

Definition at line 60 of file manager_impl.hpp.

◆ map_t

using game_events::event_handlers::map_t = std::unordered_map<std::string, handler_list>
private

Definition at line 59 of file manager_impl.hpp.

Constructor & Destructor Documentation

◆ event_handlers()

game_events::event_handlers::event_handlers ( )
inline

Definition at line 90 of file manager_impl.hpp.

Member Function Documentation

◆ add_event_handler()

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().

◆ clean_up_expired_handlers()

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.

Parameters
event_nameThe 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().

◆ cmp()

bool game_events::event_handlers::cmp ( const handler_ptr lhs,
const handler_ptr rhs 
)
static

Compare function to sort event handlers by priority.

Definition at line 79 of file manager_impl.cpp.

Referenced by finish_adding_event_handler().

◆ finish_adding_event_handler()

void game_events::event_handlers::finish_adding_event_handler ( const handler_ptr new_handler)
private

◆ get_active() [1/2]

handler_queue_t& game_events::event_handlers::get_active ( )
inline

Definition at line 110 of file manager_impl.hpp.

References active_.

◆ get_active() [2/2]

const handler_queue_t& game_events::event_handlers::get_active ( ) const
inline

Read-only access to the active event handlers.

Essentially gives all events.

Definition at line 105 of file manager_impl.hpp.

References active_.

◆ get_dynamic()

handler_list& game_events::event_handlers::get_dynamic ( )
inline

Access to the handlers with varying event names.

Definition at line 99 of file manager_impl.hpp.

References dynamic_.

◆ get_event_handler_by_id()

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_.

◆ log_handlers()

void game_events::event_handlers::log_handlers ( )
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().

◆ 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().

◆ size()

std::size_t game_events::event_handlers::size ( ) const
inline

The number of active event handlers.

Definition at line 133 of file manager_impl.hpp.

References active_.

◆ standardize_name()

std::string game_events::event_handlers::standardize_name ( const std::string &  name)
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().

Member Data Documentation

◆ active_

handler_queue_t game_events::event_handlers::active_
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().

◆ by_name_

map_t game_events::event_handlers::by_name_
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().

◆ dynamic_

handler_list game_events::event_handlers::dynamic_
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().

◆ id_map_

id_map_t game_events::event_handlers::id_map_
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().

◆ pending_event_handler

friend game_events::event_handlers::pending_event_handler
private

Definition at line 80 of file manager_impl.hpp.


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