From 0aa35210a478610361804df467d7ff862c52848a Mon Sep 17 00:00:00 2001 From: Wouter van Kleunen Date: Sun, 18 Oct 2020 08:07:04 +0200 Subject: [PATCH] Failed to reset value in retained_map on erase --- test/retained_topic_map.cpp | 1 + test/retained_topic_map.hpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/test/retained_topic_map.cpp b/test/retained_topic_map.cpp index 136201d51..6cca5fa30 100644 --- a/test/retained_topic_map.cpp +++ b/test/retained_topic_map.cpp @@ -139,6 +139,7 @@ BOOST_AUTO_TEST_CASE(erase_upper_first) { map.insert_or_update("a/b", "2"); auto e1 = map.erase("a/b"); // erase upper first + BOOST_TEST(e1 == 1); { std::set match { diff --git a/test/retained_topic_map.hpp b/test/retained_topic_map.hpp index e756ffb90..a78bf984b 100644 --- a/test/retained_topic_map.hpp +++ b/test/retained_topic_map.hpp @@ -15,6 +15,7 @@ #include #include +#include #include "topic_filter_tokenizer.hpp" template @@ -197,6 +198,10 @@ class retained_topic_map { bool erase_topic(MQTT_NS::string_view topic) { auto path = find_topic(topic); + // Reset the value + if(!path.empty()) + path.back()->second.value = MQTT_NS::nullopt; + for (auto entry : boost::adaptors::reverse(path)) { --entry->second.count; if (entry->second.count == 0) { @@ -243,6 +248,14 @@ class retained_topic_map { // Get the size of the map std::size_t size() const { return map.size(); } + // Dump debug information + template + void dump(Output &out) { + for (auto const& i: map) { + out << i.first.first << " " << i.first.second << " " << (i.second.value ? "init" : "-") << " " << i.second.count << std::endl; + } + } + }; #endif // MQTT_RETAINED_TOPIC_MAP_HPP