ObserverPattern
Public Member Functions | Protected Member Functions | List of all members
Observer::Source< T_Container, T_Listeners > Class Template Reference

Base class for all sources. More...

#include <observer.h>

Inheritance diagram for Observer::Source< T_Container, T_Listeners >:

Public Member Functions

template<typename... Args>
void attach (Listener< Args... > *listener)
 Attach a listener object, which implements listeners given by Args. More...
 
template<typename... Args>
void attach (const std::shared_ptr< Listener< Args... >> &listener)
 Attach a listener object, which implements listeners given by Args. More...
 
template<class T >
void attach (const std::shared_ptr< T > &listener)
 Convenience method to overcome the covariant issue with smart pointers.
 
template<typename... Args>
void detach (Listener< Args... > *listener)
 Detach a listener object, which implements listeners given by Args.
 
template<typename... Args>
void detach (const std::shared_ptr< Listener< Args... >> &listener)
 Detach a listener object, which implements listeners given by Args.
 
template<class T >
void detach (const std::shared_ptr< T > &listener)
 Convenience method to overcome the covariant issue with smart pointers.
 

Protected Member Functions

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

Detailed Description

template<template< class > class T_Container, class... T_Listeners>
class Observer::Source< T_Container, T_Listeners >

Base class for all sources.

The source may be source of events for mutliple listeners. They are specified in the T_Listeners pack. Objects of rach listener type are stored in separate containers, however, the user may specify the type of the container in T_Container template parameter.

Containers must have attach(), detach(), and notify methods. Currently, two containers are provided: RawContainer for holding raw pointers and SmartContainer for holding weak pointers of listener objects.

however, users may supply their own implementation.

Member Function Documentation

◆ attach() [1/2]

template<template< class > class T_Container, class... T_Listeners>
template<typename... Args>
void Observer::Source< T_Container, T_Listeners >::attach ( Listener< Args... > *  listener)
inline

Attach a listener object, which implements listeners given by Args.

This is an overload of attach method, which accepts a raw pointer to the listerner object. Note that only those listener types, which are provided in the T_Listeners pack are registered, others are ignored.

◆ attach() [2/2]

template<template< class > class T_Container, class... T_Listeners>
template<typename... Args>
void Observer::Source< T_Container, T_Listeners >::attach ( const std::shared_ptr< Listener< Args... >> &  listener)
inline

Attach a listener object, which implements listeners given by Args.

This is an overload of attach method, which accepts a shared pointer to the listerner object. Note that only those listener types, which are provided in the T_Listeners pack are registered, others are ignored.

◆ notify()

template<template< class > class T_Container, class... T_Listeners>
template<typename T , typename... Fn_Args>
void Observer::Source< T_Container, T_Listeners >::notify ( void(T::*)(Fn_Args...)  fn,
Fn_Args &&...  args 
)
inlineprotected

Call a notification function as specified by the first parameter.

The parameter pack is forwarded to that function.


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