From 78363b689f4557c9f84f490c8ecaae78c2de7b48 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:23:00 +0200 Subject: [PATCH] a few more keller-tidy --- ecal/core/include/ecal/ecal_util.h | 4 +- ecal/core/src/ecal_descgate.cpp | 34 +++++----- ecal/core/src/ecal_descgate.h | 12 ++-- ecal/core/src/ecal_util.cpp | 65 +++++-------------- .../cpp/descgate_test/src/getpublisher.cpp | 8 +-- 5 files changed, 46 insertions(+), 77 deletions(-) diff --git a/ecal/core/include/ecal/ecal_util.h b/ecal/core/include/ecal/ecal_util.h index 6c50887..34976c9 100644 --- a/ecal/core/include/ecal/ecal_util.h +++ b/ecal/core/include/ecal/ecal_util.h @@ -64,7 +64,7 @@ namespace eCAL bool operator<(const SQualityTopicInfo& other) const { - return id <= other.id; + return std::tie(quality, id) < std::tie(other.quality, other.id); } }; using QualityTopicInfoMultiMap = std::multimap; @@ -79,7 +79,7 @@ namespace eCAL bool operator<(const SQualityServiceInfo& other) const { - return id <= other.id; + return std::tie(request_quality, response_quality, id) < std::tie(other.request_quality, other.response_quality, other.id); } }; struct SServiceMethod diff --git a/ecal/core/src/ecal_descgate.cpp b/ecal/core/src/ecal_descgate.cpp index 31e76d9..ea80fd0 100644 --- a/ecal/core/src/ecal_descgate.cpp +++ b/ecal/core/src/ecal_descgate.cpp @@ -52,52 +52,56 @@ namespace eCAL } CDescGate::~CDescGate() = default; - QualityTopicIdMap CDescGate::GetPublishers() + Util::QualityTopicInfoMultiMap CDescGate::GetPublishers() { return GetTopics(m_publisher_info_map); } - QualityTopicIdMap CDescGate::GetSubscribers() + Util::QualityTopicInfoMultiMap CDescGate::GetSubscribers() { return GetTopics(m_subscriber_info_map); } - QualityServiceIdMap CDescGate::GetServices() + Util::QualityServiceInfoMultimap CDescGate::GetServices() { return GetServices(m_service_info_map); } - QualityServiceIdMap CDescGate::GetClients() + Util::QualityServiceInfoMultimap CDescGate::GetClients() { return GetServices(m_client_info_map); } - QualityTopicIdMap CDescGate::GetTopics(SQualityTopicIdMap& topic_map_) + Util::QualityTopicInfoMultiMap CDescGate::GetTopics(SQualityTopicIdMap& topic_info_map_) { - QualityTopicIdMap map; + Util::QualityTopicInfoMultiMap multi_map; - const std::lock_guard lock(topic_map_.mtx); - topic_map_.map.remove_deprecated(); + const std::lock_guard lock(topic_info_map_.mtx); + topic_info_map_.map.remove_deprecated(); - for (const auto& topic_map_it : topic_map_.map) + for (const auto& topic_map_it : topic_info_map_.map) { - map.emplace(topic_map_it.first, topic_map_it.second); + multi_map.insert(std::pair(topic_map_it.first.topic_name, topic_map_it.second)); } - return map; + + return multi_map; } - QualityServiceIdMap CDescGate::GetServices(SQualityServiceIdMap& service_method_info_map_) + Util::QualityServiceInfoMultimap CDescGate::GetServices(SQualityServiceIdMap& service_method_info_map_) { - QualityServiceIdMap map; + Util::QualityServiceInfoMultimap multi_map; const std::lock_guard lock(service_method_info_map_.mtx); service_method_info_map_.map.remove_deprecated(); for (const auto& service_method_info_map_it : service_method_info_map_.map) { - map.emplace(service_method_info_map_it.first, service_method_info_map_it.second); + Util::SServiceMethod key; + key.service_name = service_method_info_map_it.first.service_name; + key.method_name = service_method_info_map_it.first.method_name; + multi_map.insert(std::pair(key, service_method_info_map_it.second)); } - return map; + return multi_map; } void CDescGate::ApplySample(const Registration::Sample& sample_, eTLayerType /*layer_*/) diff --git a/ecal/core/src/ecal_descgate.h b/ecal/core/src/ecal_descgate.h index c633cb6..7052797 100644 --- a/ecal/core/src/ecal_descgate.h +++ b/ecal/core/src/ecal_descgate.h @@ -73,12 +73,12 @@ namespace eCAL void ApplySample(const Registration::Sample& sample_, eTLayerType layer_); // get publisher/subscriber maps - QualityTopicIdMap GetPublishers(); - QualityTopicIdMap GetSubscribers(); + Util::QualityTopicInfoMultiMap GetPublishers(); + Util::QualityTopicInfoMultiMap GetSubscribers(); // get service/clients maps - QualityServiceIdMap GetServices(); - QualityServiceIdMap GetClients(); + Util::QualityServiceInfoMultimap GetServices(); + Util::QualityServiceInfoMultimap GetClients(); // delete copy constructor and copy assignment operator CDescGate(const CDescGate&) = delete; @@ -105,8 +105,8 @@ namespace eCAL QualityServiceIdExpMap map; }; - static QualityTopicIdMap GetTopics(SQualityTopicIdMap& topic_map_); - static QualityServiceIdMap GetServices(SQualityServiceIdMap& service_method_info_map_); + static Util::QualityTopicInfoMultiMap GetTopics (SQualityTopicIdMap& topic_info_map_); + static Util::QualityServiceInfoMultimap GetServices(SQualityServiceIdMap& service_method_info_map_); static void ApplyTopicDescription(SQualityTopicIdMap& topic_info_map_, const std::string& topic_name_, diff --git a/ecal/core/src/ecal_util.cpp b/ecal/core/src/ecal_util.cpp index 6b905f1..c2abf92 100644 --- a/ecal/core/src/ecal_util.cpp +++ b/ecal/core/src/ecal_util.cpp @@ -84,7 +84,7 @@ namespace * * @return std::map **/ - std::map ReduceQualityTopicIdMap(const eCAL::QualityTopicIdMap& source_map_) + std::map ReduceQualityTopicIdMap(const eCAL::Util::QualityTopicInfoMultiMap& source_map_) { std::map target_map; @@ -93,7 +93,7 @@ namespace const auto& source_key = source_pair.first; const auto& source_value = source_pair.second; - auto target_it = target_map.find(source_key.topic_name); + auto target_it = target_map.find(source_key); if (target_it != target_map.end()) { // key exists in target map @@ -106,7 +106,7 @@ namespace else { // key does not exist in target map, insert source pair - target_map.insert(std::make_pair(source_key.topic_name, source_value)); + target_map.insert(std::make_pair(source_key, source_value)); } } @@ -121,13 +121,13 @@ namespace * * @return std::map, SQualityServiceInfo> **/ - std::map ReduceQualityServiceIdMap(const eCAL::QualityServiceIdMap& source_map_) + std::map ReduceQualityServiceIdMap(const eCAL::Util::QualityServiceInfoMultimap& source_map_) { std::map target_map; for (const auto& source_pair : source_map_) { - const auto& source_key = source_pair.first; + const auto& source_key = source_pair.first; const auto& source_value = source_pair.second; eCAL::Util::SServiceMethod key; @@ -300,16 +300,8 @@ namespace eCAL QualityTopicInfoMultiMap GetPublishers() { - QualityTopicInfoMultiMap multi_map; - if (g_descgate() == nullptr) return multi_map; - - // insert publisher into target multimap - for (const auto& topic : g_descgate()->GetPublishers()) - { - multi_map.insert(std::pair(topic.first.topic_name, topic.second)); - } - - return multi_map; + if (g_descgate() == nullptr) return QualityTopicInfoMultiMap(); + return g_descgate()->GetPublishers(); } std::set GetPublishers(const std::string& topic_name_) @@ -319,16 +311,8 @@ namespace eCAL QualityTopicInfoMultiMap GetSubscribers() { - QualityTopicInfoMultiMap multi_map; - if (g_descgate() == nullptr) return multi_map; - - // insert subscriber into target multimap - for (const auto& topic : g_descgate()->GetSubscribers()) - { - multi_map.insert(std::pair(topic.first.topic_name, topic.second)); - } - - return multi_map; + if (g_descgate() == nullptr) return QualityTopicInfoMultiMap(); + return g_descgate()->GetSubscribers(); } std::set GetSubscribers(const std::string& topic_name_) @@ -352,34 +336,15 @@ namespace eCAL QualityServiceInfoMultimap GetServices() { QualityServiceInfoMultimap multi_map; - if (g_descgate() == nullptr) return multi_map; - - // insert services into target multimap - for (const auto& service : g_descgate()->GetServices()) - { - SServiceMethod key; - key.service_name = service.first.service_name; - key.method_name = service.first.method_name; - multi_map.insert(std::pair(key, service.second)); - } - return multi_map; + if (g_descgate() == nullptr) return QualityServiceInfoMultimap(); + return g_descgate()->GetServices(); } QualityServiceInfoMultimap GetClients() { QualityServiceInfoMultimap multi_map; - if (g_descgate() == nullptr) return multi_map; - - // insert clients into target multimap - for (const auto& client : g_descgate()->GetClients()) - { - SServiceMethod key; - key.service_name = client.first.service_name; - key.method_name = client.first.method_name; - multi_map.insert(std::pair(key, client.second)); - } - - return multi_map; + if (g_descgate() == nullptr) return QualityServiceInfoMultimap(); + return g_descgate()->GetClients(); } SServiceMethodInformation GetHighestQualityServiceMethodInformation(const std::set& quality_service_info_set_) @@ -415,8 +380,8 @@ namespace eCAL quality_topic_info_map_.clear(); if (g_descgate() == nullptr) return; - QualityTopicIdMap pub_sub_map = g_descgate()->GetPublishers(); - QualityTopicIdMap sub_map = g_descgate()->GetSubscribers(); + QualityTopicInfoMultiMap pub_sub_map = g_descgate()->GetPublishers(); + QualityTopicInfoMultiMap sub_map = g_descgate()->GetSubscribers(); pub_sub_map.insert(sub_map.begin(), sub_map.end()); // transform into a map with the highest quality data type information diff --git a/ecal/tests/cpp/descgate_test/src/getpublisher.cpp b/ecal/tests/cpp/descgate_test/src/getpublisher.cpp index 6ab1157..c631905 100644 --- a/ecal/tests/cpp/descgate_test/src/getpublisher.cpp +++ b/ecal/tests/cpp/descgate_test/src/getpublisher.cpp @@ -116,7 +116,7 @@ TEST(core_cpp_descgate, PublisherQualities) // check pub1 quality { - auto pub_it = sample_map.find({ "pub1", 1 }); + auto pub_it = sample_map.find("pub1"); EXPECT_NE(pub_it, sample_map.end()); if (pub_it != sample_map.end()) { @@ -129,7 +129,7 @@ TEST(core_cpp_descgate, PublisherQualities) // check pub2 quality { - auto pub_it = sample_map.find({ "pub2", 2 }); + auto pub_it = sample_map.find("pub2"); EXPECT_NE(pub_it, sample_map.end()); if (pub_it != sample_map.end()) { @@ -205,7 +205,7 @@ TEST(core_cpp_descgate, SubscriberQualities) // check sub1 quality { - auto sub_it = sample_map.find({ "sub1", 1 }); + auto sub_it = sample_map.find("sub1"); EXPECT_NE(sub_it, sample_map.end()); if (sub_it != sample_map.end()) { @@ -218,7 +218,7 @@ TEST(core_cpp_descgate, SubscriberQualities) // check sub2 quality { - auto sub_it = sample_map.find({ "sub2", 2 }); + auto sub_it = sample_map.find("sub2"); EXPECT_NE(sub_it, sample_map.end()); if (sub_it != sample_map.end()) {