![]() |
Workspace 7.0.2
|
Base class for all observable classes. More...
#include <Workspace/DataExecution/Events/observable.h>
Public Member Functions | |
virtual | ~Observable () |
void | attachObserver (Observer &observer) |
void | destroy () |
void | detachObserver (Observer &observer) |
void | notifyEvent (const ObservableEvent &event) |
Protected Member Functions | |
Observable () | |
Observable (const Observable &) | |
All public functions in this class are thread-safe. Clients are allowed to attach and detach observers at any time, including an observer currently responding to an event notification. The constructor is inherently thread-safe since a new independent object is created with each invocation. Destructors are never thread-safe, since an object can only be destroyed once.
|
protected |
Newly constructed Observable objects have no-one to notify.
|
protected |
The copy constructor does not copy the source object's list of observers. Therefore, the new object is created with no observers regardless of what is passed to this constructor (actually, the parameter is not used at all).
|
virtual |
The destructor will destroy all observers still attached to it. Therefore, it is important that all such observers were dynamically allocated and are not local stack objects.
void attachObserver | ( | Observer & | observer | ) |
observer | The observer to attach. |
void destroy | ( | ) |
void detachObserver | ( | Observer & | observer | ) |
observer | The observer to detach. |
Allows an observer to be detached. If an observer was attached for a specific event type, then it cannot simply be detached by passing the result of AllObservableEvents::eventID() for eventID. An observer must be detached with the identical eventID for which it was attached.
void notifyEvent | ( | const ObservableEvent & | event | ) |
event | The event for which all interested objects should be notified. |
Initiates an event of type event and notifies all currently attached observers interested in that event type (or all event types). Those observers attached for this specific event type will be notified first, followed by observers attached to respond for all events.
It is safe for an observer to detach itself as part of responding to the event. Internal checks are performed which will delay the detachment until the observer has finished responding to the event. The observer can safely delete itself, since the detachment does not use the observer in any way.