The class Observable defines a mechanism that allows objects to be notified of changes to the specified properties of other objects. More...
#include <Observable.h>
Public Member Functions | |
Observable () | |
Default constructor. | |
virtual | ~Observable () |
Default destructor. | |
virtual void | addObserver (string aKey, Observer &o) |
Register an observer. | |
virtual void | removeObserver (string aKey, Observer &o) |
Unregister an observer. | |
virtual void | removeAllObservers () |
Remove all observer from the dispatch table. | |
virtual int | countObservers () |
Returns the number of keys observed. | |
Protected Member Functions | |
virtual void | willChangeValueForKey (string aKey) |
Notification before value changes. | |
virtual void | didChangeValueForKey (string aKey) |
Notification after value changed. | |
Private Attributes | |
map< string, set< Observer * > > | _observers |
Association between the key and the list of observers. |
The class Observable defines a mechanism that allows objects to be notified of changes to the specified properties of other objects.
You can observe any object properties including simple attributes. Observers are informed of the type of change made — as well as which objects are involved in the change.
Observable::Observable | ( | ) |
Default constructor.
References LOG_CTOR.
Observable::~Observable | ( | ) | [virtual] |
Default destructor.
References LOG_DTOR.
void Observable::addObserver | ( | std::string | aKey, | |
Observer & | o | |||
) | [virtual] |
Register an observer.
Adds an entry to the receiver’s dispatch table with an observer, for a notifications restricted to key.
[in] | aKey | The name of the notification for which to register the observer |
[in] | o | Object registering as an observer. This value must not be NULL |
References _observers, LOG, and Observer::toString().
Referenced by testObserver().
int Observable::countObservers | ( | ) | [virtual] |
void Observable::didChangeValueForKey | ( | string | aKey | ) | [protected, virtual] |
Notification after value changed.
Invoked to inform the receiver that the value of a given property has changed.
References _observers, and LOG.
Referenced by TestObservable::setKey().
void Observable::removeAllObservers | ( | ) | [virtual] |
Remove all observer from the dispatch table.
References _observers.
void Observable::removeObserver | ( | string | aKey, | |
Observer & | o | |||
) | [virtual] |
Unregister an observer.
Removes matching entries from the receiver’s dispatch table for the specified keys.
[in] | aKey | The name of the notification for which to remove the observer |
[in] | o | Observer to remove from the dispatch table |
References _observers, LOG, and Observer::toString().
Referenced by testObserver().
void Observable::willChangeValueForKey | ( | string | aKey | ) | [protected, virtual] |
Notification before value changes.
Invoked to inform the receiver that the value of a given property is about to change.
References _observers, and LOG.
Referenced by TestObservable::setKey().
map<string, set<Observer *> > Observable::_observers [private] |
Association between the key and the list of observers.
Referenced by addObserver(), countObservers(), didChangeValueForKey(), removeAllObservers(), removeObserver(), and willChangeValueForKey().