13#ifndef IOX2_SAMPLE_MUT_HPP
14#define IOX2_SAMPLE_MUT_HPP
20#include "iox2/iceoryx2.h"
48template <ServiceType S,
typename Payload,
typename UserHeader>
65 template <typename T = UserHeader, typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value, T>>
69 template <typename T = UserHeader, typename = std::enable_if_t<!std::is_same<
void, UserHeader>::value, T>>
73 template <typename T = Payload, typename = std::enable_if_t<!bb::IsSlice<T>::VALUE,
void>>
74 auto
payload() const -> const ValueType&;
77 template <typename T = Payload, typename = std::enable_if_t<!bb::IsSlice<T>::VALUE,
void>>
80 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
81 auto
payload() const -> bb::ImmutableSlice<ValueType>;
83 template <typename T = Payload, typename = std::enable_if_t<bb::IsSlice<T>::VALUE,
void>>
92 template <
ServiceType ST, typename PayloadT, typename UserHeaderT>
101 iox2_sample_mut_t m_sample;
102 iox2_sample_mut_h m_handle =
nullptr;
105template <
ServiceType S, typename Payload, typename UserHeader>
106inline
void SampleMut<S, Payload, UserHeader>::drop() {
107 if (m_handle !=
nullptr) {
108 iox2_sample_mut_drop(m_handle);
114template <ServiceType S,
typename Payload,
typename UserHeader>
116 *
this = std::move(rhs);
121void iox2_sample_mut_move(iox2_sample_mut_t*, iox2_sample_mut_t*, iox2_sample_mut_h*);
125template <ServiceType S,
typename Payload,
typename UserHeader>
130 internal::iox2_sample_mut_move(&rhs.m_sample, &m_sample, &m_handle);
131 rhs.m_handle =
nullptr;
137template <ServiceType S,
typename Payload,
typename UserHeader>
142template <ServiceType S,
typename Payload,
typename UserHeader>
144 iox2_publish_subscribe_header_h header_handle =
nullptr;
145 iox2_sample_mut_header(&m_handle,
nullptr, &header_handle);
150template <ServiceType S,
typename Payload,
typename UserHeader>
151template <
typename T,
typename>
153 const void* ptr =
nullptr;
155 iox2_sample_mut_user_header(&m_handle, &ptr);
157 return *
static_cast<const T*
>(ptr);
160template <ServiceType S,
typename Payload,
typename UserHeader>
161template <
typename T,
typename>
165 iox2_sample_mut_user_header_mut(&m_handle, &ptr);
167 return *
static_cast<T*
>(ptr);
170template <ServiceType S,
typename Payload,
typename UserHeader>
171template <
typename T,
typename>
173 const void* ptr =
nullptr;
175 iox2_sample_mut_payload(&m_handle, &ptr,
nullptr);
177 return *
static_cast<const ValueType*
>(ptr);
180template <ServiceType S,
typename Payload,
typename UserHeader>
181template <
typename T,
typename>
185 iox2_sample_mut_payload_mut(&m_handle, &ptr,
nullptr);
187 return *
static_cast<ValueType*
>(ptr);
190template <ServiceType S,
typename Payload,
typename UserHeader>
191template <
typename T,
typename>
193 const void* ptr =
nullptr;
194 size_t number_of_elements = 0;
196 iox2_sample_mut_payload(&m_handle, &ptr, &number_of_elements);
200 auto length = number_of_elements;
201 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
202 length = iox2_sample_mut_payload_number_of_bytes(&m_handle);
205 return bb::ImmutableSlice<ValueType>(
static_cast<const ValueType*
>(ptr), length);
208template <ServiceType S,
typename Payload,
typename UserHeader>
209template <
typename T,
typename>
212 size_t number_of_elements = 0;
214 iox2_sample_mut_payload_mut(&m_handle, &ptr, &number_of_elements);
216 auto length = number_of_elements;
217 if (std::is_same<ValueType, CustomPayloadMarker>::value) {
218 length = iox2_sample_mut_payload_number_of_bytes(&m_handle);
221 return bb::MutableSlice<ValueType>(
static_cast<ValueType*
>(ptr), length);
224template <ServiceType S,
typename Payload,
typename UserHeader>
226 size_t number_of_recipients = 0;
227 auto result = iox2_sample_mut_send(sample.m_handle, &number_of_recipients);
228 sample.m_handle =
nullptr;
230 if (result == IOX2_OK) {
231 return number_of_recipients;
234 return bb::err(bb::into<SendError>(result));
Sending endpoint of a publish-subscriber based communication.
auto user_header_mut() -> T &
Returns a mutable reference to the user_header of the [Sample].
auto header() const -> HeaderPublishSubscribe
Returns a reference to the [Header] of the [Sample].
SampleMut(const SampleMut &)=delete
auto payload_mut() -> ValueType &
Returns a reference to the payload of the sample.
friend auto send(SampleMut< ST, PayloadT, UserHeaderT > &&sample) -> bb::Expected< size_t, SendError >
auto payload() const -> const ValueType &
Returns a reference to the const payload of the sample.
auto user_header() const -> const T &
Returns a reference to the user_header of the [Sample].
auto operator=(const SampleMut &) -> SampleMut &=delete
auto operator=(SampleMut &&rhs) noexcept -> SampleMut &
constexpr auto err(const E &error) -> Unexpected< E >
iox2::bb::variation::Expected< T, E > Expected
SendError
Failure that can be emitted when data is sent.