Skip to content

Commit

Permalink
Failed to reset value in retained_map on erase
Browse files Browse the repository at this point in the history
  • Loading branch information
kleunen committed Oct 18, 2020
1 parent a86229f commit ae45fcf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/retained_topic_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> match {
Expand Down
12 changes: 12 additions & 0 deletions test/retained_topic_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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) {
Expand Down Expand Up @@ -243,6 +247,14 @@ class retained_topic_map {
// Get the size of the map
std::size_t size() const { return map.size(); }

// Dump debug information
template<typename Output>
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

0 comments on commit ae45fcf

Please sign in to comment.