Skip to content

Commit

Permalink
a few more keller-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Apr 24, 2024
1 parent ba81137 commit 78363b6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 77 deletions.
4 changes: 2 additions & 2 deletions ecal/core/include/ecal/ecal_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, SQualityTopicInfo>;
Expand All @@ -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
Expand Down
34 changes: 19 additions & 15 deletions ecal/core/src/ecal_descgate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(topic_map_.mtx);
topic_map_.map.remove_deprecated();
const std::lock_guard<std::mutex> 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<std::string, Util::SQualityTopicInfo>(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<std::mutex> 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<Util::SServiceMethod, Util::SQualityServiceInfo>(key, service_method_info_map_it.second));
}
return map;
return multi_map;
}

void CDescGate::ApplySample(const Registration::Sample& sample_, eTLayerType /*layer_*/)
Expand Down
12 changes: 6 additions & 6 deletions ecal/core/src/ecal_descgate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_,
Expand Down
65 changes: 15 additions & 50 deletions ecal/core/src/ecal_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace
*
* @return std::map<TopicName, SQualityTopicInfo>
**/
std::map<std::string, eCAL::Util::SQualityTopicInfo> ReduceQualityTopicIdMap(const eCAL::QualityTopicIdMap& source_map_)
std::map<std::string, eCAL::Util::SQualityTopicInfo> ReduceQualityTopicIdMap(const eCAL::Util::QualityTopicInfoMultiMap& source_map_)
{
std::map<std::string, eCAL::Util::SQualityTopicInfo> target_map;

Expand All @@ -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
Expand All @@ -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));
}
}

Expand All @@ -121,13 +121,13 @@ namespace
*
* @return std::map<std::tuple<ServiceName, MethodName>, SQualityServiceInfo>
**/
std::map<eCAL::Util::SServiceMethod, eCAL::Util::SQualityServiceInfo> ReduceQualityServiceIdMap(const eCAL::QualityServiceIdMap& source_map_)
std::map<eCAL::Util::SServiceMethod, eCAL::Util::SQualityServiceInfo> ReduceQualityServiceIdMap(const eCAL::Util::QualityServiceInfoMultimap& source_map_)
{
std::map<eCAL::Util::SServiceMethod, eCAL::Util::SQualityServiceInfo> 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;
Expand Down Expand Up @@ -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<std::string, SQualityTopicInfo>(topic.first.topic_name, topic.second));
}

return multi_map;
if (g_descgate() == nullptr) return QualityTopicInfoMultiMap();
return g_descgate()->GetPublishers();
}

std::set<SQualityTopicInfo> GetPublishers(const std::string& topic_name_)
Expand All @@ -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<std::string, SQualityTopicInfo>(topic.first.topic_name, topic.second));
}

return multi_map;
if (g_descgate() == nullptr) return QualityTopicInfoMultiMap();
return g_descgate()->GetSubscribers();
}

std::set<SQualityTopicInfo> GetSubscribers(const std::string& topic_name_)
Expand All @@ -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<SServiceMethod, SQualityServiceInfo>(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<SServiceMethod, SQualityServiceInfo>(key, client.second));
}

return multi_map;
if (g_descgate() == nullptr) return QualityServiceInfoMultimap();
return g_descgate()->GetClients();
}

SServiceMethodInformation GetHighestQualityServiceMethodInformation(const std::set<SQualityServiceInfo>& quality_service_info_set_)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ecal/tests/cpp/descgate_test/src/getpublisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
{
Expand All @@ -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())
{
Expand Down

0 comments on commit 78363b6

Please sign in to comment.