15 #ifndef BORNAGAIN_CORE_FITTING_FITOBSERVER_H
16 #define BORNAGAIN_CORE_FITTING_FITOBSERVER_H
28 using observer_t = std::function<void(
const T&)>;
40 void notify_all(
const T& data);
46 ObserverData() : m_every_nth(0) {}
47 ObserverData(
int every_nth, observer_t observer)
48 : m_every_nth(every_nth), m_observer(observer)
52 observer_t m_observer;
55 bool need_notify(
int every_nth);
57 std::vector<ObserverData> m_observers;
66 m_observers.push_back(ObserverData(every_nth, observer));
71 for (
const auto& observer : m_observers) {
72 if (need_notify(observer.m_every_nth))
73 observer.m_observer(data);
81 for (
const auto& observer : m_observers)
82 observer.m_observer(data);
89 return m_notify_count == 0 || m_notify_count % every_nth == 0;
Defines common types for fitting library.
Contains collection of observers and call them at specified intervals.
void notify(const T &data)
Notifies all observers at their personally specified intervals.
void addObserver(int every_nth, observer_t observer)
Adds observer to the list.