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]
Collaboration diagram for Observable:
Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual ~Observable ()
virtual void addObserver (string aKey, Observer &o)
 Adds an entry to the receiver’s dispatch table with an observer, for a notifications restricted to key.
virtual void removeObserver (string aKey, Observer &o)
 Removes matching entries from the receiver’s dispatch table for the specified keys.
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)
 Invoked to inform the receiver that the value of a given property is about to change.
virtual void didChangevalueForKey (string aKey)
 Invoked to inform the receiver that the value of a given property has 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

virtual Observable::~Observable (  )  [inline, virtual]

Member Function Documentation

void Observable::addObserver ( std::string  aKey,
Observer o 
) [virtual]

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.

int Observable::countObservers (  )  [virtual]

Returns the number of keys observed.

Returns:
Count of keys.

References observers.

void Observable::didChangevalueForKey ( string  aKey  )  [protected, virtual]

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.

void Observable::removeAllObservers (  )  [virtual]

Remove all observer from the dispatch table.

References observers.

void Observable::removeObserver ( string  aKey,
Observer o 
) [virtual]

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.

void Observable::willChangeValueForKey ( string  aKey  )  [protected, virtual]

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.


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