ocra-recipes
Doxygen documentation for the ocra-recipes repository
Public Member Functions | Protected Types | Protected Member Functions | Friends | List of all members
ocra::ObserverBase< EVT > Class Template Reference

Base class for Observers with propagation system. More...

#include <ObserverSubjectBase.h>

Public Member Functions

void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 

Protected Types

typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 

Protected Member Functions

void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 

Friends

template<class , int , bool >
class Invoker
 

Detailed Description

template<int EVT>
class ocra::ObserverBase< EVT >

Base class for Observers with propagation system.

Use this class as a public base class to observe subjects and propagate the observed events. Classes who derive this class can connect to Subjects so that if these subjects raise an event with a timestamp greater than the last event's timestamp, then the registered callback is called; else nothing happens. Other subjects can be bound to an Observer so that the event is automatically propagated to these subjects; in this case, observers who observe these bound subjects will be triggered, except if the method ObserverBase::stopPropagation() is called within the callback.

For observers who derive ObserverBase: When a callback is triggered because a subject has raised an event with timestamp t0, any event with timestamp t <= t0 will have no effect; the callback will be triggered for events with timestamps t > t0. This is to avoid infinite looping when an observer is connected to a subject and propagates the event through a cycle to this same subject. This also allows calling a callback more than once for the same events when a callback can be triggered for the same event with two different pathes.

Warning
For the time being, ensuring that observers and subjects are alive is left to the client code. No automatic unregistration of a dying observer or subject is performed.

Example: Creation of a chain of observers and subjects for an event identified with the integer constant MY_EVENT_ID. class MySubject : public SubjectBase<MY_EVENT_ID> { ... }; class MyObserverSubject : public ObserverBase<MY_EVENT_ID>, public SubjectBase<MY_EVENT_ID> { ... }; class MyObserver : public ObserverBase<MY_EVENT_ID> { ... }; ... MySubject subject; MyObserverSubject obsSubject; MyObserver observer; subject.connect(obsSubject, &MyObserverSubject::theMethodYouWant); obsSubject.bind(obsSubject); // so that when obsSubject receives an event from subject, it can propagate it and be observed. obsSubject.connect(observer, &MyObserver::anyMethodYouThinkIsSuitable); subject.propagate(); // will trigger obsSubject.theMethodYouWant(), which propagates to observer.anyMethodYouThinkIsSuitable()...

Definition at line 32 of file ObserverSubjectBase.h.

Member Typedef Documentation

template<int EVT>
typedef InvokerBase<EVT> ocra::ObserverBase< EVT >::invoker_type
protected

Definition at line 239 of file ObserverSubjectBase.h.

template<int EVT>
typedef SubjectBase<EVT> ocra::ObserverBase< EVT >::subject_type
protected

Definition at line 238 of file ObserverSubjectBase.h.

Constructor & Destructor Documentation

template<int EVT>
ocra::ObserverBase< EVT >::ObserverBase ( )
inlineprotected

Definition at line 251 of file ObserverSubjectBase.h.

template<int EVT>
ocra::ObserverBase< EVT >::~ObserverBase ( )
inlineprotected

Definition at line 252 of file ObserverSubjectBase.h.

Member Function Documentation

template<int EVT>
void ocra::ObserverBase< EVT >::bind ( subject_type subject)
inline

Call this method to automatically propagate observed events to observers connected to the subject given in argument.

Definition at line 243 of file ObserverSubjectBase.h.

template<int EVT>
void ocra::ObserverBase< EVT >::stopPropagation ( )
inlineprotected

Call this method from your callbacks to avoid propagation to the bound subject (if any).

Definition at line 247 of file ObserverSubjectBase.h.

Friends And Related Function Documentation

template<int EVT>
template<class , int , bool >
friend class Invoker
friend

Definition at line 274 of file ObserverSubjectBase.h.


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