From 30f7d250cb05af469b03395c02fc21b7a8454a48 Mon Sep 17 00:00:00 2001 From: Jeff Ithier Date: Mon, 18 Nov 2024 16:44:34 +0100 Subject: [PATCH] [#500] Make bytes() method const --- iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp | 16 ++++++++-------- iceoryx2-ffi/cxx/src/unique_port_id.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp b/iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp index cc423795f..d03d57b09 100644 --- a/iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp +++ b/iceoryx2-ffi/cxx/include/iox2/unique_port_id.hpp @@ -31,7 +31,7 @@ class UniquePublisherId { auto operator=(UniquePublisherId&& rhs) noexcept -> UniquePublisherId&; ~UniquePublisherId(); - auto bytes() -> const iox::optional&; + auto bytes() const -> const iox::optional&; private: template @@ -44,7 +44,7 @@ class UniquePublisherId { void drop(); iox2_unique_publisher_id_h m_handle = nullptr; - iox::optional m_raw_id; + mutable iox::optional m_raw_id; }; /// The system-wide unique id of a [`Subscriber`]. @@ -56,7 +56,7 @@ class UniqueSubscriberId { auto operator=(UniqueSubscriberId&& rhs) noexcept -> UniqueSubscriberId&; ~UniqueSubscriberId(); - auto bytes() -> const iox::optional&; + auto bytes() const -> const iox::optional&; private: template @@ -68,7 +68,7 @@ class UniqueSubscriberId { void drop(); iox2_unique_subscriber_id_h m_handle = nullptr; - iox::optional m_raw_id; + mutable iox::optional m_raw_id; }; /// The system-wide unique id of a [`Notifier`]. @@ -80,7 +80,7 @@ class UniqueNotifierId { auto operator=(UniqueNotifierId&& rhs) noexcept -> UniqueNotifierId&; ~UniqueNotifierId(); - auto bytes() -> const iox::optional&; + auto bytes() const -> const iox::optional&; private: template @@ -92,7 +92,7 @@ class UniqueNotifierId { void drop(); iox2_unique_notifier_id_h m_handle = nullptr; - iox::optional m_raw_id; + mutable iox::optional m_raw_id; }; /// The system-wide unique id of a [`Listener`]. @@ -104,7 +104,7 @@ class UniqueListenerId { auto operator=(UniqueListenerId&& rhs) noexcept -> UniqueListenerId&; ~UniqueListenerId(); - auto bytes() -> const iox::optional&; + auto bytes() const -> const iox::optional&; private: template @@ -116,7 +116,7 @@ class UniqueListenerId { void drop(); iox2_unique_listener_id_h m_handle = nullptr; - iox::optional m_raw_id; + mutable iox::optional m_raw_id; }; auto operator==(const UniquePublisherId& lhs, const UniquePublisherId& rhs) -> bool; diff --git a/iceoryx2-ffi/cxx/src/unique_port_id.cpp b/iceoryx2-ffi/cxx/src/unique_port_id.cpp index 07b07409a..533cc95d6 100644 --- a/iceoryx2-ffi/cxx/src/unique_port_id.cpp +++ b/iceoryx2-ffi/cxx/src/unique_port_id.cpp @@ -43,7 +43,7 @@ UniquePublisherId::UniquePublisherId(iox2_unique_publisher_id_h handle) : m_handle { handle } { } -auto UniquePublisherId::bytes() -> const iox::optional& { +auto UniquePublisherId::bytes() const -> const iox::optional& { if (!m_raw_id.has_value() && m_handle != nullptr) { RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 }; iox2_unique_publisher_id_value(m_handle, bytes.data(), bytes.size()); @@ -90,7 +90,7 @@ UniqueSubscriberId::UniqueSubscriberId(iox2_unique_subscriber_id_h handle) : m_handle { handle } { } -auto UniqueSubscriberId::bytes() -> const iox::optional& { +auto UniqueSubscriberId::bytes() const -> const iox::optional& { if (!m_raw_id.has_value() && m_handle != nullptr) { RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 }; iox2_unique_subscriber_id_value(m_handle, bytes.data(), bytes.size()); @@ -136,7 +136,7 @@ UniqueNotifierId::UniqueNotifierId(iox2_unique_notifier_id_h handle) : m_handle { handle } { } -auto UniqueNotifierId::bytes() -> const iox::optional& { +auto UniqueNotifierId::bytes() const -> const iox::optional& { if (!m_raw_id.has_value() && m_handle != nullptr) { RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 }; iox2_unique_notifier_id_value(m_handle, bytes.data(), bytes.size()); @@ -182,7 +182,7 @@ UniqueListenerId::UniqueListenerId(iox2_unique_listener_id_h handle) : m_handle { handle } { } -auto UniqueListenerId::bytes() -> const iox::optional& { +auto UniqueListenerId::bytes() const -> const iox::optional& { if (!m_raw_id.has_value() && m_handle != nullptr) { RawIdType bytes { UNIQUE_PORT_ID_LENGTH, 0 }; iox2_unique_listener_id_value(m_handle, bytes.data(), bytes.size());