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 #include "macros.h"
00044 
00045 namespace rosbag {
00046 
00047 class Bag;
00048 
00050 
00058 class ROSBAG_DECL MessageInstance
00059 {
00060     friend class View;
00061   
00062 public:
00063     ros::Time   const& getTime()              const;
00064     std::string const& getTopic()             const;
00065     std::string const& getDataType()          const;
00066     std::string const& getMD5Sum()            const;
00067     std::string const& getMessageDefinition() const;
00068 
00069     boost::shared_ptr<ros::M_string> getConnectionHeader() const;
00070 
00071     std::string getCallerId() const;
00072     bool        isLatching()  const;
00073 
00075 
00078     template<class T>
00079     bool isType() const;
00080 
00082 
00085     template<class T>
00086     boost::shared_ptr<T> instantiate() const;
00087   
00089     template<typename Stream>
00090     void write(Stream& stream) const;
00091 
00093     uint32_t size() const;
00094 
00095 private:
00096     MessageInstance(ConnectionInfo const* connection_info, IndexEntry const& index, Bag const& bag);
00097 
00098     ConnectionInfo const* connection_info_;
00099     IndexEntry const      index_entry_;
00100     Bag const*            bag_;
00101 };
00102 
00103 
00105 
00109 ros::AdvertiseOptions createAdvertiseOptions(MessageInstance const& msg, uint32_t queue_size);
00110 
00111 } // namespace rosbag
00112 
00113 namespace ros {
00114 namespace message_traits {
00115 
00116 template<>
00117 struct MD5Sum<rosbag::MessageInstance>
00118 {
00119     static const char* value(const rosbag::MessageInstance& m) { return m.getMD5Sum().c_str(); }
00120 };
00121 
00122 template<>
00123 struct DataType<rosbag::MessageInstance>
00124 {
00125     static const char* value(const rosbag::MessageInstance& m) { return m.getDataType().c_str(); }
00126 };
00127 
00128 template<>
00129 struct Definition<rosbag::MessageInstance>
00130 {
00131     static const char* value(const rosbag::MessageInstance& m) { return m.getMessageDefinition().c_str(); }
00132 };
00133 
00134 } // namespace message_traits
00135 
00136 namespace serialization
00137 {
00138 
00139 template<>
00140 struct Serializer<rosbag::MessageInstance>
00141 {
00142     template<typename Stream>
00143     inline static void write(Stream& stream, const rosbag::MessageInstance& m) {
00144         m.write(stream);
00145     }
00146 
00147     inline static uint32_t serializedLength(const rosbag::MessageInstance& m) {
00148         return m.size();
00149     }
00150 };
00151 
00152 } // namespace serialization
00153 
00154 } // namespace ros
00155 
00156 #include "rosbag/bag.h"
00157 
00158 namespace rosbag {
00159 
00160 template<class T>
00161 bool MessageInstance::isType() const {
00162     char const* md5sum = ros::message_traits::MD5Sum<T>::value();
00163     return md5sum == std::string("*") || md5sum == getMD5Sum();
00164 }
00165 
00166 template<class T>
00167 boost::shared_ptr<T> MessageInstance::instantiate() const {
00168     if (!isType<T>())
00169         return boost::shared_ptr<T>();
00170 
00171     return bag_->instantiateBuffer<T>(index_entry_);
00172 }
00173 
00174 template<typename Stream>
00175 void MessageInstance::write(Stream& stream) const {
00176     bag_->readMessageDataIntoStream(index_entry_, stream);
00177 }
00178 
00179 } // namespace rosbag
00180 
00181 #endif


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman
autogenerated on Mon Oct 6 2014 11:47:09