Design Pattern Examples
Overview of object-oriented design patterns
HandlerChain Class Reference

Represents a list of handlers that all implement the IMessageHandler interface. This list can be dynamically updated and each element in the list is passed messages for processing. More...

#include <HandlerChain_Class.h>

Collaboration diagram for HandlerChain:
Collaboration graph

Public Types

using unique_ptr_t = std::unique_ptr< HandlerChain >
 

Public Member Functions

void SendMessage (Message *message)
 Send a message to each of the handlers in the list, protected by a multi-threading lock.
 
void AddHandler (IMessageHandler::shared_ptr_t window)
 Add an instance of the IMessageHandler interface to end of the list of handlers, protected by a multi-threading lock.
 
void RemoveHandler (IMessageHandler::shared_ptr_t window)
 Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.
 
void RemoveHandler (IMessageHandler *window)
 Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.
 
std::string ToString ()
 Convert this HandlerChain to a string, protected by a multi-threading lock.
 

Private Attributes

std::list< IMessageHandler::shared_ptr_t_messageHandlers
 The list of message handlers.
 
std::mutex _messageHandlersLock
 Object used to lock access to the message handlers list for multi-threaded support.
 

Detailed Description

Represents a list of handlers that all implement the IMessageHandler interface. This list can be dynamically updated and each element in the list is passed messages for processing.

Definition at line 77 of file HandlerChain_Class.h.

Member Typedef Documentation

◆ unique_ptr_t

using unique_ptr_t = std::unique_ptr<HandlerChain>

Definition at line 80 of file HandlerChain_Class.h.

Member Function Documentation

◆ AddHandler()

void AddHandler ( IMessageHandler::shared_ptr_t  window)
inline

Add an instance of the IMessageHandler interface to end of the list of handlers, protected by a multi-threading lock.

If a message handler is already in the list, it is not added again.

Parameters
windowThe IMessageHandler object to add.

Definition at line 128 of file HandlerChain_Class.h.

References HandlerChain::_messageHandlers, and HandlerChain::_messageHandlersLock.

Referenced by MessageWindow::CreateWindow().

◆ RemoveHandler() [1/2]

void RemoveHandler ( IMessageHandler window)
inline

Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.

If the message handler is not in the list, the request to remove is ignored.

Parameters
windowThe window to remove

Definition at line 166 of file HandlerChain_Class.h.

References HandlerChain::_messageHandlers, HandlerChain::_messageHandlersLock, and IMessageHandler::ID().

◆ RemoveHandler() [2/2]

void RemoveHandler ( IMessageHandler::shared_ptr_t  window)
inline

Remove an instance of the IMessageHandler interface from the list, protected by a multi-threading lock.

If the message handler is not in the list, the request to remove is ignored.

Parameters
windowThe window to remove

Definition at line 152 of file HandlerChain_Class.h.

References HandlerChain::_messageHandlers, and HandlerChain::_messageHandlersLock.

Referenced by MessageWindow::_HandleCloseMessage().

◆ SendMessage()

void SendMessage ( Message message)
inline

Send a message to each of the handlers in the list, protected by a multi-threading lock.

Parameters
messageThe Message object to send to each handler.

Definition at line 100 of file HandlerChain_Class.h.

References HandlerChain::_messageHandlers, and HandlerChain::_messageHandlersLock.

Referenced by MessageWindow::_HandleButtonUpMessage().

◆ ToString()

std::string ToString ( )
inline

Convert this HandlerChain to a string, protected by a multi-threading lock.

Returns
Returns a string representation of this HandlerChain and all the handlers it contains.

Definition at line 179 of file HandlerChain_Class.h.

References HandlerChain::_messageHandlers, HandlerChain::_messageHandlersLock, and Helpers::formatstring().

Member Data Documentation

◆ _messageHandlers

std::list<IMessageHandler::shared_ptr_t> _messageHandlers
private

◆ _messageHandlersLock

std::mutex _messageHandlersLock
private

Object used to lock access to the message handlers list for multi-threaded support.

Definition at line 92 of file HandlerChain_Class.h.

Referenced by HandlerChain::AddHandler(), HandlerChain::RemoveHandler(), HandlerChain::SendMessage(), and HandlerChain::ToString().


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