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

Thread safe observers list (internal usage). More...

#include <observerList.hpp>

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

Public Member Functions

 ObserverList ()
 ObserverList (const ObserverList &)=delete
 ~ObserverList ()=default
ObserverList & operator= (const ObserverList &)=delete
bool add (anch::events::Observer< T > &observer)
void remove (anch::events::Observer< T > &observer)
void notify (const anch::events::Event< T > &event)

Detailed Description

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

Thread safe observers list (internal usage).

List shared by Observable and EventBus.
Notifications are done without lock on a snapshot of the list (copy on write) so observers can add or remove observers, or notify again, from their handle method.
Guarantees:

  • an observer removed during a notification is not notified anymore by this notification ;
  • when remove returns, the observer will not be notified anymore by any thread and can be destroyed. remove waits for notifications running in other threads. Called from a handle method (current thread is notifying this list), it does not wait for the current thread notifications.

Observers are notified in their registration order.

Since
0.1
Author
Vincent Lachenal

Constructor & Destructor Documentation

◆ ObserverList() [1/2]

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

ObserverList constructor

◆ ObserverList() [2/2]

template<typename T>
anch::events::ObserverList< T >::ObserverList ( const ObserverList< T > & )
delete

Prohibits ObserverList copy constructor

Here is the call graph for this function:

◆ ~ObserverList()

template<typename T>
anch::events::ObserverList< T >::~ObserverList ( )
default

ObserverList destructor

Member Function Documentation

◆ add()

template<typename T>
bool anch::events::ObserverList< T >::add ( anch::events::Observer< T > & observer)

Register observer

Parameters
observerthe observer to register
Returns
true when observer has been added, false when it was already registered

◆ notify()

template<typename T>
void anch::events::ObserverList< T >::notify ( const anch::events::Event< T > & event)

Notify every registered observer

Parameters
eventthe event to notify

◆ operator=()

template<typename T>
ObserverList & anch::events::ObserverList< T >::operator= ( const ObserverList< T > & )
delete

Prohibits ObserverList copy assignment

Here is the call graph for this function:

◆ remove()

template<typename T>
void anch::events::ObserverList< T >::remove ( anch::events::Observer< T > & observer)

Unregister observer.
Wait for notifications running in other threads.

Parameters
observerthe observer to unregister

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