8 class MonitoredValueController;
14 template<
typename _T_>
18 MonitoredValue(
const _T_& _init) : d(
new Private{{}, _init, 0, {}}) {}
26 std::size_t
addMonitor(
const std::function<
void(
const _T_& _value)>& _function);
27 void removeMonitor(std::size_t _idx);
34 QMap<std::size_t, std::function<void(
const _T_& _value)>> monitors;
39 template<
typename _T_>
44 template<
typename _T_>
45 MonitoredValue<_T_>& MonitoredValue<_T_>::operator=(
const MonitoredValue& _rhs)
51 template<
typename _T_>
52 MonitoredValue<_T_>::~MonitoredValue()
56 template<
typename _T_>
62 template<
typename _T_>
66 QMutexLocker l(&d->m);
67 std::size_t
id = d->nextId++;
68 d->monitors[id] = _function;
72 template<
typename _T_>
75 QMutexLocker l(&d->m);
76 d->monitors.remove(_idx);
85 template<
typename _T_>
98 template<
typename _T_>
100 : m_value(_initial_value)
104 template<
typename _T_>
105 MonitoredValueController<_T_>::~MonitoredValueController()
109 template<
typename _T_>
112 QMutexLocker l(&m_value.d->m);
113 m_value.d->value = _value;
114 for(
const std::function<
void(
const _T_&)>& monitor : m_value.d->monitors)
120 template<
typename _T_>
Definition MonitoredValue.h:87
void setValue(const _T_ &_value)
Set the value and trigger the monitors.
Definition MonitoredValue.h:110
Definition MonitoredValue.h:16
std::size_t addMonitor(const std::function< void(const _T_ &_value)> &_function)
Add a monitor, which is called when the value is changed by the controller.
Definition MonitoredValue.h:64
_T_ value() const
Definition MonitoredValue.h:57