aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/observer.hpp
blob: e4129c67b23e35541143addbfa39d2170b8d192a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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_);
	}
};