Skip to content

Commit 7ffd80e

Browse files
Fix python code generation for bounded strings (#440) (#442)
* Refs #22835. SWIG extend to set fixed_string from std::string. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. SWIG export template for fixed_string members. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Fix access to typecode. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Fix max size typo. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Fix exported template name. Signed-off-by: Miguel Company <[email protected]> * Refs #22835. Fix extend code. Signed-off-by: Miguel Company <[email protected]> * Refs #22850. Apply suggestions from review. Signed-off-by: Miguel Company <[email protected]> --------- Signed-off-by: Miguel Company <[email protected]> (cherry picked from commit 8eaca9a) Co-authored-by: Miguel Company <[email protected]>
1 parent 61a020b commit 7ffd80e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ $ctx.directIncludeDependencies : {include | %include "$include$.i"}; separator="
5252
%}
5353

5454
%include <fastcdr/config.h>
55+
$if(ctx.thereIsOptionalAnnotation)$
5556
%import(module="fastdds") "fastcdr/xcdr/optional.hpp"
57+
$endif$
58+
$if(ctx.thereIsString)$
59+
%import(module="fastdds") "fastcdr/cdr/fixed_size_string.hpp"
60+
$endif$
5661
%import(module="fastdds") "fastdds/dds/core/LoanableCollection.hpp"
5762
%import(module="fastdds") "fastdds/dds/core/LoanableTypedCollection.hpp"
5863
%import(module="fastdds") "fastdds/dds/core/LoanableSequence.hpp"
@@ -188,6 +193,18 @@ $else$
188193
%ignore $struct_name$::$member.name$();
189194
%rename("%s") $struct_name$::$member.name$() const;
190195

196+
$if(member.typecode.isStringType && member.typecode.isBounded)$
197+
%template(fixed_string_$member.typecode.maxsize$) eprosima::fastcdr::fixed_string<$member.typecode.maxsize$>;
198+
%extend $struct_name$
199+
{
200+
void $member.name$(const std::string& value)
201+
{
202+
eprosima::fastcdr::fixed_string<$member.typecode.maxsize$> tmp(value);
203+
\$self->$member.name$(tmp);
204+
}
205+
}
206+
$endif$
207+
191208
$endif$
192209

193210
>>

0 commit comments

Comments
 (0)