message_instance.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2008, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of Willow Garage, Inc. nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #ifndef ROSBAG_MESSAGE_INSTANCE_H
00036 #define ROSBAG_MESSAGE_INSTANCE_H
00037 
00038 #include <ros/message_traits.h>
00039 #include <ros/ros.h>
00040 #include <ros/time.h>
00041 
00042 #include "rosbag/structures.h"
00043 
00044 namespace rosbag {
00045 
00046 class Bag;
00047 
00049 
00057 class MessageInstance
00058 {
00059     friend class View;
00060   
00061 public:
00062     ros::Time   const& getTime()              const;
00063     std::string const& getTopic()             const;
00064     std::string const& getDataType()          const;
00065     std::string const& getMD5Sum()            const;
00066     std::string const& getMessageDefinition() const;
00067 
00068     boost::shared_ptr<ros::M_string> getConnectionHeader() const;
00069 
00070     std::string getCallerId() const;
00071     bool        isLatching()  const;
00072 
00074 
00077     template<class T>
00078     bool isType() const;
00079 
00081 
00084     template<class T>
00085     boost::shared_ptr<T> instantiate() const;
00086   
00088     template<typename Stream>
00089     void write(Stream& stream) const;
00090 
00092     uint32_t size() const;
00093 
00094 private:
00095     MessageInstance(ConnectionInfo const* connection_info, IndexEntry const& index, Bag const& bag);
00096 
00097     ConnectionInfo const* connection_info_;
00098     IndexEntry const      index_entry_;
00099     Bag const*            bag_;
00100 };
00101 
00102 
00104 
00108 ros::AdvertiseOptions createAdvertiseOptions(MessageInstance const& msg, uint32_t queue_size);
00109 
00110 } // namespace rosbag
00111 
00112 namespace ros {
00113 namespace message_traits {
00114 
00115 template<>
00116 struct MD5Sum<rosbag::MessageInstance>
00117 {
00118     static const char* value(const rosbag::MessageInstance& m) { return m.getMD5Sum().c_str(); }
00119 };
00120 
00121 template<>
00122 struct DataType<rosbag::MessageInstance>
00123 {
00124     static const char* value(const rosbag::MessageInstance& m) { return m.getDataType().c_str(); }
00125 };
00126 
00127 template<>
00128 struct Definition<rosbag::MessageInstance>
00129 {
00130     static const char* value(const rosbag::MessageInstance& m) { return m.getMessageDefinition().c_str(); }
00131 };
00132 
00133 } // namespace message_traits
00134 
00135 namespace serialization
00136 {
00137 
00138 template<>
00139 struct Serializer<rosbag::MessageInstance>
00140 {
00141     template<typename Stream>
00142     inline static void write(Stream& stream, const rosbag::MessageInstance& m) {
00143         m.write(stream);
00144     }
00145 
00146     inline static uint32_t serializedLength(const rosbag::MessageInstance& m) {
00147         return m.size();
00148     }
00149 };
00150 
00151 } // namespace serialization
00152 
00153 } // namespace ros
00154 
00155 #include "rosbag/bag.h"
00156 
00157 namespace rosbag {
00158 
00159 template<class T>
00160 bool MessageInstance::isType() const {
00161     char const* md5sum = ros::message_traits::MD5Sum<T>::value();
00162     return md5sum == std::string("*") || md5sum == getMD5Sum();
00163 }
00164 
00165 template<class T>
00166 boost::shared_ptr<T> MessageInstance::instantiate() const {
00167     if (!isType<T>())
00168         return boost::shared_ptr<T>();
00169 
00170     return bag_->instantiateBuffer<T>(index_entry_);
00171 }
00172 
00173 template<typename Stream>
00174 void MessageInstance::write(Stream& stream) const {
00175     bag_->readMessageDataIntoStream(index_entry_, stream);
00176 }
00177 
00178 } // namespace rosbag
00179 
00180 #endif


rosbag
Author(s): Tim Field (tfield@willowgarage.com), Jeremy Leibs (leibs@willowgarage.com), and James Bowman (jamesb@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:43:05