23
23
from rosidl_parser .definition import Array
24
24
from rosidl_parser .definition import BasicType
25
25
from rosidl_parser .definition import BoundedSequence
26
+ from rosidl_parser .definition import BoundedString
26
27
from rosidl_parser .definition import FLOATING_POINT_TYPES
27
28
from rosidl_parser .definition import NamespacedType
28
29
from rosidl_parser .definition import UnboundedSequence
30
+ from rosidl_parser .definition import UnboundedString
29
31
30
32
31
33
def generate_cpp (generator_arguments_file ):
@@ -67,13 +69,44 @@ def prefix_with_bom_if_necessary(content):
67
69
'int32' : 'int32_t' ,
68
70
'uint64' : 'uint64_t' ,
69
71
'int64' : 'int64_t' ,
70
- 'string' : 'std::basic_string<char, std::char_traits<char>, ' +
71
- 'typename std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>' ,
72
- 'wstring' : 'std::basic_string<char16_t, std::char_traits<char16_t>, typename ' +
73
- 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char16_t>>' ,
74
72
}
75
73
76
74
75
+ def resolve_string_type (type_ ):
76
+ """
77
+ Convert a string type into the C++ declaration,
78
+ respecting character width and string boundedness.
79
+
80
+ Example input: TODO
81
+ Example output: TODO
82
+
83
+ @param type_: The message type
84
+ @type type_: rosidl_parser.Type
85
+ """
86
+ if isinstance (type_ , AbstractString ):
87
+ if isinstance (type_ , BoundedString ):
88
+ return \
89
+ ('rosidl_runtime_cpp::bounded_basic_string<char, %u, std::char_traits<char>, ' +
90
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>' ) \
91
+ % (type_ .maximum_size )
92
+ elif isinstance (type_ , UnboundedString ):
93
+ return \
94
+ ('std::basic_string<char, std::char_traits<char>, ' +
95
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>' )
96
+ elif isinstance (type_ , AbstractWString ):
97
+ if isinstance (type_ , BoundedWString ):
98
+ return \
99
+ ('rosidl_runtime_cpp::bounded_basic_string<char16_t, %u, ' +
100
+ 'std::char_traits<char16_t>, ' +
101
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char16_t>>' ) \
102
+ % (type_ .maximum_size )
103
+ elif isinstance (type_ , UnboundedWString ):
104
+ return \
105
+ ('std::basic_string<char16_t, std::char_traits<char16_t>, ' +
106
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char16_t>>' )
107
+ assert False , type_
108
+
109
+
77
110
def msg_type_only_to_cpp (type_ ):
78
111
"""
79
112
Convert a message type into the C++ declaration, ignoring array types.
@@ -88,10 +121,8 @@ def msg_type_only_to_cpp(type_):
88
121
type_ = type_ .value_type
89
122
if isinstance (type_ , BasicType ):
90
123
cpp_type = MSG_TYPE_TO_CPP [type_ .typename ]
91
- elif isinstance (type_ , AbstractString ):
92
- cpp_type = MSG_TYPE_TO_CPP ['string' ]
93
- elif isinstance (type_ , AbstractWString ):
94
- cpp_type = MSG_TYPE_TO_CPP ['wstring' ]
124
+ elif isinstance (type_ , AbstractGenericString ):
125
+ cpp_type = resolve_string_type (type_ )
95
126
elif isinstance (type_ , NamespacedType ):
96
127
typename = '::' .join (type_ .namespaced_name ())
97
128
cpp_type = typename + '_<ContainerAllocator>'
0 commit comments