9 from roslib
import packages,msgs
12 from cStringIO
import StringIO
16 NAME=
'create_boost_header' 20 Writes the message-specific includes 22 @param s: The stream to write to 24 @param spec: The message spec to iterate over 25 @type spec: roslib.msgs.MsgSpec 26 @param serializer: The serializer type for which to include headers 29 for field
in spec.parsed_fields():
30 if (
not field.is_builtin):
31 (pkg, name) = genmsg.names.package_resource_name(field.base_type)
32 pkg = (pkg
or spec.package)
33 s.write(
'#include <%s/boost/%s.h>\n'%(pkg, name))
40 Writes the boost::serialize function for a message 42 @param s: Stream to write to 44 @param spec: The message spec 45 @type spec: roslib.msgs.MsgSpec 46 @param cpp_name_prefix: The C++ prefix to prepend to a message to refer to it (e.g. "std_msgs::") 47 @type cpp_name_prefix: str 51 s.write(
"/* Auto-generated by create_boost_header.py for file %s */\n"%(file))
52 s.write(
'#ifndef %s_BOOST_SERIALIZATION_%s_H\n'%(spec.package.upper(), spec.short_name.upper()))
53 s.write(
'#define %s_BOOST_SERIALIZATION_%s_H\n\n'%(spec.package.upper(), spec.short_name.upper()))
54 s.write(
'#include <boost/serialization/serialization.hpp>\n')
55 s.write(
'#include <boost/serialization/nvp.hpp>\n')
56 s.write(
'#include <boost/serialization/vector.hpp>\n')
57 s.write(
'#include <boost/serialization/string.hpp>\n')
58 s.write(
'#include <%s/%s.h>\n'%(spec.package,spec.short_name))
60 s.write(
'namespace boost\n{\n')
61 s.write(
'namespace serialization\n{\n\n')
63 s.write(
'template<class Archive, class ContainerAllocator>\n')
65 s.write(
'void serialize(Archive& a, %s & m, unsigned int)\n{\n'%(cpp_msg_with_alloc))
67 for field
in spec.parsed_fields():
68 s.write(
' a & make_nvp("%s",m.%s);\n'%(field.name,field.name))
71 s.write(
'} // namespace serialization\n')
72 s.write(
'} // namespace boost\n\n')
73 s.write(
'#endif // %s_BOOST_SERIALIZATION_%s_H\n'%(spec.package.upper(), spec.short_name.upper()))
79 Generate a boost::serialization header 81 @param msg_path: The path to the .msg file 84 mc = genmsg.msg_loader.MsgContext()
86 spec = genmsg.msg_loader.load_msg_from_file(mc, msg_path, msg_type)
87 cpp_prefix =
'%s::'%(package)
92 (output_dir,filename) = os.path.split(boost_header_path)
94 os.makedirs(output_dir)
98 f = open(boost_header_path,
'w')
99 print >> f, s.getvalue()
105 parser = argparse.ArgumentParser(description=
'Generate boost serialization header for ROS message.')
106 parser.add_argument(
'pkg',metavar=
'PKG',type=str, nargs=1,help=
'The package name.')
107 parser.add_argument(
'msg_type',metavar=
'MSG_TYPE',type=str, nargs=1,help=
'The message type.')
108 parser.add_argument(
'msg_file_path',metavar=
'MSG_FILE_PATH',type=str, nargs=1,help=
'The full path to a .msg file.')
109 parser.add_argument(
'boost_file_path',metavar=
'BOOST_HEADER_PATH',type=str, nargs=1,help=
'The full path to the generated boost header file.')
111 args = parser.parse_args()
115 if __name__ ==
"__main__":
119 sys.stderr.write(
"Failed to generate boost headers: " + str(e))
def cpp_message_declarations(name_prefix, msg)