From 42d98c3b4595e17032c9a19656a639a60e6fa8ac Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 3 Sep 2016 16:38:44 -0700 Subject: [PATCH] RecentEntries: Remove Packet template arg. --- firmware/application/ais_app.cpp | 7 ++++--- firmware/application/ais_app.hpp | 2 +- firmware/application/ert_app.cpp | 3 ++- firmware/application/ert_app.hpp | 2 +- firmware/application/recent_entries.hpp | 9 +++------ firmware/application/tpms_app.cpp | 3 ++- firmware/application/tpms_app.hpp | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index cb9e1ef88..049acf71d 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -336,12 +336,13 @@ void AISAppView::on_packet(const ais::Packet& packet) { logger->on_packet(packet); } - const auto updated_entry = recent.on_packet(packet.source_id(), packet); + auto& entry = recent.on_packet(packet.source_id()); + entry.update(packet); recent_entries_view.set_dirty(); // TODO: Crude hack, should be a more formal listener arrangement... - if( updated_entry.key() == recent_entry_detail_view.entry().key() ) { - recent_entry_detail_view.set_entry(updated_entry); + if( entry.key() == recent_entry_detail_view.entry().key() ) { + recent_entry_detail_view.set_entry(entry); } } diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 10da06a24..556002e13 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -91,7 +91,7 @@ struct AISRecentEntry { void update(const ais::Packet& packet); }; -using AISRecentEntries = RecentEntries; +using AISRecentEntries = RecentEntries; class AISLogger { public: diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index d02133c82..fcfc9b1e8 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -150,7 +150,8 @@ void ERTAppView::on_packet(const ert::Packet& packet) { } if( packet.crc_ok() ) { - recent.on_packet({ packet.id(), packet.commodity_type() }, packet); + auto& entry = recent.on_packet({ packet.id(), packet.commodity_type() }); + entry.update(packet); recent_entries_view.set_dirty(); } } diff --git a/firmware/application/ert_app.hpp b/firmware/application/ert_app.hpp index cba9e74a3..49c7701e5 100644 --- a/firmware/application/ert_app.hpp +++ b/firmware/application/ert_app.hpp @@ -100,7 +100,7 @@ private: LogFile log_file; }; -using ERTRecentEntries = RecentEntries; +using ERTRecentEntries = RecentEntries; namespace ui { diff --git a/firmware/application/recent_entries.hpp b/firmware/application/recent_entries.hpp index 0f899ed0d..9c23bde6b 100644 --- a/firmware/application/recent_entries.hpp +++ b/firmware/application/recent_entries.hpp @@ -33,7 +33,7 @@ #include #include -template +template class RecentEntries { public: using EntryType = Entry; @@ -43,7 +43,7 @@ public: using const_iterator = typename ContainerType::const_iterator; using RangeType = std::pair; - const EntryType& on_packet(const Key key, const Packet& packet) { + EntryType& on_packet(const Key key) { auto matching_recent = find(key); if( matching_recent != std::end(entries) ) { // Found within. Move to front of list, increment counter. @@ -54,10 +54,7 @@ public: truncate_entries(); } - auto& entry = entries.front(); - entry.update(packet); - - return entry; + return entries.front(); } const_reference front() const { diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 9da4fce69..a00ff16f1 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -199,7 +199,8 @@ void TPMSAppView::on_packet(const tpms::Packet& packet) { const auto reading_opt = packet.reading(); if( reading_opt.is_valid() ) { const auto reading = reading_opt.value(); - recent.on_packet({ reading.type(), reading.id() }, reading); + auto& entry = recent.on_packet({ reading.type(), reading.id() }); + entry.update(reading); recent_entries_view.set_dirty(); } } diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index 98715219a..c294862eb 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -72,7 +72,7 @@ struct TPMSRecentEntry { void update(const tpms::Reading& reading); }; -using TPMSRecentEntries = RecentEntries; +using TPMSRecentEntries = RecentEntries; class TPMSLogger { public: