Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef BLOB_SHAPE_SHIFTER_H
00030 #define BLOB_SHAPE_SHIFTER_H
00031
00032 #include <ros/ros.h>
00033 #include <blob/Blob.h>
00034
00035 namespace blob {
00036
00037 struct ShapeShifter
00038 {
00039 typedef ShapeShifter Type;
00040
00041 ShapeShifter();
00042 ShapeShifter(const Blob& blob);
00043 virtual ~ShapeShifter();
00044
00045 typedef boost::shared_ptr< ShapeShifter > Ptr;
00046 typedef boost::shared_ptr< ShapeShifter const> ConstPtr;
00047
00048
00049 std::string const& getDataType() const;
00050 std::string const& getMD5Sum() const;
00051 std::string const& getMessageDefinition() const;
00052
00053 ShapeShifter& morph(const std::string& md5sum, const std::string& datatype,
00054 const std::string& msg_def = std::string(), const std::string& latching = std::string());
00055
00056
00057 ros::Publisher advertise(ros::NodeHandle& nh, const std::string& topic, uint32_t queue_size_, bool latch=false,
00058 const ros::SubscriberStatusCallback &connect_cb=ros::SubscriberStatusCallback()) const;
00059
00061 template<class M>
00062 boost::shared_ptr<M> instantiate() const;
00063
00065 template<typename Stream>
00066 void write(Stream& stream) const;
00067
00068 template<typename Stream>
00069 void read(Stream& stream);
00070
00072 uint32_t size() const;
00073
00074 const Blob& blob() const
00075 {
00076 return blob_;
00077 }
00078
00079 boost::shared_ptr<std::map<std::string, std::string> > __connection_header;
00080
00081 private:
00082 std::string md5, datatype, msg_def, latching;
00083 Blob blob_;
00084 };
00085
00086 typedef boost::shared_ptr<ShapeShifter > ShapeShifterPtr;
00087 typedef boost::shared_ptr<ShapeShifter const> ShapeShifterConstPtr;
00088
00089 std::ostream& operator<<(std::ostream& s, const ShapeShifter & v)
00090 {
00091 ros::message_operations::Printer< ShapeShifter >::stream(s, "", v);
00092 return s;
00093 }
00094
00095 template <typename ContainerAllocator>
00096 ShapeShifter Blob_<ContainerAllocator>::asMessage() const
00097 {
00098 return ShapeShifter(*this);
00099 }
00100
00101 }
00102
00103
00104 namespace ros {
00105 namespace message_traits {
00106
00107 template <> struct IsMessage<blob::ShapeShifter> : TrueType { };
00108 template <> struct IsMessage<const blob::ShapeShifter> : TrueType { };
00109
00110 template<>
00111 struct MD5Sum<blob::ShapeShifter>
00112 {
00113 static const char* value(const blob::ShapeShifter& m) { return m.getMD5Sum().c_str(); }
00114
00115
00116 static const char* value() { return "*"; }
00117 };
00118
00119 template<>
00120 struct DataType<blob::ShapeShifter>
00121 {
00122 static const char* value(const blob::ShapeShifter& m) { return m.getDataType().c_str(); }
00123
00124
00125 static const char* value() { return "*"; }
00126 };
00127
00128 template<>
00129 struct Definition<blob::ShapeShifter>
00130 {
00131 static const char* value(const blob::ShapeShifter& m) { return m.getMessageDefinition().c_str(); }
00132 };
00133
00134 }
00135
00136
00137 namespace serialization
00138 {
00139
00140 template<>
00141 struct Serializer<blob::ShapeShifter>
00142 {
00143 template<typename Stream>
00144 inline static void write(Stream& stream, const blob::ShapeShifter& m) {
00145 m.write(stream);
00146 }
00147
00148 template<typename Stream>
00149 inline static void read(Stream& stream, blob::ShapeShifter& m)
00150 {
00151 m.read(stream);
00152 }
00153
00154 inline static uint32_t serializedLength(const blob::ShapeShifter& m) {
00155 return m.size();
00156 }
00157 };
00158
00159
00160 template<>
00161 struct PreDeserialize<blob::ShapeShifter>
00162 {
00163 static void notify(const PreDeserializeParams<blob::ShapeShifter>& params)
00164 {
00165 std::string md5 = (*params.connection_header)["md5sum"];
00166 std::string datatype = (*params.connection_header)["type"];
00167 std::string msg_def = (*params.connection_header)["message_definition"];
00168 std::string latching = (*params.connection_header)["latching"];
00169
00170 typedef std::map<std::string, std::string> map_t;
00171 boost::shared_ptr<map_t> shmap(new map_t(*params.connection_header));
00172 params.message->__connection_header = shmap;
00173 params.message->morph(md5, datatype, msg_def, latching);
00174 }
00175 };
00176
00177 }
00178 }
00179
00180
00181
00182
00183 namespace blob
00184 {
00185
00186 template<class M>
00187 boost::shared_ptr<M> ShapeShifter::instantiate() const
00188 {
00189 return blob_.instantiate<M>();
00190 }
00191
00192 template<typename Stream>
00193 void ShapeShifter::write(Stream& stream) const {
00194 if (blob_.empty()) return;
00195 std::copy(blob_.begin(), blob_.end(), stream.advance(blob_.size()));
00196 }
00197
00198 template<typename Stream>
00199 void ShapeShifter::read(Stream& stream)
00200 {
00201 stream.getLength();
00202 stream.getData();
00203
00204 Blob::BufferPtr buffer(new Blob::Buffer(stream.getLength()));
00205 std::copy(stream.getData(), stream.getData() + stream.getLength(), buffer->begin());
00206 blob_.set(buffer);
00207 }
00208
00209 }
00210
00211 #endif // BLOB_SHAPE_SHIFTER_H