Observable Class Reference

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>

Inheritance diagram for Observable:
Inheritance graph
[legend]

List of all members.

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.

Detailed Description

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.


Constructor & Destructor Documentation

Observable::Observable (  ) 

Default constructor.

References LOG_CTOR.

Observable::~Observable (  )  [virtual]

Default destructor.

References LOG_DTOR.


Member Function Documentation

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.

Parameters:
[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]

Returns the number of keys observed.

Returns:
Count of keys.

References _observers.

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.

Returns:
aKey The name of the property that 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.

Parameters:
[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.

Returns:
aKey The name of the property that will change.

References _observers, and LOG.

Referenced by TestObservable::setKey().


Member Data Documentation

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().


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

Generated by  doxygen 1.6.2