From c2194fe4ef9a94c7cb2793ebccc23cafbe39eb27 Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Tue, 30 Jul 2024 23:54:43 +0200 Subject: [PATCH] [#264] Enable slice methods only for slice Payload; remove reinterpret cast --- iceoryx2-ffi/cxx/include/iox2/publisher.hpp | 5 +++++ iceoryx2-ffi/cxx/include/iox2/sample.hpp | 8 +++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/iceoryx2-ffi/cxx/include/iox2/publisher.hpp b/iceoryx2-ffi/cxx/include/iox2/publisher.hpp index be87ed01a..efe79fbb9 100644 --- a/iceoryx2-ffi/cxx/include/iox2/publisher.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/publisher.hpp @@ -24,6 +24,7 @@ #include "iox2/unique_port_id.hpp" #include +#include namespace iox2 { /// Sending endpoint of a publish-subscriber based communication. @@ -64,6 +65,7 @@ class Publisher { /// [`Payload`]. /// /// On failure it returns [`PublisherLoanError`] describing the failure. + template ::VALUE, T>> auto loan_slice(uint64_t number_of_elements) -> iox::expected, PublisherLoanError>; @@ -71,6 +73,7 @@ class Publisher { /// The user has to initialize the payload before it can be sent. /// /// On failure it returns [`PublisherLoanError`] describing the failure. + template ::VALUE, T>> auto loan_slice_uninit(uint64_t number_of_elements) -> iox::expected, PublisherLoanError>; @@ -171,12 +174,14 @@ Publisher::loan() -> iox::expected +template inline auto Publisher::loan_slice(const uint64_t number_of_elements) -> iox::expected, PublisherLoanError> { IOX_TODO(); } template +template inline auto Publisher::loan_slice_uninit(const uint64_t number_of_elements) -> iox::expected, PublisherLoanError> { IOX_TODO(); diff --git a/iceoryx2-ffi/cxx/include/iox2/sample.hpp b/iceoryx2-ffi/cxx/include/iox2/sample.hpp index bf07fba12..013a3e685 100644 --- a/iceoryx2-ffi/cxx/include/iox2/sample.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/sample.hpp @@ -117,15 +117,13 @@ inline auto Sample::operator->() const -> const Payload* template inline auto Sample::payload() const -> const Payload& { auto* ref_handle = iox2_cast_sample_ref_h(m_handle); - const Payload* payload_ptr = nullptr; + const void* payload_ptr = nullptr; size_t payload_len = 0; - // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast), no other way for type erasure - iox2_sample_payload(ref_handle, reinterpret_cast(&payload_ptr), &payload_len); - // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast) + iox2_sample_payload(ref_handle, &payload_ptr, &payload_len); IOX_ASSERT(sizeof(Payload) <= payload_len, ""); - return *payload_ptr; + return *static_cast(payload_ptr); } template