Skip to content

Commit

Permalink
Perfect forwaring and some other arguments updated in subscription_ma…
Browse files Browse the repository at this point in the history
…p and retained_topic_map
  • Loading branch information
kleunen committed Oct 17, 2020
1 parent 362c5c3 commit 2ca44f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 4 additions & 2 deletions test/retained_topic_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ class retained_topic_map {
}

// Insert a value at the specified subscription path
void insert_or_update(MQTT_NS::string_view topic, Value const& value) {
this->create_topic(topic)->second.value = value;

template <typename V>
void insert_or_update(MQTT_NS::string_view topic, V&& value) {
this->create_topic(topic)->second.value = std::move(value);
}

// Find all stored topics that math the specified subscription
Expand Down
17 changes: 11 additions & 6 deletions test/subscription_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class subscription_map_base {
return result;
}

std::vector< map_type_iterator> find_subscription(MQTT_NS::string_view const& subscription) {
std::vector< map_type_iterator> find_subscription(MQTT_NS::string_view subscription) {
auto parent = root;
std::vector< map_type_iterator > path;

Expand Down Expand Up @@ -316,7 +316,8 @@ class single_subscription_map
using handle = typename subscription_map_base< Value >::handle;

// Insert a value at the specified subscription path
handle insert(MQTT_NS::string_view subscription, Value value) {
template <typename V>
handle insert(MQTT_NS::string_view subscription, V&& value) {
auto existing_subscription = this->find_subscription(subscription);
if (!existing_subscription.empty()) {
if(existing_subscription.back()->second.value)
Expand All @@ -331,7 +332,8 @@ class single_subscription_map
}

// Update a value at the specified subscription path
void update(MQTT_NS::string_view subscription, Value value) {
template <typename V>
void update(MQTT_NS::string_view subscription, V&& value) {
auto path = this->find_subscription(subscription);
if (path.empty()) {
throw std::runtime_error("Invalid subscription was specified");
Expand All @@ -340,7 +342,8 @@ class single_subscription_map
path.back()->second.value = std::move(value);
}

void update(handle h, Value value) {
template <typename V>
void update(handle h, V&& value) {
auto entry_iter = this->get_key(h.back());
if (entry_iter == this->end()) {
throw std::runtime_error("Invalid subscription was specified");
Expand Down Expand Up @@ -404,7 +407,8 @@ class multiple_subscription_map
using handle = typename subscription_map_base< Value >::handle;

// Insert a value at the specified subscription path
std::pair<handle, bool> insert(MQTT_NS::string_view subscription, Value value) {
template <typename V>
std::pair<handle, bool> insert(MQTT_NS::string_view subscription, V&& value) {
auto path = this->find_subscription(subscription);
if(path.empty()) {
auto new_subscription_path = this->create_subscription(subscription);
Expand All @@ -419,7 +423,8 @@ class multiple_subscription_map
}

// Insert a value with a handle to the subscription
std::pair<handle, bool> insert(handle h, Value value) {
template <typename V>
std::pair<handle, bool> insert(handle h, V&& value) {
if (h.empty()) {
throw std::runtime_error("Invalid handle was specified");
}
Expand Down

0 comments on commit 2ca44f1

Please sign in to comment.