From 392788b1db2d60cd73cac12e58fbc4e6ce304d9e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 6 Apr 2015 14:26:24 -0500 Subject: in SimpleAlarmQueue, add a new method 'bool already_triggered() const' to reduce code overlapl between find_next_alarm() and appointment_get_current_alarm() --- src/alarm-queue-simple.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/alarm-queue-simple.cpp') diff --git a/src/alarm-queue-simple.cpp b/src/alarm-queue-simple.cpp index 19e5208..921e8d2 100644 --- a/src/alarm-queue-simple.cpp +++ b/src/alarm-queue-simple.cpp @@ -103,6 +103,12 @@ private: } } + bool already_triggered (const Appointment& appt, const Alarm& alarm) const + { + const std::pair key{appt.uid, alarm.time}; + return m_triggered.count(key) != 0; + } + // return the next Alarm (if any) that will kick now or in the future const Alarm* find_next_alarm(const std::vector& appointments) const { @@ -116,8 +122,7 @@ private: { for(const auto& alarm : appointment.alarms) { - const std::pair trig{appointment.uid, alarm.time}; - if (m_triggered.count(trig)) + if (already_triggered(appointment, alarm)) continue; if (alarm.time < beginning_of_minute) // has this one already passed? @@ -139,14 +144,8 @@ private: const auto now = m_clock->localtime(); for (const auto& alarm : appointment.alarms) - { - const std::pair trig{appointment.uid, alarm.time}; - if (m_triggered.count(trig)) // did we already use this one? - continue; - - if (DateTime::is_same_minute(now, alarm.time)) + if (!already_triggered(appointment, alarm) && DateTime::is_same_minute(now, alarm.time)) return &alarm; - } return nullptr; } -- cgit v1.2.3