void CStatsDisplay::Update(CWeatherData const & subject) { m_inStats.temperatureStats.Update(subject.GetTemperature()); m_inStats.humidityStats.Update(subject.GetHumidity()); m_inStats.pressureStats.Update(subject.GetPressure()); PrintWeatherData(); }
int main() { CWeatherData wdIndoor; CWeatherWindData wdOutdoor; const auto senderNameProvider = [](boost::variant<IObservable<SWeatherInfo>&, IObservable<SWeatherInfoWind>&> sender) { return sender.apply_visitor(SenderNameProviderVisitor()); }; CDisplay display(senderNameProvider); wdIndoor.RegisterObserver(display.GetBasicObserver(), 0); wdOutdoor.RegisterObserver(display.GetWindObserver(), 0); CStatsDisplay statsDisplay(senderNameProvider); wdIndoor.RegisterObserver(statsDisplay.GetBasicObserver(), 0); wdOutdoor.RegisterObserver(statsDisplay.GetWindObserver(), 0); wdOutdoor.SetMeasurements(3, 0.7, 760, 2, 0); wdIndoor.SetMeasurements(15, 0.5, 762); wdOutdoor.SetMeasurements(4, 0.8, 761, 3, 10); wdIndoor.SetMeasurements(16, 0.6, 763); wdIndoor.RemoveObserver(statsDisplay.GetBasicObserver()); wdOutdoor.RemoveObserver(display.GetWindObserver()); wdOutdoor.SetMeasurements(10, 0.8, 761, 5, 100); wdIndoor.SetMeasurements(20, 0.6, 763); wdOutdoor.SetMeasurements(-10, 0.8, 761, 7, 145); wdIndoor.SetMeasurements(22, 0.6, 763); return 0; }
int main() { CWeatherData wdIn; CProWeatherData wdOut; CStatsDisplay statsDisplay(wdIn, wdOut); wdIn.SetMeasurements(7.1, 2.5, 760); wdOut.SetMeasurements(-5.5, 3.5, 765, 2.2, 60); CDisplay display(wdIn, wdOut); wdIn.SetMeasurements(17.2, 10.3, 760); wdOut.SetMeasurements(-6.5, 3.5, 765, 2.2, 60); return 0; }
int main() { CWeatherData wd; CDisplay display; wd.RegisterObserver(display); CStatsDisplay statsDisplay; wd.RegisterObserver(statsDisplay); wd.SetMeasurements(3, 0.7, 760); wd.SetMeasurements(4, 0.8, 761); wd.RemoveObserver(statsDisplay); wd.SetMeasurements(10, 0.8, 761); wd.SetMeasurements(-10, 0.8, 761); return 0; }