Radium Engine  1.5.20
Loading...
Searching...
No Matches
Ra::Core::Utils::Observable< Args > Class Template Reference

#include <Core/Utils/Observable.hpp>

+ Inheritance diagram for Ra::Core::Utils::Observable< Args >:
+ Collaboration diagram for Ra::Core::Utils::Observable< Args >:

Public Types

using Observer = std::function<void( Args... )>
 Observer functor type.
 

Public Member Functions

 Observable ()=default
 Default constructor ... do nothing ;)
 
 Observable (const Observable &)=delete
 
Observableoperator= (const Observable &)=delete
 
void copyObserversTo (Observable &other) const
 explicit copy of all attached observers the other Observable
 
int attach (Observer observer)
 
template<typename T >
int attachMember (T *object, void(T::*observer)(Args...))
 
void notify (Args... p) const
 Notify (i.e. call) each attached observer with argument p.
 
void detachAll ()
 Detach all observers.
 
void detach (int observerId)
 

Detailed Description

template<typename... Args>
class Ra::Core::Utils::Observable< Args >

Simple observable implementation with void observer(Args...) notification. Typical usage is to derive from Observer with the intended Args as in

class MyClass : public Oberservable<int> [...]
MyClass c;
c.attach(functor)
int attach(Observer observer)

Also a class can have Observable members, than act as slots

class MyClass {
public :
Oberservable<int> slot0;
Oberservable<> slot1;
void f(){ slot0.notify(10); }
};
MyClass c;
c.slot0.attach(functor)
c.slot1.attach(functor)

Definition at line 33 of file Observable.hpp.

Member Typedef Documentation

◆ Observer

template<typename... Args>
using Ra::Core::Utils::Observable< Args >::Observer = std::function<void( Args... )>

Observer functor type.

Definition at line 37 of file Observable.hpp.

Member Function Documentation

◆ attach()

template<typename... Args>
int Ra::Core::Utils::Observable< Args >::attach ( Observer observer)
inline

Attach an observer that will be call on subsecant call to notify()

Returns
An unique int to identify the observer, could be used to pass to Obeservable::detach

Definition at line 54 of file Observable.hpp.

◆ attachMember()

template<typename... Args>
template<typename T >
int Ra::Core::Utils::Observable< Args >::attachMember ( T * object,
void(T::* observer )(Args...) )
inline

Utility function that extract the observer from a class member. Attach an observer that will be call on subsecant call to notify()

Returns
An unique int to identify the observer, could be used to pass to Obeservable::detach

Definition at line 63 of file Observable.hpp.

+ Here is the call graph for this function:

◆ copyObserversTo()

template<typename... Args>
void Ra::Core::Utils::Observable< Args >::copyObserversTo ( Observable< Args > & other) const
inline

explicit copy of all attached observers the other Observable

Definition at line 46 of file Observable.hpp.

+ Here is the call graph for this function:

◆ detach()

template<typename... Args>
void Ra::Core::Utils::Observable< Args >::detach ( int observerId)
inline

Detach the observerId, observerId must have been saved from a previous call to attach

Definition at line 77 of file Observable.hpp.

◆ detachAll()

template<typename... Args>
void Ra::Core::Utils::Observable< Args >::detachAll ( )
inline

Detach all observers.

Definition at line 73 of file Observable.hpp.

◆ notify()

template<typename... Args>
void Ra::Core::Utils::Observable< Args >::notify ( Args... p) const
inline

Notify (i.e. call) each attached observer with argument p.

Definition at line 67 of file Observable.hpp.

+ Here is the call graph for this function:

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