LDA++
Public Member Functions | List of all members
ldaplusplus::events::EventDispatcherInterface Class Referenceabstract

#include <Events.hpp>

Inheritance diagram for ldaplusplus::events::EventDispatcherInterface:
ldaplusplus::events::EventDispatcher ldaplusplus::events::ThreadSafeEventDispatcher ldaplusplus::events::SameThreadEventDispatcher

Public Member Functions

virtual void add_listener (std::shared_ptr< EventListenerInterface > listener)=0
 
virtual void remove_listener (std::shared_ptr< EventListenerInterface > listener)=0
 
virtual void dispatch (std::shared_ptr< Event > event)=0
 
std::shared_ptr< EventListenerInterfaceadd_listener (std::function< void(std::shared_ptr< Event >)> listener)
 
template<class ListenerType , typename... Args>
std::shared_ptr< EventListenerInterfaceadd_listener (Args...args)
 
template<class EventType , typename... Args>
void dispatch (Args...args)
 

Detailed Description

EventDispatcher is the interface of a very simple event dispatcher.

Member Function Documentation

virtual void ldaplusplus::events::EventDispatcherInterface::add_listener ( std::shared_ptr< EventListenerInterface listener)
pure virtual

Add a listener to this dispatcher so that in subsequent calls to dispatch this listener will be notified.

The interface doesn't define handling of double adds or double removes.

Parameters
listenerThe listener to be added

Implemented in ldaplusplus::events::ThreadSafeEventDispatcher, and ldaplusplus::events::EventDispatcher.

std::shared_ptr<EventListenerInterface> ldaplusplus::events::EventDispatcherInterface::add_listener ( std::function< void(std::shared_ptr< Event >)>  listener)
inline

Create on the fly a listener from the function and add it to the dispatcher.

The created object is returned so that the listener can be removed later.

Parameters
listenerA function implementing the EventListener interface.
template<class ListenerType , typename... Args>
std::shared_ptr<EventListenerInterface> ldaplusplus::events::EventDispatcherInterface::add_listener ( Args...  args)
inline

Create on the fly a listener of type ListenerType and add it to the dispatcher.

The created object is returned so that the listener can be removed later.

Parameters
argsVariadic template arguments to be expanded as constructor parameters for the listener
virtual void ldaplusplus::events::EventDispatcherInterface::dispatch ( std::shared_ptr< Event event)
pure virtual

Call the on_event() function of every listener passing this event as a parameter.

The interface doesn't define when the on_event function will be called and it is not guaranteed that upon return of the dispatch function all listeners will be notified.

Parameters
eventThe event to be sent to the listeners

Implemented in ldaplusplus::events::SameThreadEventDispatcher, ldaplusplus::events::ThreadSafeEventDispatcher, and ldaplusplus::events::EventDispatcher.

template<class EventType , typename... Args>
void ldaplusplus::events::EventDispatcherInterface::dispatch ( Args...  args)
inline

Create on the fly an event object and dispatch it.

Parameters
argsVariadic template arguments to be expanded as constructor parameters for the event
virtual void ldaplusplus::events::EventDispatcherInterface::remove_listener ( std::shared_ptr< EventListenerInterface listener)
pure virtual

Remove a listener from this dispatcher so that in subsequent calls to dispatch this listener will not be notified.

The interface doesn't define handling of double adds or double removes.

Parameters
listenerThe listener to be removed

Implemented in ldaplusplus::events::ThreadSafeEventDispatcher, and ldaplusplus::events::EventDispatcher.


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