The Battle for Wesnoth  1.15.2+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 ()
 
handler_listget (const std::string &name)
 Access to the handlers with fixed event names, by event name. More...
 
void add_event_handler (const config &cfg, 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...
 

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

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

Detailed Description

Definition at line 26 of file manager_impl.hpp.

Member Typedef Documentation

◆ handler_queue_t

Definition at line 29 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 31 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 30 of file manager_impl.hpp.

Constructor & Destructor Documentation

◆ event_handlers()

game_events::event_handlers::event_handlers ( )
inline

Definition at line 55 of file manager_impl.hpp.

Member Function Documentation

◆ add_event_handler()

void game_events::event_handlers::add_event_handler ( const config cfg,
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 92 of file manager_impl.cpp.

References active_, by_name_, DBG_EH, dynamic_, config::empty(), id_map_, utils::join(), log_handlers(), utils::might_contain_variables(), utils::split(), standardize_name(), and lg::wml_error().

Referenced by get_active().

◆ 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 199 of file manager_impl.cpp.

References active_, dynamic_, p, and utils::split().

Referenced by get_active().

◆ get()

handler_list & game_events::event_handlers::get ( const std::string &  name)

Access to the handlers with fixed event names, by event name.

Read-only access to the handlers with fixed event names, by event name.

Definition at line 77 of file manager_impl.cpp.

References by_name_, and standardize_name().

◆ get_active() [1/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 70 of file manager_impl.hpp.

References active_.

◆ get_active() [2/2]

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

◆ get_dynamic()

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

Access to the handlers with varying event names.

Definition at line 64 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 222 of file manager_impl.cpp.

References id_map_.

Referenced by get_active().

◆ log_handlers()

void game_events::event_handlers::log_handlers ( )
private

Definition at line 36 of file manager_impl.cpp.

References active_, DBG_EH, lg::debug(), and h.

Referenced by add_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 170 of file manager_impl.cpp.

References DBG_EH, id_map_, and log_handlers().

Referenced by get_active().

◆ size()

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

The number of active event handlers.

Definition at line 101 of file manager_impl.hpp.

◆ 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 61 of file manager_impl.cpp.

Referenced by add_event_handler(), game_events::manager::execute_on_events(), and get().

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 38 of file manager_impl.hpp.

Referenced by add_event_handler(), clean_up_expired_handlers(), get_active(), and log_handlers().

◆ 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 41 of file manager_impl.hpp.

Referenced by add_event_handler(), and get().

◆ dynamic_

handler_list game_events::event_handlers::dynamic_
private

Active event handlers with variables in their event names.

Definition at line 44 of file manager_impl.hpp.

Referenced by add_event_handler(), clean_up_expired_handlers(), 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 47 of file manager_impl.hpp.

Referenced by add_event_handler(), get_event_handler_by_id(), and remove_event_handler().


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