| 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 |
|
|---|
| 14 | class UpdateCountObserver : public Observer {
|
|---|
| 15 | public:
|
|---|
| 16 | UpdateCountObserver();
|
|---|
| 17 | void update(Observable *publisher);
|
|---|
| 18 | void subjectKilled(Observable *publisher);
|
|---|
| 19 |
|
|---|
| 20 | int updates;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | class SimpleObservable : public Observable {
|
|---|
| 24 | public:
|
|---|
| 25 | SimpleObservable();
|
|---|
| 26 |
|
|---|
| 27 | void changeMethod();
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | class CallObservable : public Observable {
|
|---|
| 31 | public:
|
|---|
| 32 | CallObservable();
|
|---|
| 33 |
|
|---|
| 34 | void changeMethod1();
|
|---|
| 35 | void changeMethod2();
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | class BlockObservable : public Observable {
|
|---|
| 39 | public:
|
|---|
| 40 | BlockObservable();
|
|---|
| 41 |
|
|---|
| 42 | void changeMethod1();
|
|---|
| 43 | void changeMethod2();
|
|---|
| 44 |
|
|---|
| 45 | void internalMethod1();
|
|---|
| 46 | void internalMethod2();
|
|---|
| 47 |
|
|---|
| 48 | void noChangeMethod();
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | class SuperObservable : public Observable {
|
|---|
| 52 | public:
|
|---|
| 53 | SuperObservable();
|
|---|
| 54 | ~SuperObservable();
|
|---|
| 55 |
|
|---|
| 56 | void changeMethod();
|
|---|
| 57 |
|
|---|
| 58 | SimpleObservable *subObservable;
|
|---|
| 59 | };
|
|---|
| 60 |
|
|---|
| 61 | class NotificationObservable : public Observable {
|
|---|
| 62 | public:
|
|---|
| 63 | NotificationObservable();
|
|---|
| 64 | ~NotificationObservable();
|
|---|
| 65 |
|
|---|
| 66 | void operation1();
|
|---|
| 67 | void operation2();
|
|---|
| 68 |
|
|---|
| 69 | Notification_ptr notification1;
|
|---|
| 70 | Notification_ptr notification2;
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | class NotificationObserver : public Observer {
|
|---|
| 74 | public:
|
|---|
| 75 | NotificationObserver(Notification_ptr notification);
|
|---|
| 76 |
|
|---|
| 77 | void update(Observable*);
|
|---|
| 78 | void subjectKilled(Observable*);
|
|---|
| 79 | void recieveNotification(Observable *publisher, Notification_ptr notification);
|
|---|
| 80 |
|
|---|
| 81 | Notification_ptr requestedNotification;
|
|---|
| 82 |
|
|---|
| 83 | bool wasNotified;
|
|---|
| 84 | };
|
|---|
| 85 |
|
|---|
| 86 | class ObservableSet : public Observable {
|
|---|
| 87 | public:
|
|---|
| 88 | typedef std::set<SimpleObservable*> set;
|
|---|
| 89 | typedef ObservedIterator<set> iterator;
|
|---|
| 90 | typedef set::const_iterator const_iterator;
|
|---|
| 91 |
|
|---|
| 92 | ObservableSet(int _num);
|
|---|
| 93 | ~ObservableSet();
|
|---|
| 94 |
|
|---|
| 95 | iterator begin();
|
|---|
| 96 | iterator end();
|
|---|
| 97 |
|
|---|
| 98 | const int num;
|
|---|
| 99 |
|
|---|
| 100 | private:
|
|---|
| 101 | set theSet;
|
|---|
| 102 | };
|
|---|
| 103 |
|
|---|
| 104 | class ObservableMap : public Observable {
|
|---|
| 105 | public:
|
|---|
| 106 | typedef std::map<int,SimpleObservable*> set;
|
|---|
| 107 | typedef ObservedIterator<set> iterator;
|
|---|
| 108 | typedef set::const_iterator const_iterator;
|
|---|
| 109 |
|
|---|
| 110 | ObservableMap(int _num);
|
|---|
| 111 | ~ObservableMap();
|
|---|
| 112 |
|
|---|
| 113 | iterator begin();
|
|---|
| 114 | iterator end();
|
|---|
| 115 |
|
|---|
| 116 | const int num;
|
|---|
| 117 |
|
|---|
| 118 | private:
|
|---|
| 119 | set theSet;
|
|---|
| 120 | };
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | #endif /* OBSERVERSTUB_HPP_ */
|
|---|