COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coConfigEditorController.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 //templates here. Observer for entry is coConfigEditorEntry
9 #ifndef COCONFIGOBSERVER
10 #define COCONFIGOBSERVER
11 #include <vector>
12 namespace covise
13 {
14 
15 template <class T>
16 class Observer
17 {
18 
19 public:
21  {
22  }
23  virtual ~Observer()
24  {
25  }
26 
27  virtual void update(T *subject) = 0;
28 };
29 
30 template <class T>
31 class Subject
32 {
33 public:
35  {
36  }
37  virtual ~Subject()
38  {
39  }
40 
41  void attach(Observer<T> &observer)
42  {
43  this->observers.push_back(&observer);
44  }
45 
46  void notify()
47  {
48  // vector<Observer<T> *>::iterator it;
49 
50  typename std::vector<Observer<T> *>::iterator it;
51  for (it = this->observers.begin();
52  it != this->observers.end();
53  ++it)
54  (*it)->update(static_cast<T *>(this));
55  }
56 
57 private:
58  std::vector<Observer<T> *> observers;
59 };
60 }
61 #endif
Definition: coConfigEditorController.h:16
virtual ~Subject()
Definition: coConfigEditorController.h:37
std::vector< Observer< T > * > observers
Definition: coConfigEditorController.h:58
Definition: coConfigEditorController.h:31
Observer()
Definition: coConfigEditorController.h:20
virtual void update(T *subject)=0
Subject()
Definition: coConfigEditorController.h:34
virtual ~Observer()
Definition: coConfigEditorController.h:23
void attach(Observer< T > &observer)
Definition: coConfigEditorController.h:41
void notify()
Definition: coConfigEditorController.h:46