ocra-recipes
Doxygen documentation for the ocra-recipes repository
|
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 |
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.
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.
|
protected |
Definition at line 239 of file ObserverSubjectBase.h.
|
protected |
Definition at line 238 of file ObserverSubjectBase.h.
|
inlineprotected |
Definition at line 251 of file ObserverSubjectBase.h.
|
inlineprotected |
Definition at line 252 of file ObserverSubjectBase.h.
|
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.
|
inlineprotected |
Call this method from your callbacks to avoid propagation to the bound subject (if any).
Definition at line 247 of file ObserverSubjectBase.h.
Definition at line 274 of file ObserverSubjectBase.h.