[084729c] | 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 "CodePatterns/Observer/Observer.hpp"
|
---|
| 12 | #include "CodePatterns/Observer/Observable.hpp"
|
---|
| 13 | #include "CodePatterns/Observer/ObservedIterator.hpp"
|
---|
| 14 | #include "CodePatterns/Observer/Relay.hpp"
|
---|
| 15 |
|
---|
| 16 | class UpdateCountObserver : public Observer {
|
---|
| 17 | public:
|
---|
| 18 | UpdateCountObserver();
|
---|
| 19 | virtual ~UpdateCountObserver();
|
---|
| 20 |
|
---|
| 21 | void update(Observable *publisher);
|
---|
| 22 | void subjectKilled(Observable *publisher);
|
---|
| 23 |
|
---|
| 24 | int updates;
|
---|
| 25 | };
|
---|
| 26 |
|
---|
| 27 | class SimpleObservable : public Observable {
|
---|
| 28 | public:
|
---|
| 29 | SimpleObservable();
|
---|
| 30 |
|
---|
| 31 | void changeMethod();
|
---|
| 32 | };
|
---|
| 33 |
|
---|
| 34 | class CallObservable : public Observable {
|
---|
| 35 | public:
|
---|
| 36 | CallObservable();
|
---|
| 37 |
|
---|
| 38 | void changeMethod1();
|
---|
| 39 | void changeMethod2();
|
---|
| 40 | };
|
---|
| 41 |
|
---|
| 42 | class BlockObservable : public Observable {
|
---|
| 43 | public:
|
---|
| 44 | BlockObservable();
|
---|
| 45 |
|
---|
| 46 | void changeMethod1();
|
---|
| 47 | void changeMethod2();
|
---|
| 48 |
|
---|
| 49 | void internalMethod1();
|
---|
| 50 | void internalMethod2();
|
---|
| 51 |
|
---|
| 52 | void noChangeMethod();
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 | class SuperObservable : public Observable {
|
---|
| 56 | public:
|
---|
| 57 | SuperObservable();
|
---|
| 58 | virtual ~SuperObservable();
|
---|
| 59 |
|
---|
| 60 | void changeMethod();
|
---|
| 61 |
|
---|
| 62 | SimpleObservable *subObservable;
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | class NotificationObservable : public Observable {
|
---|
| 66 | public:
|
---|
| 67 | NotificationObservable();
|
---|
| 68 | virtual ~NotificationObservable();
|
---|
| 69 |
|
---|
| 70 | enum NotificationType {
|
---|
| 71 | Operation1Notify = 0,
|
---|
| 72 | Operation2Notify = 1
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | void operation1();
|
---|
| 76 | void operation2();
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | class NotificationObserver : public Observer {
|
---|
| 80 | public:
|
---|
| 81 | NotificationObserver(Notification_ptr notification);
|
---|
| 82 | virtual ~NotificationObserver();
|
---|
| 83 |
|
---|
| 84 | void update(Observable*);
|
---|
| 85 | void subjectKilled(Observable*);
|
---|
| 86 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 87 |
|
---|
| 88 | Notification_ptr requestedNotification;
|
---|
| 89 |
|
---|
| 90 | bool wasNotified;
|
---|
| 91 | };
|
---|
| 92 |
|
---|
| 93 | class ObservableSet : public Observable {
|
---|
| 94 | public:
|
---|
| 95 | typedef std::set<SimpleObservable*> set;
|
---|
| 96 | typedef ObservedIterator<set> iterator;
|
---|
| 97 | typedef set::const_iterator const_iterator;
|
---|
| 98 |
|
---|
| 99 | ObservableSet(int _num);
|
---|
| 100 | virtual ~ObservableSet();
|
---|
| 101 |
|
---|
| 102 | iterator begin();
|
---|
| 103 | iterator end();
|
---|
| 104 |
|
---|
| 105 | const int num;
|
---|
| 106 |
|
---|
| 107 | private:
|
---|
| 108 | set theSet;
|
---|
| 109 | };
|
---|
| 110 |
|
---|
| 111 | class ObservableMap : public Observable {
|
---|
| 112 | public:
|
---|
| 113 | typedef std::map<int,SimpleObservable*> set;
|
---|
| 114 | typedef ObservedIterator<set> iterator;
|
---|
| 115 | typedef set::const_iterator const_iterator;
|
---|
| 116 |
|
---|
| 117 | ObservableMap(int _num);
|
---|
| 118 | virtual ~ObservableMap();
|
---|
| 119 |
|
---|
| 120 | iterator begin();
|
---|
| 121 | iterator end();
|
---|
| 122 |
|
---|
| 123 | const int num;
|
---|
| 124 |
|
---|
| 125 | private:
|
---|
| 126 | set theSet;
|
---|
| 127 | };
|
---|
| 128 |
|
---|
| 129 | class RelayTest : public Relay
|
---|
| 130 | {
|
---|
| 131 | public:
|
---|
| 132 | RelayTest();
|
---|
| 133 | ~RelayTest();
|
---|
| 134 | private:
|
---|
| 135 | };
|
---|
| 136 |
|
---|
| 137 | class RelayCountObserver : public Observer {
|
---|
| 138 | public:
|
---|
| 139 | RelayCountObserver(const Observable * const relay);
|
---|
| 140 | virtual ~RelayCountObserver();
|
---|
| 141 |
|
---|
| 142 | void update(Observable *publisher);
|
---|
| 143 | void subjectKilled(Observable *publisher);
|
---|
| 144 |
|
---|
| 145 | int updates;
|
---|
| 146 | private:
|
---|
| 147 | const Observable * const relay;
|
---|
| 148 | };
|
---|
| 149 |
|
---|
| 150 | class RelayNotification : public Relay
|
---|
| 151 | {
|
---|
| 152 | public:
|
---|
| 153 | RelayNotification();
|
---|
| 154 | ~RelayNotification();
|
---|
| 155 | private:
|
---|
| 156 | };
|
---|
| 157 |
|
---|
| 158 | class RelayNotificationObserver : public Observer {
|
---|
| 159 | public:
|
---|
| 160 | RelayNotificationObserver(const Observable * const _relay);
|
---|
| 161 | virtual ~RelayNotificationObserver();
|
---|
| 162 |
|
---|
| 163 | void update(Observable*);
|
---|
| 164 | void subjectKilled(Observable*);
|
---|
| 165 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
---|
| 166 |
|
---|
| 167 | bool wasNotified;
|
---|
| 168 | private:
|
---|
| 169 | const Observable * const relay;
|
---|
| 170 | };
|
---|
| 171 |
|
---|
| 172 | #endif /* OBSERVERSTUB_HPP_ */
|
---|