Merge pull request #123 from ros2/publish_const_shared_ptr
add publish specialization for shared_ptr<const MessageT>
This commit is contained in:
commit
89541ea10f
1 changed files with 18 additions and 0 deletions
|
@ -157,6 +157,24 @@ public:
|
||||||
return this->publish(unique_msg);
|
return this->publish(unique_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename MessageT>
|
||||||
|
void
|
||||||
|
publish(std::shared_ptr<const MessageT> msg)
|
||||||
|
{
|
||||||
|
// Avoid allocating when not using intra process.
|
||||||
|
if (!store_intra_process_message_) {
|
||||||
|
// In this case we're not using intra process.
|
||||||
|
return this->do_inter_process_publish(msg.get());
|
||||||
|
}
|
||||||
|
// Otherwise we have to allocate memory in a unique_ptr and pass it along.
|
||||||
|
// TODO(wjwwood):
|
||||||
|
// The intra process manager should probably also be able to store
|
||||||
|
// shared_ptr's and do the "smart" thing based on other intra process
|
||||||
|
// subscriptions. For now call the other publish().
|
||||||
|
std::unique_ptr<MessageT> unique_msg(new MessageT(*msg.get()));
|
||||||
|
return this->publish(unique_msg);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename MessageT>
|
template<typename MessageT>
|
||||||
void
|
void
|
||||||
publish(const MessageT & msg)
|
publish(const MessageT & msg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue