aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/observer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'signal-composer-binding/observer.hpp')
-rw-r--r--signal-composer-binding/observer.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/signal-composer-binding/observer.hpp b/signal-composer-binding/observer.hpp
new file mode 100644
index 0000000..e4129c6
--- /dev/null
+++ b/signal-composer-binding/observer.hpp
@@ -0,0 +1,30 @@
+#include <vector>
+
+class Observer
+{
+public:
+ virtual void update(double timestamp, double value) = 0;
+};
+
+class Subject
+{
+ double timestamp_;
+ double value_;
+ std::vector<Observer*> m_views;
+public:
+ void attach(Observer *obs)
+ {
+ m_views.push_back(obs);
+ }
+ void set_val(double timestamp, double value)
+ {
+ timestamp_ = timestamp;
+ value_ = value;
+ notify();
+ }
+ void notify()
+ {
+ for (int i = 0; i < m_views.size(); ++i)
+ m_views[i]->update(timestamp_, value_);
+ }
+};