From 7626af788bead957e1243dd3f4a668851c8d83fe Mon Sep 17 00:00:00 2001 From: Berkay Karaman Date: Mon, 11 Mar 2024 14:43:27 +0300 Subject: [PATCH] feat: move GidCompare and namespace into class Signed-off-by: Berkay Karaman --- .../ros/published_time_publisher.hpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp b/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp index 98b66e0192fc8..2b6c2997f2caf 100644 --- a/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp +++ b/common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp @@ -26,34 +26,23 @@ namespace tier4_autoware_utils { -using autoware_internal_msgs::msg::PublishedTime; - -// Custom comparison struct for rmw_gid_t -struct GidCompare -{ - bool operator()(const rmw_gid_t & lhs, const rmw_gid_t & rhs) const - { - return std::memcmp(lhs.data, rhs.data, RMW_GID_STORAGE_SIZE) < 0; - } -}; class PublishedTimePublisher { public: explicit PublishedTimePublisher( - rclcpp::Node * node, const std::string & end_name = "/debug/published_time", + rclcpp::Node * node, const std::string & publisher_topic_suffix = "/debug/published_time", const rclcpp::QoS & qos = rclcpp::QoS(1)) - : node_(node), end_name_(end_name), qos_(qos) + : node_(node), publisher_topic_suffix_(publisher_topic_suffix), qos_(qos) { } void publish(const rclcpp::PublisherBase::ConstSharedPtr & publisher, const rclcpp::Time & stamp) { const auto & gid_key = publisher->get_gid(); - const auto & topic_name = publisher->get_topic_name(); // if the publisher is not in the map, create a new publisher for published time - ensure_publisher_exists(gid_key, topic_name); + ensure_publisher_exists(gid_key, publisher->get_topic_name()); const auto & pub_published_time_ = publishers_[gid_key]; @@ -72,10 +61,9 @@ class PublishedTimePublisher const rclcpp::PublisherBase::ConstSharedPtr & publisher, const std_msgs::msg::Header & header) { const auto & gid_key = publisher->get_gid(); - const auto & topic_name = publisher->get_topic_name(); // if the publisher is not in the map, create a new publisher for published time - ensure_publisher_exists(gid_key, topic_name); + ensure_publisher_exists(gid_key, publisher->get_topic_name()); const auto & pub_published_time_ = publishers_[gid_key]; @@ -92,14 +80,26 @@ class PublishedTimePublisher private: rclcpp::Node * node_; - std::string end_name_; + std::string publisher_topic_suffix_; rclcpp::QoS qos_; + using PublishedTime = autoware_internal_msgs::msg::PublishedTime; + + // Custom comparison struct for rmw_gid_t + struct GidCompare + { + bool operator()(const rmw_gid_t & lhs, const rmw_gid_t & rhs) const + { + return std::memcmp(lhs.data, rhs.data, RMW_GID_STORAGE_SIZE) < 0; + } + }; + // ensure that the publisher exists in publisher_ map, if not, create a new one void ensure_publisher_exists(const rmw_gid_t & gid_key, const std::string & topic_name) { if (publishers_.find(gid_key) == publishers_.end()) { - publishers_[gid_key] = node_->create_publisher(topic_name + end_name_, qos_); + publishers_[gid_key] = + node_->create_publisher(topic_name + publisher_topic_suffix_, qos_); } }