METSlib 0.5
Public Member Functions | Protected Attributes | List of all members
mets::subject< observed_subject > Class Template Reference

template class for subjects (cfr. Observer Design Pattern). More...

#include <observer.hh>

Collaboration diagram for mets::subject< observed_subject >:
Collaboration graph

Public Member Functions

virtual void attach (observer< observed_subject > &o)
 Attach a new observer to this subject.
 
virtual void detach (observer< observed_subject > &o)
 Detach a new observer to this subject.
 
virtual void notify ()
 Notify all attached observers.
 

Protected Attributes

std::set< observer< observed_subject > * > observers_m
 

Detailed Description

template<typename observed_subject>
class mets::subject< observed_subject >

template class for subjects (cfr. Observer Design Pattern).

You must declare the subject of the observations with:

class my_observed_sbj : public subject<my_observed_sbj>

Than you should call notify() manually or automatically from every method that changes the subject status.

Only attached observers (cfr. attach() and detach() methods) will be notified.

Member Function Documentation

◆ attach()

template<typename observed_subject >
void mets::subject< observed_subject >::attach ( observer< observed_subject< observed_subject > > & o)
virtual

Attach a new observer to this subject.

Parameters
oa new observer for this subject. if the observer was already present nothing happens.

◆ detach()

template<typename observed_subject >
void mets::subject< observed_subject >::detach ( observer< observed_subject< observed_subject > > & o)
virtual

Detach a new observer to this subject.

Parameters
oobserver to detach from this subject. if the observer "o" was not present nothing happens.

◆ notify()

template<typename observed_subject >
void mets::subject< observed_subject >::notify ( )
virtual

Notify all attached observers.

When this method is called every observed_subject::update method is called and "this" subject is passed as a param.


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

Return to METSlib home page