@@ -67,13 +67,44 @@ def prefix_with_bom_if_necessary(content):
67
67
'int32' : 'int32_t' ,
68
68
'uint64' : 'uint64_t' ,
69
69
'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
70
}
75
71
76
72
73
+ def resolve_string_type (type_ ):
74
+ """
75
+ Convert a string type into the C++ declaration,
76
+ respecting character width and string boundedness.
77
+
78
+ Example input: TODO
79
+ Example output: TODO
80
+
81
+ @param type_: The message type
82
+ @type type_: rosidl_parser.Type
83
+ """
84
+ if isinstance (type_ , AbstractString ):
85
+ if isinstance (type_ , BoundedString ):
86
+ return \
87
+ ('rosidl_runtime_cpp::bounded_basic_string<char, %u, std::char_traits<char>, ' +
88
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>' ) \
89
+ % (type_ .maximum_size )
90
+ elif isinstance (type_ , UnboundedString ):
91
+ return \
92
+ ('std::basic_string<char, std::char_traits<char>, ' +
93
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>' )
94
+ elif isinstance (type_ , AbstractWString ):
95
+ if isinstance (type_ , BoundedWString ):
96
+ return \
97
+ ('rosidl_runtime_cpp::bounded_basic_string<char16_t, %u, ' +
98
+ 'std::char_traits<char16_t>, ' +
99
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char16_t>>' ) \
100
+ % (type_ .maximum_size )
101
+ elif isinstance (type_ , UnboundedWString ):
102
+ return \
103
+ ('std::basic_string<char16_t, std::char_traits<char16_t>, ' +
104
+ 'std::allocator_traits<ContainerAllocator>::template rebind_alloc<char16_t>>' )
105
+ assert False , type_
106
+
107
+
77
108
def msg_type_only_to_cpp (type_ ):
78
109
"""
79
110
Convert a message type into the C++ declaration, ignoring array types.
@@ -88,10 +119,8 @@ def msg_type_only_to_cpp(type_):
88
119
type_ = type_ .value_type
89
120
if isinstance (type_ , BasicType ):
90
121
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' ]
122
+ elif isinstance (type_ , AbstractGenericString ):
123
+ cpp_type = resolve_string_type (type_ )
95
124
elif isinstance (type_ , NamespacedType ):
96
125
typename = '::' .join (type_ .namespaced_name ())
97
126
cpp_type = typename + '_<ContainerAllocator>'
0 commit comments