@@ -16,6 +16,7 @@ from rosidl_parser.definition import NamespacedType
1616from rosidl_parser .definition import NestedType
1717from rosidl_parser .definition import Sequence
1818from rosidl_parser .definition import String
19+ from rosidl_parser .definition import UnboundedSequence
1920from rosidl_parser .definition import WString
2021}@
2122
@@ -135,45 +136,44 @@ class @(message.structure.type.name)(metaclass=Metaclass_@(message.structure.typ
135136@ [end for ]@
136137 ]
137138
138- _fields_and_field_types = {
139+ SLOT_TYPES = (
139140@ [for member in message .structure .members ]@
140141@ {
141142type_ = member .type
142143if isinstance (type_, NestedType):
143144 type_ = type_ .basetype
144145}@
145- ' @(member.name)' : ' @
146- @# the prefix for nested types
147- @[ if isinstance(member.type, Sequence)]@
148- sequence<@
146+ @
147+ @ [ if isinstance (member .type , BoundedSequence)]@
148+ rosidl_parser .definition .BoundedSequence (@
149+ @ [ elif isinstance (member .type , UnboundedSequence)]@
150+ rosidl_parser .definition .UnboundedSequence (@
151+ @ [ elif isinstance (member .type , Array )]@
152+ rosidl_parser .definition .Array (@
149153@ [ end if ]@
150154@ # the typename of the non-nested type or the nested basetype
151155@ [ if isinstance (type_, BasicType)]@
152- @(type_.type)@
156+ rosidl_parser . definition . BasicType ( ' @(type_.type) ' )@
153157@ [ elif isinstance (type_, BaseString)]@
154- @
155158@ [ if isinstance (type_, WString)]@
156- w@
157- @[ end if]@
158- string@
159- @[ if type_.maximum_size is not None]@
160- <@(type_.maximum_size)>@
159+ rosidl_parser .definition .WString (' @
160+ @[ else]@
161+ rosidl_parser.definition.String(' @
161162@ [ end if ]@
163+ @ (str (type_ .maximum_size ))' )@
162164@[ elif isinstance(type_, NamespacedType)]@
163- @( ' / ' .join([ type_.namespaces[0 ], type_.name]) )@
165+ rosidl_parser.definition.NamespacedType([ ' @ ( " ', ' " .join (type_ .namespaces )) ' ], ' @ ( type_ .name ) ' )@
164166@[ end if]@
165- @# the suffix for nested types
166- @[ if isinstance(member.type, Sequence)]@
167- @[ if isinstance(member.type, BoundedSequence)]@
168- , @(member.type.upper_bound)@
169- @[ end if]@
170- >@
167+ @[ if isinstance(member.type, BoundedSequence)]@
168+ , @(member.type.upper_bound))@
171169@[ elif isinstance(member.type, Array)]@
172- [@(member.type.size)]@
170+ , @(member.type.size))@
171+ @[ elif isinstance(member.type, UnboundedSequence)]@
172+ )@
173173@[ end if]@
174- ' ,
174+ ,
175175@[end for]@
176- }
176+ )
177177
178178 def __init__(self, **kwargs):
179179 assert all(' _' + key in self.__slots__ for key in kwargs.keys()), \
@@ -246,9 +246,8 @@ if isinstance(type_, NestedType):
246246 return True
247247
248248 @@classmethod
249- def get_fields_and_field_types (cls):
250- from copy import copy
251- return copy (cls ._fields_and_field_types )
249+ def get_slot_types(cls):
250+ return OrderedDict(zip([s[1:] for s in cls.__slots__], cls.SLOT_TYPES))
252251@[for member in message.structure.members]@
253252
254253@{
0 commit comments