source: src/Patterns/unittests/stubs/ObserverStub.hpp@ 74e0f7

Last change on this file since 74e0f7 was 74e0f7, checked in by Frederik Heber <heber@…>, 14 years ago

Extended Observables by NotificationChannels member variable.

  • new class Channels that aggregates Notifications.
  • NOTIFY now just takes a channel number.
  • may or may not be instantiated for a given Observable.
  • Observable just needs to add enum of all desired channels and addChannel on each of these.
  • ObserverUnitTest has been adapted.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * ObserverStub.hpp
3 *
4 * Created on: Jan 16, 2011
5 * Author: heber
6 */
7
8#ifndef OBSERVERSTUB_HPP_
9#define OBSERVERSTUB_HPP_
10
11#include "Observer.hpp"
12#include "ObservedIterator.hpp"
13
14class UpdateCountObserver : public Observer {
15public:
16 UpdateCountObserver();
17 virtual ~UpdateCountObserver();
18
19 void update(Observable *publisher);
20 void subjectKilled(Observable *publisher);
21
22 int updates;
23};
24
25class SimpleObservable : public Observable {
26public:
27 SimpleObservable();
28
29 void changeMethod();
30};
31
32class CallObservable : public Observable {
33public:
34 CallObservable();
35
36 void changeMethod1();
37 void changeMethod2();
38};
39
40class BlockObservable : public Observable {
41public:
42 BlockObservable();
43
44 void changeMethod1();
45 void changeMethod2();
46
47 void internalMethod1();
48 void internalMethod2();
49
50 void noChangeMethod();
51};
52
53class SuperObservable : public Observable {
54public:
55 SuperObservable();
56 virtual ~SuperObservable();
57
58 void changeMethod();
59
60 SimpleObservable *subObservable;
61};
62
63class NotificationObservable : public Observable {
64public:
65 NotificationObservable();
66 virtual ~NotificationObservable();
67
68 enum NotificationType {
69 Operation1Notify = 0,
70 Operation2Notify = 1
71 };
72
73 void operation1();
74 void operation2();
75};
76
77class NotificationObserver : public Observer {
78public:
79 NotificationObserver(Notification_ptr notification);
80 virtual ~NotificationObserver();
81
82 void update(Observable*);
83 void subjectKilled(Observable*);
84 void recieveNotification(Observable *publisher, Notification_ptr notification);
85
86 Notification_ptr requestedNotification;
87
88 bool wasNotified;
89};
90
91class ObservableSet : public Observable {
92public:
93 typedef std::set<SimpleObservable*> set;
94 typedef ObservedIterator<set> iterator;
95 typedef set::const_iterator const_iterator;
96
97 ObservableSet(int _num);
98 virtual ~ObservableSet();
99
100 iterator begin();
101 iterator end();
102
103 const int num;
104
105private:
106 set theSet;
107};
108
109class ObservableMap : public Observable {
110public:
111 typedef std::map<int,SimpleObservable*> set;
112 typedef ObservedIterator<set> iterator;
113 typedef set::const_iterator const_iterator;
114
115 ObservableMap(int _num);
116 virtual ~ObservableMap();
117
118 iterator begin();
119 iterator end();
120
121 const int num;
122
123private:
124 set theSet;
125};
126
127
128#endif /* OBSERVERSTUB_HPP_ */
Note: See TracBrowser for help on using the repository browser.