Skip to content

Commit dc9b8cf

Browse files
committed
feat: move GidCompare and namespace into class
Signed-off-by: Berkay Karaman <brkay54@gmail.com> publishedt Signed-off-by: Berkay Karaman <brkay54@gmail.com>
1 parent df714bf commit dc9b8cf

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

common/tier4_autoware_utils/include/tier4_autoware_utils/ros/published_time_publisher.hpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,23 @@
2626

2727
namespace tier4_autoware_utils
2828
{
29-
using autoware_internal_msgs::msg::PublishedTime;
30-
31-
// Custom comparison struct for rmw_gid_t
32-
struct GidCompare
33-
{
34-
bool operator()(const rmw_gid_t & lhs, const rmw_gid_t & rhs) const
35-
{
36-
return std::memcmp(lhs.data, rhs.data, RMW_GID_STORAGE_SIZE) < 0;
37-
}
38-
};
3929

4030
class PublishedTimePublisher
4131
{
4232
public:
4333
explicit PublishedTimePublisher(
44-
rclcpp::Node * node, const std::string & end_name = "/debug/published_time",
34+
rclcpp::Node * node, const std::string & publisher_topic_suffix = "/debug/published_time",
4535
const rclcpp::QoS & qos = rclcpp::QoS(1))
46-
: node_(node), end_name_(end_name), qos_(qos)
36+
: node_(node), publisher_topic_suffix_(publisher_topic_suffix), qos_(qos)
4737
{
4838
}
4939

5040
void publish(const rclcpp::PublisherBase::ConstSharedPtr & publisher, const rclcpp::Time & stamp)
5141
{
5242
const auto & gid_key = publisher->get_gid();
53-
const auto & topic_name = publisher->get_topic_name();
5443

5544
// if the publisher is not in the map, create a new publisher for published time
56-
ensure_publisher_exists(gid_key, topic_name);
45+
ensure_publisher_exists(gid_key, publisher->get_topic_name());
5746

5847
const auto & pub_published_time_ = publishers_[gid_key];
5948

@@ -92,14 +81,25 @@ class PublishedTimePublisher
9281

9382
private:
9483
rclcpp::Node * node_;
95-
std::string end_name_;
84+
std::string publisher_topic_suffix_;
9685
rclcpp::QoS qos_;
9786

87+
using PublishedTime = autoware_internal_msgs::msg::PublishedTime;
88+
89+
// Custom comparison struct for rmw_gid_t
90+
struct GidCompare
91+
{
92+
bool operator()(const rmw_gid_t & lhs, const rmw_gid_t & rhs) const
93+
{
94+
return std::memcmp(lhs.data, rhs.data, RMW_GID_STORAGE_SIZE) < 0;
95+
}
96+
};
97+
9898
// ensure that the publisher exists in publisher_ map, if not, create a new one
9999
void ensure_publisher_exists(const rmw_gid_t & gid_key, const std::string & topic_name)
100100
{
101101
if (publishers_.find(gid_key) == publishers_.end()) {
102-
publishers_[gid_key] = node_->create_publisher<PublishedTime>(topic_name + end_name_, qos_);
102+
publishers_[gid_key] = node_->create_publisher<PublishedTime>(topic_name + publisher_topic_suffix_, qos_);
103103
}
104104
}
105105

0 commit comments

Comments
 (0)