From 90e92356713c877eef483e9b4fb79ffe7b40cd53 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Tue, 25 Feb 2025 12:08:08 +0100 Subject: [PATCH 1/4] Fix python code generation for bounded strings (#440) * Refs #22835. SWIG extend to set fixed_string from std::string. Signed-off-by: Miguel Company * Refs #22835. SWIG export template for fixed_string members. Signed-off-by: Miguel Company * Refs #22835. Fix access to typecode. Signed-off-by: Miguel Company * Refs #22835. Fix max size typo. Signed-off-by: Miguel Company * Refs #22835. Fix exported template name. Signed-off-by: Miguel Company * Refs #22835. Fix extend code. Signed-off-by: Miguel Company * Refs #22850. Apply suggestions from review. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company (cherry picked from commit 8eaca9ae9c6d352bf58c5f71b5b92fa8718b1fd2) # Conflicts: # src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg --- .../idl/templates/TypesSwigInterface.stg | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 78a87b3d..1d835132 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -44,9 +44,18 @@ $ctx.directIncludeDependencies : {include | %include "$include$.i"}; separator=" %} %include +<<<<<<< HEAD #if FASTCDR_VERSION_MAJOR > 1 %import(module="fastdds") "fastcdr/xcdr/optional.hpp" #endif +======= +$if(ctx.thereIsOptionalAnnotation)$ +%import(module="fastdds") "fastcdr/xcdr/optional.hpp" +$endif$ +$if(ctx.thereIsString)$ +%import(module="fastdds") "fastcdr/cdr/fixed_size_string.hpp" +$endif$ +>>>>>>> 8eaca9a (Fix python code generation for bounded strings (#440)) %import(module="fastdds") "fastdds/dds/core/LoanableCollection.hpp" %import(module="fastdds") "fastdds/dds/core/LoanableTypedCollection.hpp" %import(module="fastdds") "fastdds/dds/core/LoanableSequence.hpp" @@ -205,6 +214,18 @@ $else$ %ignore $struct_name$::$member.name$(); %rename("%s") $struct_name$::$member.name$() const; +$if(member.typecode.isStringType && member.typecode.isBounded)$ +%template(fixed_string_$member.typecode.maxsize$) eprosima::fastcdr::fixed_string<$member.typecode.maxsize$>; +%extend $struct_name$ +{ + void $member.name$(const std::string& value) + { + eprosima::fastcdr::fixed_string<$member.typecode.maxsize$> tmp(value); + \$self->$member.name$(tmp); + } +} +$endif$ + $endif$ >> From b8c75484e1fa1a9bcccfc37db899bee91adbbd32 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 26 Feb 2025 10:45:30 +0100 Subject: [PATCH 2/4] Fix conflicts Signed-off-by: Miguel Company --- .../eprosima/fastcdr/idl/templates/TypesSwigInterface.stg | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 1d835132..054031fa 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -44,18 +44,14 @@ $ctx.directIncludeDependencies : {include | %include "$include$.i"}; separator=" %} %include -<<<<<<< HEAD #if FASTCDR_VERSION_MAJOR > 1 -%import(module="fastdds") "fastcdr/xcdr/optional.hpp" -#endif -======= $if(ctx.thereIsOptionalAnnotation)$ %import(module="fastdds") "fastcdr/xcdr/optional.hpp" $endif$ $if(ctx.thereIsString)$ %import(module="fastdds") "fastcdr/cdr/fixed_size_string.hpp" $endif$ ->>>>>>> 8eaca9a (Fix python code generation for bounded strings (#440)) +#endif %import(module="fastdds") "fastdds/dds/core/LoanableCollection.hpp" %import(module="fastdds") "fastdds/dds/core/LoanableTypedCollection.hpp" %import(module="fastdds") "fastdds/dds/core/LoanableSequence.hpp" From 726aa910ba1dc26f9cd176abc8aed0b28d254c92 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Wed, 26 Feb 2025 10:47:32 +0100 Subject: [PATCH 3/4] Conditional build of fastcdr v2 features Signed-off-by: Miguel Company --- .../com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 054031fa..9228375a 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -211,6 +211,7 @@ $else$ %rename("%s") $struct_name$::$member.name$() const; $if(member.typecode.isStringType && member.typecode.isBounded)$ +#if FASTCDR_VERSION_MAJOR > 1 %template(fixed_string_$member.typecode.maxsize$) eprosima::fastcdr::fixed_string<$member.typecode.maxsize$>; %extend $struct_name$ { @@ -220,6 +221,7 @@ $if(member.typecode.isStringType && member.typecode.isBounded)$ \$self->$member.name$(tmp); } } +#endif $endif$ $endif$ From db66b322421239cbdfa5028e140757cb17427d88 Mon Sep 17 00:00:00 2001 From: Miguel Company Date: Thu, 25 Sep 2025 15:16:16 +0200 Subject: [PATCH 4/4] Always import optional header Signed-off-by: Miguel Company --- .../com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 9228375a..c51bafbd 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -45,9 +45,7 @@ $ctx.directIncludeDependencies : {include | %include "$include$.i"}; separator=" %include #if FASTCDR_VERSION_MAJOR > 1 -$if(ctx.thereIsOptionalAnnotation)$ %import(module="fastdds") "fastcdr/xcdr/optional.hpp" -$endif$ $if(ctx.thereIsString)$ %import(module="fastdds") "fastcdr/cdr/fixed_size_string.hpp" $endif$