-
Notifications
You must be signed in to change notification settings - Fork 522
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
Why don't use std::unique_ptr<> as input parameter instead of std::unique_ptr<>& in this function:
rclcpp/rclcpp/include/rclcpp/publisher.hpp
Lines 216 to 253 in 8743bcb
| virtual void | |
| publish(std::unique_ptr<MessageT, MessageDeleter> & msg) | |
| { | |
| this->do_inter_process_publish(msg.get()); | |
| if (store_intra_process_message_) { | |
| // Take the pointer from the unique_msg, release it and pass as a void * | |
| // to the ipm. The ipm should then capture it again as a unique_ptr of | |
| // the correct type. | |
| // TODO(wjwwood): | |
| // investigate how to transfer the custom deleter (if there is one) | |
| // from the incoming unique_ptr through to the ipm's unique_ptr. | |
| // See: http://stackoverflow.com/questions/11002641/dynamic-casting-for-unique-ptr | |
| MessageT * msg_ptr = msg.get(); | |
| msg.release(); | |
| uint64_t message_seq = | |
| store_intra_process_message_(intra_process_publisher_id_, msg_ptr, typeid(MessageT)); | |
| rcl_interfaces::msg::IntraProcessMessage ipm; | |
| ipm.publisher_id = intra_process_publisher_id_; | |
| ipm.message_sequence = message_seq; | |
| auto status = rcl_publish(&intra_process_publisher_handle_, &ipm); | |
| if (RCL_RET_PUBLISHER_INVALID == status) { | |
| rcl_reset_error(); // next call will reset error message if not context | |
| if (rcl_publisher_is_valid_except_context(&intra_process_publisher_handle_)) { | |
| rcl_context_t * context = rcl_publisher_get_context(&intra_process_publisher_handle_); | |
| if (nullptr != context && !rcl_context_is_valid(context)) { | |
| // publisher is invalid due to context being shutdown | |
| return; | |
| } | |
| } | |
| } | |
| if (RCL_RET_OK != status) { | |
| rclcpp::exceptions::throw_from_rcl_error(status, "failed to publish intra process message"); | |
| } | |
| } else { | |
| // Always destroy the message, even if we don't consume it, for consistency. | |
| msg.reset(); | |
| } | |
| } |
I think it is strange because the the parameter is input parameter, not an input and output parameter. So we can use std::unique_ptr<> instead. Here is the guideline: https://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested