From 7653b00b572c1270fb78f5b99df1688509af369e Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 16:19:51 +0200 Subject: [PATCH 1/8] First ideas for optional support for dds4ccm * connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl: * ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb: * ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb: --- .../unkeyed_writer/data/unkeyed_writer.idl | 1 + .../templates/typesupport/src/toplevel_seq.erb | 6 +++++- .../facets/dds/templates/udt_traits/struct.erb | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl b/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl index 8fe1f211..563ec596 100644 --- a/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl +++ b/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl @@ -22,6 +22,7 @@ module UnkeyedWriterTest /// the receiver can check that we don't get duplicate /// samples unsigned long sample_index; + @optional ::OctetSeq ff; }; }; diff --git a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb index 62453070..6a49d090 100644 --- a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb +++ b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb @@ -1,7 +1,11 @@ %if has_toplevel_annotation? % unaliased_type = 'std::vector<'+resolved_cxxtype+'>' -// Unaliased type : <%= unaliased_type %> +%annotations.each do |_a| +% unaliased_type = _a.idl_stringified + unaliased_type +%end + +// Unaliased type : <%= annotations %><%= unaliased_type %> // Scoped element type : <%= scoped_cxxtype %> % ddsx11_alias_md5 = (unaliased_type+scoped_cxxtype).to_md5 // DDSX11 MD5 : <%= ddsx11_alias_md5 %> diff --git a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb index 665fb39d..8be542db 100644 --- a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb +++ b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb @@ -15,7 +15,14 @@ namespace DDSX11 <%= native_scoped_cxxtype %> &to, const <%= scoped_cxxtype %> &from) { %members.each do |_m| +%if _m.optional? + if (from.<%= _m.cxxname %> ().has_value()) { + #todo memalloc + ::DDSX11::to_dds (*to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ().value()); + } +% else ::DDSX11::to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ()); +% end %end return to; } @@ -27,7 +34,18 @@ namespace DDSX11 <%= scoped_cxxtype %> &to, const <%= native_scoped_cxxtype %> &from) { %members.each do |_m| +%if _m.optional? + if (from.<%= _m.cxxname %> != nullptr) + { + ::DDSX11::from_dds (to.<%= _m.cxxname %> ().value (), *from.<%= _m.cxxname %>); + } + else + { + to.<%= _m.cxxname %> ().reset (); + } +% else ::DDSX11::from_dds (to.<%= _m.cxxname %> (), from.<%= _m.cxxname %>); +% end %end return to; } From 6f65b03c9c0178bd81a722b697912d81a1596b49 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 16:27:22 +0200 Subject: [PATCH 2/8] Add mem alloc support * ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb: --- .../ccmx11/facets/dds/templates/udt_traits/struct.erb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb index 8be542db..36c1bb56 100644 --- a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb +++ b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb @@ -17,9 +17,17 @@ namespace DDSX11 %members.each do |_m| %if _m.optional? if (from.<%= _m.cxxname %> ().has_value()) { - #todo memalloc + if (to.<%= _m.cxxname %> == nullptr) + { + to.<%= _m.cxxname %> = new <%= _m.native_scoped_cxxtype %>; + } ::DDSX11::to_dds (*to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ().value()); } + else + { + delete to.<%= _m.cxxname %>; + to.<%= _m.cxxname %> = nullptr; + } % else ::DDSX11::to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ()); % end From a12e6b3b61cd0985abcc13158d0f7e90848fd2ed Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 16:52:17 +0200 Subject: [PATCH 3/8] Use emplace * ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb: --- ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb index 36c1bb56..03c18809 100644 --- a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb +++ b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb @@ -45,7 +45,7 @@ namespace DDSX11 %if _m.optional? if (from.<%= _m.cxxname %> != nullptr) { - ::DDSX11::from_dds (to.<%= _m.cxxname %> ().value (), *from.<%= _m.cxxname %>); + ::DDSX11::from_dds (to.<%= _m.cxxname %> ().emplace (), *from.<%= _m.cxxname %>); } else { From 65c433b49d339db3cfd5365302188bb8caf74d76 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 17:06:44 +0200 Subject: [PATCH 4/8] Further simplified optional support * ddsx11/dds/dds_conversion_traits.h: * ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb: --- ddsx11/dds/dds_conversion_traits.h | 36 +++++++++++++++++++ .../dds/templates/udt_traits/struct.erb | 30 ++-------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/ddsx11/dds/dds_conversion_traits.h b/ddsx11/dds/dds_conversion_traits.h index f9519b20..81c6f2d4 100644 --- a/ddsx11/dds/dds_conversion_traits.h +++ b/ddsx11/dds/dds_conversion_traits.h @@ -233,4 +233,40 @@ namespace DDSX11 //@} } // namespace DDSX11 +namespace DDSX11 +{ + template + void optional_to_dds (DDS_DATA_TYPE*& to, DATA_TYPE& from) + { + if (from.has_value()) { + if (to == nullptr) + { + to = new DDS_DATA_TYPE; + } + ::DDSX11::to_dds (*to, from.value()); + } + else + { + delete to; + to = nullptr; + } + } + + template + void optional_from_dds (DATA_TYPE& to, DDS_DATA_TYPE* from) + { + if (from != nullptr) + { + ::DDSX11::from_dds (to.emplace (), *from); + } + else + { + to.reset (); + } + } + +} + + + #endif /* DDSX11_IMPL_CONVERSION_TRAITS_BASE_H_ */ diff --git a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb index 03c18809..31ecfbc9 100644 --- a/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb +++ b/ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb @@ -15,22 +15,7 @@ namespace DDSX11 <%= native_scoped_cxxtype %> &to, const <%= scoped_cxxtype %> &from) { %members.each do |_m| -%if _m.optional? - if (from.<%= _m.cxxname %> ().has_value()) { - if (to.<%= _m.cxxname %> == nullptr) - { - to.<%= _m.cxxname %> = new <%= _m.native_scoped_cxxtype %>; - } - ::DDSX11::to_dds (*to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ().value()); - } - else - { - delete to.<%= _m.cxxname %>; - to.<%= _m.cxxname %> = nullptr; - } -% else - ::DDSX11::to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ()); -% end + ::DDSX11::<%if _m.optional? %>optional_<% end %>to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ()); %end return to; } @@ -42,18 +27,7 @@ namespace DDSX11 <%= scoped_cxxtype %> &to, const <%= native_scoped_cxxtype %> &from) { %members.each do |_m| -%if _m.optional? - if (from.<%= _m.cxxname %> != nullptr) - { - ::DDSX11::from_dds (to.<%= _m.cxxname %> ().emplace (), *from.<%= _m.cxxname %>); - } - else - { - to.<%= _m.cxxname %> ().reset (); - } -% else - ::DDSX11::from_dds (to.<%= _m.cxxname %> (), from.<%= _m.cxxname %>); -% end + ::DDSX11::<%if _m.optional? %>optional_<% end %>from_dds (to.<%= _m.cxxname %> (), from.<%= _m.cxxname %>); %end return to; } From 9900b197741faf82df53af0946300cf8055a0795 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 17:19:05 +0200 Subject: [PATCH 5/8] Revert changes * connectors/dds4ccm/tests/unkeyed_writer/components/sender/unkeyed_writer_sender_exec.cpp: * connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl: * ddsx11/dds/dds_conversion_traits.h: --- .../sender/unkeyed_writer_sender_exec.cpp | 1 - .../unkeyed_writer/data/unkeyed_writer.idl | 1 - ddsx11/dds/dds_conversion_traits.h | 26 ++++++++----------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/connectors/dds4ccm/tests/unkeyed_writer/components/sender/unkeyed_writer_sender_exec.cpp b/connectors/dds4ccm/tests/unkeyed_writer/components/sender/unkeyed_writer_sender_exec.cpp index a67d945c..c87f8916 100644 --- a/connectors/dds4ccm/tests/unkeyed_writer/components/sender/unkeyed_writer_sender_exec.cpp +++ b/connectors/dds4ccm/tests/unkeyed_writer/components/sender/unkeyed_writer_sender_exec.cpp @@ -16,7 +16,6 @@ //@@{__RIDL_REGEN_MARKER__} - END : UnkeyedWriterTest_Sender_Impl[user_includes] //@@{__RIDL_REGEN_MARKER__} - BEGIN : UnkeyedWriterTest_Sender_Impl[user_global_impl] -// Your declarations here //@@{__RIDL_REGEN_MARKER__} - END : UnkeyedWriterTest_Sender_Impl[user_global_impl] namespace UnkeyedWriterTest_Sender_Impl diff --git a/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl b/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl index 563ec596..8fe1f211 100644 --- a/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl +++ b/connectors/dds4ccm/tests/unkeyed_writer/data/unkeyed_writer.idl @@ -22,7 +22,6 @@ module UnkeyedWriterTest /// the receiver can check that we don't get duplicate /// samples unsigned long sample_index; - @optional ::OctetSeq ff; }; }; diff --git a/ddsx11/dds/dds_conversion_traits.h b/ddsx11/dds/dds_conversion_traits.h index 81c6f2d4..53aeb996 100644 --- a/ddsx11/dds/dds_conversion_traits.h +++ b/ddsx11/dds/dds_conversion_traits.h @@ -231,31 +231,30 @@ namespace DDSX11 typedef out inout; }; //@} -} // namespace DDSX11 -namespace DDSX11 -{ + template void optional_to_dds (DDS_DATA_TYPE*& to, DATA_TYPE& from) { - if (from.has_value()) { - if (to == nullptr) + if (from.has_value()) { - to = new DDS_DATA_TYPE; - } - ::DDSX11::to_dds (*to, from.value()); + if (to == nullptr) + { + to = new DDS_DATA_TYPE; + } + ::DDSX11::to_dds (*to, from.value()); } else { - delete to; - to = nullptr; + delete to; + to = nullptr; } } template void optional_from_dds (DATA_TYPE& to, DDS_DATA_TYPE* from) { - if (from != nullptr) + if (from != nullptr) { ::DDSX11::from_dds (to.emplace (), *from); } @@ -264,9 +263,6 @@ namespace DDSX11 to.reset (); } } - -} - - +} // namespace DDSX11 #endif /* DDSX11_IMPL_CONVERSION_TRAITS_BASE_H_ */ From fe4d3afbb4cd5e14cdfb141d797b09577467c642 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 17:19:58 +0200 Subject: [PATCH 6/8] REvert test code * ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb: --- .../facets/dds/templates/typesupport/src/toplevel_seq.erb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb index 6a49d090..9dddeda5 100644 --- a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb +++ b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb @@ -1,10 +1,6 @@ %if has_toplevel_annotation? % unaliased_type = 'std::vector<'+resolved_cxxtype+'>' -%annotations.each do |_a| -% unaliased_type = _a.idl_stringified + unaliased_type -%end - // Unaliased type : <%= annotations %><%= unaliased_type %> // Scoped element type : <%= scoped_cxxtype %> % ddsx11_alias_md5 = (unaliased_type+scoped_cxxtype).to_md5 From 98b0c0f948d48da9c39d2eb22ac28703a2b94d1f Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Thu, 12 Sep 2024 17:20:20 +0200 Subject: [PATCH 7/8] revert * ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb: --- .../facets/dds/templates/typesupport/src/toplevel_seq.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb index 9dddeda5..62453070 100644 --- a/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb +++ b/ridlbe/ccmx11/facets/dds/templates/typesupport/src/toplevel_seq.erb @@ -1,7 +1,7 @@ %if has_toplevel_annotation? % unaliased_type = 'std::vector<'+resolved_cxxtype+'>' -// Unaliased type : <%= annotations %><%= unaliased_type %> +// Unaliased type : <%= unaliased_type %> // Scoped element type : <%= scoped_cxxtype %> % ddsx11_alias_md5 = (unaliased_type+scoped_cxxtype).to_md5 // DDSX11 MD5 : <%= ddsx11_alias_md5 %> From 268badd5d55f6de1cb56d41adee9f01219d0c504 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Fri, 13 Sep 2024 08:31:07 +0200 Subject: [PATCH 8/8] Moved optional to rti code * ddsx11/dds/dds_conversion_traits.h: * ddsx11/vendors/ndds/dds/ndds_base_traits.h: --- ddsx11/dds/dds_conversion_traits.h | 32 ---------------------- ddsx11/vendors/ndds/dds/ndds_base_traits.h | 32 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/ddsx11/dds/dds_conversion_traits.h b/ddsx11/dds/dds_conversion_traits.h index 53aeb996..f9519b20 100644 --- a/ddsx11/dds/dds_conversion_traits.h +++ b/ddsx11/dds/dds_conversion_traits.h @@ -231,38 +231,6 @@ namespace DDSX11 typedef out inout; }; //@} - - - template - void optional_to_dds (DDS_DATA_TYPE*& to, DATA_TYPE& from) - { - if (from.has_value()) - { - if (to == nullptr) - { - to = new DDS_DATA_TYPE; - } - ::DDSX11::to_dds (*to, from.value()); - } - else - { - delete to; - to = nullptr; - } - } - - template - void optional_from_dds (DATA_TYPE& to, DDS_DATA_TYPE* from) - { - if (from != nullptr) - { - ::DDSX11::from_dds (to.emplace (), *from); - } - else - { - to.reset (); - } - } } // namespace DDSX11 #endif /* DDSX11_IMPL_CONVERSION_TRAITS_BASE_H_ */ diff --git a/ddsx11/vendors/ndds/dds/ndds_base_traits.h b/ddsx11/vendors/ndds/dds/ndds_base_traits.h index abb34871..fa9ff8a7 100644 --- a/ddsx11/vendors/ndds/dds/ndds_base_traits.h +++ b/ddsx11/vendors/ndds/dds/ndds_base_traits.h @@ -21,7 +21,6 @@ constexpr uint32_t max_member_string_size () { return 255; } namespace DDSX11 { - /** * Standard type DDS traits for NDDS implementation */ @@ -459,6 +458,37 @@ namespace DDSX11 { return sequence_from_dds (to, from); } + + template + void optional_to_dds (DDS_DATA_TYPE*& to, DATA_TYPE& from) + { + if (from.has_value()) + { + if (to == nullptr) + { + to = new DDS_DATA_TYPE; + } + ::DDSX11::to_dds (*to, from.value()); + } + else + { + delete to; + to = nullptr; + } + } + + template + void optional_from_dds (DATA_TYPE& to, DDS_DATA_TYPE* from) + { + if (from != nullptr) + { + ::DDSX11::from_dds (to.emplace (), *from); + } + else + { + to.reset (); + } + } } #endif /* DDSX11_IMPL_NDDS_BASE_TRAITS_H_ */