29 #ifndef ROSCPP_MESSAGE_EVENT_H 30 #define ROSCPP_MESSAGE_EVENT_H 36 #include <boost/type_traits/is_void.hpp> 37 #include <boost/type_traits/is_base_of.hpp> 38 #include <boost/type_traits/is_const.hpp> 39 #include <boost/type_traits/add_const.hpp> 40 #include <boost/type_traits/remove_const.hpp> 41 #include <boost/utility/enable_if.hpp> 42 #include <boost/function.hpp> 43 #include <boost/make_shared.hpp> 53 return boost::make_shared<M>();
73 typedef typename boost::remove_const<M>::type
Message;
79 : nonconst_need_copy_(true)
95 nonconst_need_copy_ = nonconst_need_copy;
101 nonconst_need_copy_ = nonconst_need_copy;
129 init(message, connection_header, receipt_time, nonconst_need_copy, create);
135 connection_header_ = connection_header;
136 receipt_time_ = receipt_time;
137 nonconst_need_copy_ = nonconst_need_copy;
144 message_copy_.reset();
150 message_copy_.reset();
160 return copyMessageIfNecessary<M>();
176 const std::string&
getPublisherName()
const {
return connection_header_ ? (*connection_header_)[
"callerid"] : s_unknown_publisher_string_; }
186 bool operator<(const MessageEvent<M>& rhs)
188 if (message_ != rhs.message_)
190 return message_ < rhs.message_;
193 if (receipt_time_ != rhs.receipt_time_)
195 return receipt_time_ < rhs.receipt_time_;
198 return nonconst_need_copy_ < rhs.nonconst_need_copy_;
208 return !(*
this == rhs);
214 template<
typename M2>
217 if (boost::is_const<M>::value || !nonconst_need_copy_)
219 return boost::const_pointer_cast<Message>(message_);
224 return message_copy_;
228 message_copy_ = create_();
229 *message_copy_ = *message_;
231 return message_copy_;
234 template<
typename M2>
237 return boost::const_pointer_cast<Message>(message_);
256 #endif // ROSCPP_MESSAGE_EVENT_H boost::add_const< M >::type ConstMessage
ros::Time getReceiptTime() const
Returns the time at which this message was received.
boost::enable_if< boost::is_void< M2 >, boost::shared_ptr< M > >::type copyMessageIfNecessary() const
boost::disable_if< boost::is_void< M2 >, boost::shared_ptr< M > >::type copyMessageIfNecessary() const
boost::shared_ptr< Message > MessagePtr
bool nonConstWillCopy() const
bool operator==(const MessageEvent< M > &rhs)
const CreateFunction & getMessageFactory() const
M_string & getConnectionHeader() const
Retrieve the connection header.
MessageEvent(const MessageEvent< ConstMessage > &rhs)
bool operator!=(const MessageEvent< M > &rhs)
boost::shared_ptr< M_string > connection_header_
const boost::shared_ptr< M_string > & getConnectionHeaderPtr() const
void operator=(const MessageEvent< Message > &rhs)
MessageEvent(const MessageEvent< ConstMessage > &rhs, bool nonconst_need_copy)
static const std::string s_unknown_publisher_string_
MessageEvent(const ConstMessagePtr &message, const boost::shared_ptr< M_string > &connection_header, ros::Time receipt_time)
std::map< std::string, std::string > M_string
const std::string & getPublisherName() const
Returns the name of the node which published this message.
const boost::shared_ptr< ConstMessage > & getConstMessage() const
Retrieve a const version of the message.
bool getMessageWillCopy() const
Event type for subscriptions, const ros::MessageEvent<M const>& can be used in your callback instead ...
void operator=(const MessageEvent< ConstMessage > &rhs)
boost::shared_ptr< ConstMessage > ConstMessagePtr
boost::function< MessagePtr()> CreateFunction
MessageEvent(const ConstMessagePtr &message)
boost::shared_ptr< M > operator()()
void init(const ConstMessagePtr &message, const boost::shared_ptr< M_string > &connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction &create)
MessageEvent(const MessageEvent< void const > &rhs, const CreateFunction &create)
MessageEvent(const MessageEvent< Message > &rhs, bool nonconst_need_copy)
ROS_DEPRECATED boost::shared_ptr< M > defaultMessageCreateFunction()
MessageEvent(const ConstMessagePtr &message, ros::Time receipt_time)
MessageEvent(const MessageEvent< Message > &rhs)
boost::remove_const< M >::type Message
MessageEvent(const ConstMessagePtr &message, const boost::shared_ptr< M_string > &connection_header, ros::Time receipt_time, bool nonconst_need_copy, const CreateFunction &create)
boost::shared_ptr< M > getMessage() const
Retrieve the message. If M is const, this returns a reference to it. If M is non const and this event...