Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @optional to DDSX11 conversion code #444

Merged
merged 8 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 31 additions & 1 deletion ddsx11/vendors/ndds/dds/ndds_base_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ constexpr uint32_t max_member_string_size () { return 255; }

namespace DDSX11
{

/**
* Standard type DDS traits for NDDS implementation
*/
Expand Down Expand Up @@ -459,6 +458,37 @@ namespace DDSX11
{
return sequence_from_dds (to, from);
}

template <typename DDS_DATA_TYPE, typename DATA_TYPE>
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 <typename DDS_DATA_TYPE, typename DATA_TYPE>
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_ */
4 changes: 2 additions & 2 deletions ridlbe/ccmx11/facets/dds/templates/udt_traits/struct.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DDSX11
<%= native_scoped_cxxtype %> &to, const <%= scoped_cxxtype %> &from)
{
%members.each do |_m|
::DDSX11::to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ());
::DDSX11::<%if _m.optional? %>optional_<% end %>to_dds (to.<%= _m.cxxname %>, from.<%= _m.cxxname %> ());
%end
return to;
}
Expand All @@ -27,7 +27,7 @@ namespace DDSX11
<%= scoped_cxxtype %> &to, const <%= native_scoped_cxxtype %> &from)
{
%members.each do |_m|
::DDSX11::from_dds (to.<%= _m.cxxname %> (), from.<%= _m.cxxname %>);
::DDSX11::<%if _m.optional? %>optional_<% end %>from_dds (to.<%= _m.cxxname %> (), from.<%= _m.cxxname %>);
%end
return to;
}
Expand Down