3 from __future__
import print_function
4 from __future__
import unicode_literals
13 from roslib
import packages,msgs
16 from io
import StringIO
20 NAME=
'create_boost_header' 24 Writes the message-specific includes 26 @param s: The stream to write to 28 @param spec: The message spec to iterate over 29 @type spec: roslib.msgs.MsgSpec 30 @param serializer: The serializer type for which to include headers 33 for field
in spec.parsed_fields():
34 if (
not field.is_builtin):
35 (pkg, name) = genmsg.names.package_resource_name(field.base_type)
36 pkg = (pkg
or spec.package)
37 s.write(
'#include <%s/boost/%s.h>\n'%(pkg, name))
44 Writes the boost::serialize function for a message 46 @param s: Stream to write to 48 @param spec: The message spec 49 @type spec: roslib.msgs.MsgSpec 50 @param cpp_name_prefix: The C++ prefix to prepend to a message to refer to it (e.g. "std_msgs::") 51 @type cpp_name_prefix: str 55 s.write(
"/* Auto-generated by create_boost_header.py for file %s */\n"%(file))
56 s.write(
'#ifndef %s_BOOST_SERIALIZATION_%s_H\n'%(spec.package.upper(), spec.short_name.upper()))
57 s.write(
'#define %s_BOOST_SERIALIZATION_%s_H\n\n'%(spec.package.upper(), spec.short_name.upper()))
58 s.write(
'#include <boost/serialization/serialization.hpp>\n')
59 s.write(
'#include <boost/serialization/nvp.hpp>\n')
60 s.write(
'#include <boost/serialization/vector.hpp>\n')
61 s.write(
'#include <boost/serialization/string.hpp>\n')
62 s.write(
'#include <%s/%s.h>\n'%(spec.package,spec.short_name))
64 s.write(
'namespace boost\n{\n')
65 s.write(
'namespace serialization\n{\n\n')
67 s.write(
'template<class Archive, class ContainerAllocator>\n')
69 s.write(
'void serialize(Archive& a, %s & m, unsigned int)\n{\n'%(cpp_msg_with_alloc))
71 for field
in spec.parsed_fields():
72 s.write(
' a & make_nvp("%s",m.%s);\n'%(field.name,field.name))
75 s.write(
'} // namespace serialization\n')
76 s.write(
'} // namespace boost\n\n')
77 s.write(
'#endif // %s_BOOST_SERIALIZATION_%s_H\n'%(spec.package.upper(), spec.short_name.upper()))
83 Generate a boost::serialization header 85 @param msg_path: The path to the .msg file 88 mc = genmsg.msg_loader.MsgContext()
90 spec = genmsg.msg_loader.load_msg_from_file(mc, msg_path, msg_type)
91 cpp_prefix =
'%s::'%(package)
96 (output_dir,filename) = os.path.split(boost_header_path)
98 os.makedirs(output_dir)
102 f = open(boost_header_path,
'w')
103 print(s.getvalue(), file=f)
109 parser = argparse.ArgumentParser(description=
'Generate boost serialization header for ROS message.')
110 parser.add_argument(
'pkg',metavar=
'PKG',type=str, nargs=1,help=
'The package name.')
111 parser.add_argument(
'msg_type',metavar=
'MSG_TYPE',type=str, nargs=1,help=
'The message type.')
112 parser.add_argument(
'msg_file_path',metavar=
'MSG_FILE_PATH',type=str, nargs=1,help=
'The full path to a .msg file.')
113 parser.add_argument(
'boost_file_path',metavar=
'BOOST_HEADER_PATH',type=str, nargs=1,help=
'The full path to the generated boost header file.')
115 args = parser.parse_args()
119 if __name__ ==
"__main__":
122 except Exception
as e:
123 sys.stderr.write(
"Failed to generate boost headers: " + str(e))
def cpp_message_declarations(name_prefix, msg)