kmail

isubject.cpp
1#ifdef HAVE_CONFIG_H
2#include <config.h>
3#endif
4
5#include "isubject.h"
6#include "interfaces/observer.h"
7
8#include <tqtl.h>
9
10#include <kdebug.h>
11
12namespace KMail {
13
14 ISubject::~ISubject()
15 {
16 mObserverList.clear();
17 }
18
19 void ISubject::attach( Interface::Observer * pObserver )
20 {
21 if ( tqFind( mObserverList.begin(), mObserverList.end(), pObserver ) == mObserverList.end() )
22 mObserverList.push_back( pObserver );
23 }
24
25 void ISubject::detach( Interface::Observer * pObserver ) {
26 TQValueVector<Interface::Observer*>::iterator it = tqFind( mObserverList.begin(), mObserverList.end(), pObserver );
27 if ( it != mObserverList.end() )
28 mObserverList.erase( it );
29 }
30
31 void ISubject::notify()
32 {
33 kdDebug(5006) << "ISubject::notify " << mObserverList.size() << endl;
34
35 // iterate over a copy (to prevent crashes when
36 // {attach(),detach()} is called from an Observer::update()
37 const TQValueVector<Interface::Observer*> copy = mObserverList;
38 for ( TQValueVector<Interface::Observer*>::const_iterator it = copy.begin() ; it != copy.end() ; ++it ) {
39 if ( (*it) ) {
40 (*it)->update( this );
41 }
42 }
43 }
44
45}
46
folderdiaquotatab.h
Definition: aboutdata.cpp:40