00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004
00005 #include "isubject.h"
00006 #include "interfaces/observer.h"
00007
00008 #include <tqtl.h>
00009
00010 #include <kdebug.h>
00011
00012 namespace KMail {
00013
00014 ISubject::~ISubject()
00015 {
00016 mObserverList.clear();
00017 }
00018
00019 void ISubject::attach( Interface::Observer * pObserver )
00020 {
00021 if ( tqFind( mObserverList.begin(), mObserverList.end(), pObserver ) == mObserverList.end() )
00022 mObserverList.push_back( pObserver );
00023 }
00024
00025 void ISubject::detach( Interface::Observer * pObserver ) {
00026 TQValueVector<Interface::Observer*>::iterator it = tqFind( mObserverList.begin(), mObserverList.end(), pObserver );
00027 if ( it != mObserverList.end() )
00028 mObserverList.erase( it );
00029 }
00030
00031 void ISubject::notify()
00032 {
00033 kdDebug(5006) << "ISubject::notify " << mObserverList.size() << endl;
00034
00035
00036
00037 const TQValueVector<Interface::Observer*> copy = mObserverList;
00038 for ( TQValueVector<Interface::Observer*>::const_iterator it = copy.begin() ; it != copy.end() ; ++it ) {
00039 if ( (*it) ) {
00040 (*it)->update( this );
00041 }
00042 }
00043 }
00044
00045 }
00046