Skip to content

Commit 6e5ff5b

Browse files
committed
Rename remove to erase in subscription_map, for multiple_subscription_map return the number of elements that were removed
1 parent e7f0efc commit 6e5ff5b

File tree

2 files changed

+11
-37
lines changed

2 files changed

+11
-37
lines changed

test/subscription_map.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ BOOST_AUTO_TEST_CASE( multi_non_wc_crud ) {
255255
auto& idx = scos.get<tag_con_topic_filter>();
256256
auto it = idx.find(std::make_tuple(con1, "a/b/c"_mb));
257257
BOOST_TEST((it != idx.end()));
258-
m.remove(it->h, *it);
258+
m.erase(it->h, *it);
259259
idx.erase(it);
260260
m.find(
261261
"a/b/c",
@@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE( multi_non_wc_crud ) {
292292
auto const& elem = *it;
293293
// call remove for each handle - Value pairs
294294
// it is a little inefficient but still enough efficient
295-
m.remove(elem.h, elem);
295+
m.erase(elem.h, elem);
296296
++it;
297297
}
298298
idx.erase(r.first, r.second);
@@ -435,7 +435,7 @@ BOOST_AUTO_TEST_CASE( multi_wc_crud ) {
435435
auto& idx = scos.get<tag_con_topic_filter>();
436436
auto it = idx.find(std::make_tuple(con1, "a/+/c"_mb));
437437
BOOST_TEST((it != idx.end()));
438-
m.remove(it->h, *it);
438+
m.erase(it->h, *it);
439439
idx.erase(it);
440440
m.find(
441441
"a/b/c",
@@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE( multi_wc_crud ) {
471471
auto const& elem = *it;
472472
// call remove for each handle - Value pairs
473473
// it is a little inefficient but still enough efficient
474-
m.remove(elem.h, elem);
474+
m.erase(elem.h, elem);
475475
++it;
476476
}
477477
idx.erase(r.first, r.second);

test/subscription_map.hpp

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class single_subscription_map
337337
}
338338

339339
// Remove a value at the specified subscription path
340-
void remove(MQTT_NS::string_view subscription) {
340+
void erase(MQTT_NS::string_view subscription) {
341341
auto path = this->find_subscription(subscription);
342342
if (path.empty()) {
343343
return;
@@ -347,7 +347,7 @@ class single_subscription_map
347347
}
348348

349349
// Remove a value using a handle
350-
void remove(handle h) {
350+
void erase(handle h) {
351351
auto path = this->handle_to_iterators(h);
352352
if (!path.empty()) {
353353
this->remove_subscription(path);
@@ -399,12 +399,12 @@ class multiple_subscription_map
399399

400400
auto& subscription_set = h_iter->second.value;
401401
bool insert_result = subscription_set.insert(std::move(value)).second;
402-
return std::make_pair(this->path_to_handle(path), insert_result);
402+
return std::make_pair(h, insert_result);
403403
}
404404

405405
// Remove a value at the specified subscription path
406406
// returns the value of the removed element (if found)
407-
boost::optional<Value> remove(MQTT_NS::string_view subscription, Value const& value) {
407+
size_t remove(MQTT_NS::string_view subscription, Value const& value) {
408408
// Find the subscription in the map
409409
auto path = this->find_subscription(subscription);
410410
if (path.empty()) {
@@ -413,25 +413,12 @@ class multiple_subscription_map
413413

414414
// Remove the specified value
415415
auto& subscription_set = path.back()->second.value;
416-
auto subscription_iter = subscription_set.find(value);
417-
if (subscription_iter != subscription_set.end()) {
418-
auto result = boost::make_optional(*subscription_iter);
419-
subscription_set.erase(subscription_iter);
420-
421-
// Remove the subscription when all entries are removed
422-
if (subscription_set.empty()) {
423-
this->remove_subscription(path);
424-
}
425-
426-
return result;
427-
}
428-
429-
return boost::optional<Value>();
416+
return subscription_set.erase(value);
430417
}
431418

432419
// Remove a value at the specified handle
433420
// returns the value of the removed element (if found)
434-
boost::optional<Value> remove(handle h, Value const& value) {
421+
size_t erase(handle h, Value const& value) {
435422
if (h.empty()) {
436423
throw std::runtime_error("Invalid handle was specified");
437424
}
@@ -443,20 +430,7 @@ class multiple_subscription_map
443430
}
444431

445432
auto& subscription_set = h_iter->second.value;
446-
auto subscription_iter = subscription_set.find(value);
447-
if (subscription_iter != subscription_set.end()) {
448-
auto result = boost::make_optional(*subscription_iter);
449-
subscription_set.erase(subscription_iter);
450-
451-
// Remove the subscription when all entries are removed
452-
if (subscription_set.empty()) {
453-
this->remove_subscription(this->handle_to_iterators(h));
454-
}
455-
456-
return result;
457-
}
458-
459-
return boost::optional<Value>();
433+
return subscription_set.erase(value);
460434
}
461435

462436
// Find all subscriptions that match the specified topic

0 commit comments

Comments
 (0)