AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::events::Observable< T > Class Template Reference

An observable implementation of the observers/observable design pattern. More...

#include <observable.hpp>

Inheritance diagram for anch::events::Observable< T >:
Collaboration diagram for anch::events::Observable< T >:

Public Member Functions

 Observable ()
virtual ~Observable ()
bool addObserver (anch::events::Observer< T > &observer)
void removeObserver (anch::events::Observer< T > &observer)
void notifyObservers (const T &event, const std::map< std::string, std::string > &headers={})
void notifyObservers (const anch::events::Event< T > &event)

Detailed Description

template<typename T>
class anch::events::Observable< T >

An observable implementation of the observers/observable design pattern.

This class maintains an observer list which have to be notified on event.
Notifications are synchronous (observers are called in the notifying thread, in their registration order). Observers can add or remove observers, or notify again, from their handle method. When removeObserver returns, the observer will not be notified anymore and can be destroyed.

Since
0.1
Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ Observable()

template<typename T>
anch::events::Observable< T >::Observable ( )

Observable default constructor

◆ ~Observable()

template<typename T>
virtual anch::events::Observable< T >::~Observable ( )
virtual

Observable destructor

Member Function Documentation

◆ addObserver()

template<typename T>
bool anch::events::Observable< T >::addObserver ( anch::events::Observer< T > & observer)

Add observer for notifications

Parameters
observerThe observer to add
Returns
true if observer has been added, false otherwise

◆ notifyObservers() [1/2]

template<typename T>
void anch::events::Observable< T >::notifyObservers ( const anch::events::Event< T > & event)

Notify every observer that an event has been fired

Parameters
eventthe event to fire

◆ notifyObservers() [2/2]

template<typename T>
void anch::events::Observable< T >::notifyObservers ( const T & event,
const std::map< std::string, std::string > & headers = {} )

Notify every observer that an event has been fired

Parameters
eventthe event to fire
headersthe event's headers (default to empty)

◆ removeObserver()

template<typename T>
void anch::events::Observable< T >::removeObserver ( anch::events::Observer< T > & observer)

Remove observer for notifications.
Wait for notifications running in other threads.

Parameters
observerThe observer to remove

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