Skip to content

Commit

Permalink
Add support for string constant in messages and services.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien BARRAL committed Jul 24, 2018
1 parent b34c770 commit df19d3c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion scripts/make_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,14 @@ def __init__(self, name, ty, value):
self.value = value

def make_declaration(self, f):
f.write(' enum { %s = %s };\n' % (self.name, self.value))
if(self.type != 'string'):
f.write(' enum { %s = %s };\n' % (self.name, self.value))
else:
f.write(' static const std::string %s;\n' % (self.name))

def make_assignations(self, f, className):
if(self.type == 'string'):
f.write(' const std::string %s::%s = "%s";\n' % (className, self.name, self.value))

class PrimitiveDataType:
""" Our datatype is a C/C++ primitive. """
Expand Down Expand Up @@ -561,6 +567,10 @@ def _write_data(self, f):
e.make_declaration(f)
f.write('\n')

def _write_static_assignations(self, f, className):
for e in self.enums:
e.make_assignations(f, className)

def _write_getType(self, f):
f.write(' static const std::string& getType(){\n')
f.write(' static std::string type = "%s/%s";\n' % (self.package, self.name))
Expand Down Expand Up @@ -588,6 +598,7 @@ def _write_impl(self, f):
self._write_getMD5(f)
f.write('\n')
f.write(' };\n')
self._write_static_assignations(f, self.name);

def make_header(self, f):
f.write('#ifndef _ROS_%s_%s_h\n' % (self.package, self.name))
Expand Down

0 comments on commit df19d3c

Please sign in to comment.