Skip to content

Commit

Permalink
Merge pull request #444 from jwillemsen/jwi-dds4ccmoptional
Browse files Browse the repository at this point in the history
Add support for @optional to DDSX11 conversion code
  • Loading branch information
jwillemsen authored Sep 13, 2024
2 parents f9fa8df + 268badd commit 4ff0e16
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
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

0 comments on commit 4ff0e16

Please sign in to comment.