anatomist  5.0.5
3D neuroimaging data viewer
anatomist::Observable Class Reference

This class can be subclassed to represent an object that the programmer wants to have observed. More...

#include <anatomist/observer/Observable.h>

Inheritance diagram for anatomist::Observable:
Collaboration diagram for anatomist::Observable:

Public Member Functions

 Observable ()
 Construct an Observable with zero observers. More...
 
virtual ~Observable ()
 does nothing More...
 
Observer handling
void addObserver (Observer *observer)
 Adds an observer to the set of observers for this object. More...
 
void deleteObserver (Observer *observer)
 Deletes an observer from the set of observers of this object. More...
 
void deleteObservers ()
 Clears the observer list so that this object no longer has any observers (doesn't call any observer method - see notifyUnregisterObservers() for this ) More...
 
int countObservers () const
 Returns the number of observers of this object. More...
 
virtual void notifyObservers (void *arg=0)
 If this object has changed, as indicated by the hasChanged method, then notify all of its observers. More...
 
virtual void notifyUnregisterObservers ()
 Notifies observable destruction to all observers and unregisters them. More...
 
Changed?
bool hasChanged () const
 Tests if this object has changed. More...
 
bool obsHasChanged (int) const
 only valid during an Observer::update() More...
 
bool obsHasChanged (const std::string &) const
 only valid during an Observer::update() More...
 
void setChanged () const
 Indicates that this object has changed. More...
 
- Public Member Functions inherited from carto::SharedObject
 SharedObject ()
 
 SharedObject (const SharedObject &x)
 
virtual ~SharedObject ()
 
SharedObjectoperator= (const SharedObject &)
 
bool testDeletable ()
 
bool tryDelete ()
 
- Public Member Functions inherited from carto::WeakObject
void attachWeakPtr (weak_ptr< T > &) const
 
void detachWeakPtr (weak_ptr< T > &) const
 
void attachWeakPtr (weak_shared_ptr< T > &) const
 
void detachWeakPtr (weak_shared_ptr< T > &) const
 
virtual ~WeakObject ()
 
- Public Member Functions inherited from carto::RCObject
 RCObject ()
 
 RCObject (const RCObject &)
 
RCObjectoperator= (const RCObject &)
 
virtual ~RCObject ()
 

Protected Member Functions

void clearChanged () const
 Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change. More...
 
void obsSetChanged (int, bool=true) const
 int-based change flags (use enums to address them) More...
 
void obsSetChanged (const std::string &, bool=true) const
 string-based change flags More...
 
- Protected Member Functions inherited from carto::SharedObject
void disableRefCount ()
 
- Protected Member Functions inherited from carto::WeakObject
 WeakObject ()
 
 WeakObject (const WeakObject &)
 
WeakObjectoperator= (const WeakObject &)
 

Additional Inherited Members

- Public Types inherited from carto::RCObject
typedef int RefCounterType
 

Detailed Description

This class can be subclassed to represent an object that the programmer wants to have observed.

\ An observable object can have one or more observers. After an observable instance changes, an application calling the Observable's notifyObservers method causes all of its observers to be notified of the change by a call to their update method. \ This implementation of an observable is a mere copy of the Java Observable: http://java.sun.com/javase/6/docs/api/java/util/Observable.html

Definition at line 67 of file Observable.h.

Constructor & Destructor Documentation

◆ Observable()

anatomist::Observable::Observable ( )

Construct an Observable with zero observers.

◆ ~Observable()

virtual anatomist::Observable::~Observable ( )
virtual

does nothing

Member Function Documentation

◆ addObserver()

void anatomist::Observable::addObserver ( Observer observer)

Adds an observer to the set of observers for this object.

Parameters
observeran observer to be added

◆ clearChanged()

void anatomist::Observable::clearChanged ( ) const
protected

Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change.

This method is called automatically by the notifyObservers methods.

These changed-flags are temporary and are cleared after notifyObservers function is called: do not use them to keep an internal track of things to update (up-to-date flags should be implemented internally by objects)

◆ countObservers()

int anatomist::Observable::countObservers ( ) const

Returns the number of observers of this object.

Returns
the number of observers of this object

◆ deleteObserver()

void anatomist::Observable::deleteObserver ( Observer observer)

Deletes an observer from the set of observers of this object.

Parameters
observerobserver to be deleted

◆ deleteObservers()

void anatomist::Observable::deleteObservers ( )

Clears the observer list so that this object no longer has any observers (doesn't call any observer method - see notifyUnregisterObservers() for this )

◆ hasChanged()

bool anatomist::Observable::hasChanged ( ) const
inline

Tests if this object has changed.

Returns
true if the setChanged method has been called more recently than the clearChanged method on this object; false otherwise

Definition at line 176 of file Observable.h.

◆ notifyObservers()

virtual void anatomist::Observable::notifyObservers ( void *  arg = 0)
virtual

If this object has changed, as indicated by the hasChanged method, then notify all of its observers.

Then call the clearChanged method to indicate that this object has no longer changed. \ Each Observer.has its update method called.

Parameters
arganything you want to pass to the observers

Reimplemented in anatomist::ASurface< D >, anatomist::ASurface< 2 >, anatomist::ASurface< 3 >, and anatomist::ATexture.

◆ notifyUnregisterObservers()

virtual void anatomist::Observable::notifyUnregisterObservers ( )
virtual

Notifies observable destruction to all observers and unregisters them.

◆ obsHasChanged() [1/2]

bool anatomist::Observable::obsHasChanged ( int  ) const

only valid during an Observer::update()

◆ obsHasChanged() [2/2]

bool anatomist::Observable::obsHasChanged ( const std::string &  ) const

only valid during an Observer::update()

◆ obsSetChanged() [1/2]

void anatomist::Observable::obsSetChanged ( int  ,
bool  = true 
) const
protected

int-based change flags (use enums to address them)

◆ obsSetChanged() [2/2]

void anatomist::Observable::obsSetChanged ( const std::string &  ,
bool  = true 
) const
protected

string-based change flags

◆ setChanged()

void anatomist::Observable::setChanged ( ) const
inline

Indicates that this object has changed.

Definition at line 184 of file Observable.h.

Referenced by anatomist::MObject::eraseObject().


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