ObserverPattern
Public Member Functions | Protected Member Functions | List of all members
Observer::SmartContainer< T_Listener > Class Template Reference

A container of listeners, which holds weak pointers. More...

#include <observer.h>

Public Member Functions

void attach (const std::shared_ptr< T_Listener > &listener)
 Attach listener listener to this container. More...
 
void detach (const std::shared_ptr< T_Listener > &listener)
 Detach listener listener from this container. More...
 

Protected Member Functions

template<typename... Fn_Args>
void notify (void(T_Listener::*fn)(Fn_Args...), Fn_Args &&... args)
 Call a notification function as specified by the first parameter. More...
 

Detailed Description

template<class T_Listener>
class Observer::SmartContainer< T_Listener >

A container of listeners, which holds weak pointers.

This is a collection of weak pointers to listener objects of a single type, which is defined by the template parameter. The container is to be used in Source class.

Member Function Documentation

◆ attach()

template<class T_Listener >
void Observer::SmartContainer< T_Listener >::attach ( const std::shared_ptr< T_Listener > &  listener)
inline

Attach listener listener to this container.

When attached, notifications are sent to the listener. Note that a weak pointer to the listener is actually stored.

◆ detach()

template<class T_Listener >
void Observer::SmartContainer< T_Listener >::detach ( const std::shared_ptr< T_Listener > &  listener)
inline

Detach listener listener from this container.

When detached, notifications aren't sent to the listener anymore.

◆ notify()

template<class T_Listener >
template<typename... Fn_Args>
void Observer::SmartContainer< T_Listener >::notify ( void(T_Listener::*)(Fn_Args...)  fn,
Fn_Args &&...  args 
)
inlineprotected

Call a notification function as specified by the first parameter.

All listeners registered in this container are notified. The parameter pack is forwarded to that function.


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