publisher_wrapper.h
Go to the documentation of this file.
1 #pragma once
2 
3 #if PACKAGE_ROS_VERSION == 1
4 #else
5 
6 #include "rclcpp/rclcpp.hpp"
7 
9 {
10  public:
11  PublisherWrapperBase() = default;
12  virtual ~PublisherWrapperBase() = default;
13  virtual void publish(std::shared_ptr<void> message) = 0;
14 };
15 
16 template <typename MessageT>
18 {
19  public:
20  PublisherWrapper(rclcpp::Node::SharedPtr node, const std::string& topic_name, size_t qos)
21  : publisher_(node->create_publisher<MessageT>(topic_name, qos))
22  {
23  }
24 
25  void publish(std::shared_ptr<void> msg) override
26  {
27  const auto typed_msg = std::static_pointer_cast<MessageT>(msg);
28  if (typed_msg)
29  {
30  publisher_->publish(*typed_msg);
31  }
32  else
33  {
34  RCLCPP_ERROR(rclcpp::get_logger("rclcpp"), "Failed to cast message to correct type.");
35  }
36  }
37 
38  private:
39  typename rclcpp::Publisher<MessageT>::SharedPtr publisher_;
40 };
41 
42 #endif
PublisherWrapperBase::PublisherWrapperBase
PublisherWrapperBase()=default
PublisherWrapperBase::publish
virtual void publish(std::shared_ptr< void > message)=0
PublisherWrapper::publisher_
rclcpp::Publisher< MessageT >::SharedPtr publisher_
Definition: publisher_wrapper.h:39
PublisherWrapper::publish
void publish(std::shared_ptr< void > msg) override
Definition: publisher_wrapper.h:25
PublisherWrapperBase
Definition: publisher_wrapper.h:8
PublisherWrapper
Definition: publisher_wrapper.h:17
message
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: gl.h:1033
PublisherWrapper::PublisherWrapper
PublisherWrapper(rclcpp::Node::SharedPtr node, const std::string &topic_name, size_t qos)
Definition: publisher_wrapper.h:20
PublisherWrapperBase::~PublisherWrapperBase
virtual ~PublisherWrapperBase()=default


mvsim
Author(s):
autogenerated on Wed May 28 2025 02:13:08