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


rosbag_storage
Author(s):
autogenerated on Thu Jun 6 2019 21:09:52