Radium Engine  1.5.0
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)
Definition: Observable.hpp:54

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 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::*)(Args...)  observer 
)
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:

◆ 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.


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