blob: a086e8076547f23b2b98adda20ea757f4df7f465 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef guard_general_observer_subject_h
#define guard_general_observer_subject_h
//==============================================================================
// General Code, © 2002 Ryan Winter
//==============================================================================
#include "observer.h"
#include <list>
class Subject
{
public:
Subject();
virtual ~Subject();
//--------------------------------------------------------------------------
// Description : Notify all observers of a state change
//--------------------------------------------------------------------------
void notify();
//--------------------------------------------------------------------------
// Description : Attach an observer to the subject
// Parameters : observer - the observer
//--------------------------------------------------------------------------
void attach(Observer &observer);
//--------------------------------------------------------------------------
// Description : Detach an observer from the subject
// Parameters : observer - the observer
//--------------------------------------------------------------------------
void detach(const Observer &observer);
private:
//--------------------------------------------------------------------------
// Description : Disallow assignment operator and copy constructor
//--------------------------------------------------------------------------
Subject(const Subject &rhs);
const Subject & operator=(const Subject &rhs);
std::list<Observer *> m_observer_list;
};
//==============================================================================
//
// Summary : Subject side of the observer pattern
//
// Description : Instances of this class are what is observered by observers
//
//==============================================================================
#endif
|