-
Notifications
You must be signed in to change notification settings - Fork 0
/
Subject.cpp
48 lines (41 loc) · 913 Bytes
/
Subject.cpp
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
//
//
// @ Project : DgcApp
// @ File Name : Subject.cpp
// @ Date : 15/03/2012
// @ Author : Leonardo Lanchas
//
//
#include "Subject.h"
Subject::Subject() { }
/**
* @brief deletes all observers by calling their destructors
*/
Subject::~Subject()
{
map < int, Observer * >::iterator it = ls.begin();
for ( ; it != ls.end(); it++ ) it->second->~Observer();
}
/**
* @brief add observer to the list in order to notify them the changes
* @param O Observer * (Observer.h)
*/
void Subject::Adscribe( Observer * O ) { ls[ ( int ) O ] = O; }
/**
* @brief call Canvas::Update()
*/
void Subject::Notify()
{
map < int, Observer * >::iterator it = ls.begin();
for ( ; it != ls.end(); it++ ) it->second->Update();
}
/**
* delete Observer O
* @param O Observer *
*/
void Subject::Remove( Observer * O )
{
delete ls[ ( int ) O ];
ls[ ( int ) O ] = NULL;
ls.erase( ( int ) O );
}