-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc_model_observer.h
100 lines (86 loc) · 2.8 KB
/
icc_model_observer.h
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* ICC Examin ist eine ICC Profil Betrachter
*
* Copyright (C) 2005 Kai-Uwe Behrmann
*
* Autor: Kai-Uwe Behrmann <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* -----------------------------------------------------------------------------
*
* Implementation of the model/observer pattern
*
*/
#ifndef ICC_MODELL_BETRACHTER_H
#define ICC_MODELL_BETRACHTER_H
#include "icc_utils.h"
#include <list>
#include <string>
/*
* mode of work
*
* The class model provides the means to observe a condition.
* Observers of the class beobachter can subscribe to changes in model.
* A simple whole number informs about the changing state.
* It is important to know what kind the model is and to interprete the
* obtained number, possibly as a enumeration.
* The reduction to one argument type reduses the instanciations and
* increases the effort of interpretation.
* Models and observers should know each about the other. (Alternatively
* it would be possible to provide a reference to the model to know whether the
* observer still exists. But with destroying of the observer class a
* information can easily sent to the model.)
*
* Usage:
* It is needed to derive from the following classes and implement the
* virtual functions.
*/
namespace icc_examin_ns {
class Model;
class Observer
{
std::list<Model*> model_;
protected:
virtual ~Observer();
public:
Observer();
virtual void message ( Model* model , int infos );
void modelDel ( Model* model );
void modelAdd ( Model* model );
};
class Model
{
friend class Observer;
protected:
Model();
void observerAdd(Observer* beo);
void observerDel(Observer* beo);
void notify(int infos);
virtual ~Model();
private:
std::list<Observer*> observer_;
};
class aModel : public Model
{
public:
aModel() { ; }
~aModel() { ; }
void observerAdd(Observer* beo) { Model::observerAdd(beo); }
void observerDel(Observer* beo) { Model::observerDel(beo); }
void notify(int infos) { Model::notify(infos); }
};
}
#endif // ICC_MODELL_BETRACHTER_H