-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSubject.cpp
More file actions
55 lines (42 loc) · 748 Bytes
/
Copy pathSubject.cpp
File metadata and controls
55 lines (42 loc) · 748 Bytes
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
53
54
55
#include "Subject.h"
#include <iostream>
#include <string>
Subject::Subject()
{
}
Subject::~Subject()
{
}
void Subject::Attach(Observer* s)
{
_observers.push_back(s);
//cout << s->type << " Subscribed" << endl;
}
void Subject::Detach(Observer* s)
{
for (int i = 0; i < int(_observers.size()); i++)
{
if (_observers[i] == s)
{
_observers.erase(_observers.begin() + i);
break;
}
}
cout << s->type << "Unsubscribed" << endl;
}
void Subject::Notify()
{
//cout << "Notify" << endl;
for (int i = 0; i < int(_observers.size()); i++)
{
_observers[i]->Update(this);
}
}
void Subject::Notify(Subject* s)
{
//cout << "Notify" << endl;
for (size_t i = 0; i < _observers.size(); i++)
{
_observers[i]->Update(s);
}
}