-
Notifications
You must be signed in to change notification settings - Fork 1
/
var.h
41 lines (30 loc) · 774 Bytes
/
var.h
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
31
32
33
34
35
36
37
38
39
40
41
#ifndef JWUTIL_VAR_H
#define JWUTIL_VAR_H
#include "jw_util/signal.h"
namespace jw_util {
template <typename DataType, typename SignalType = const DataType &>
class Var {
private:
class ChangeSignal : public jw_util::SignalEmitter<SignalType> {
friend class Var<DataType, SignalType>;
};
public:
typedef typename jw_util::SignalEmitter<SignalType>::Listener ChangeListener;
Var(const DataType &initData)
: data(initData)
{}
const DataType &get() const {
return data;
}
void set(const DataType &newData) {
if (data != newData) {
data = newData;
onChange.trigger(data);
}
}
mutable ChangeSignal onChange;
private:
DataType data;
};
}
#endif // JWUTIL_VAR_H