iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
entry_value_uninit.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 Contributors to the Eclipse Foundation
2//
3// See the NOTICE file(s) distributed with this work for additional
4// information regarding copyright ownership.
5//
6// This program and the accompanying materials are made available under the
7// terms of the Apache Software License 2.0 which is available at
8// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
9// which is available at https://opensource.org/licenses/MIT.
10//
11// SPDX-License-Identifier: Apache-2.0 OR MIT
12
13#ifndef IOX2_ENTRY_VALUE_UNINIT_HPP
14#define IOX2_ENTRY_VALUE_UNINIT_HPP
15
16#include <utility>
17
18#include "iox2/iceoryx2.h"
19#include "iox2/service_type.hpp"
20
21namespace iox2 {
22template <ServiceType, typename, typename>
23class EntryHandleMut;
24
26template <ServiceType S, typename KeyType, typename ValueType>
28 public:
29 EntryValueUninit(EntryValueUninit&& rhs) noexcept;
30 auto operator=(EntryValueUninit&& rhs) noexcept -> EntryValueUninit&;
31 ~EntryValueUninit() noexcept;
32
34 auto operator=(const EntryValueUninit&) -> EntryValueUninit& = delete;
35
38 template <ServiceType ST, typename KeyT, typename ValueT>
39 friend auto update_with_copy(EntryValueUninit<ST, KeyT, ValueT>&& self, ValueT value)
41
43 template <ServiceType ST, typename KeyT, typename ValueT>
45
48 auto value_mut() -> ValueType&;
49
52 template <ServiceType ST, typename KeyT, typename ValueT>
54
55 private:
56 template <ServiceType, typename, typename>
57 friend class EntryHandleMut;
58
59 template <ServiceType ST, typename KeyT, typename ValueT>
61
62 explicit EntryValueUninit(iox2_entry_handle_mut_h entry_handle);
63
64 void drop();
65
66 auto take_handle_ownership() -> iox2_entry_value_uninit_h;
67
68 // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init) m_entry_value_uninit is initialized in the the c'tor via iox2_entry_handle_mut_loan_uninit
69 iox2_entry_value_uninit_t m_entry_value_uninit;
70 iox2_entry_value_uninit_h m_handle = nullptr;
71};
72
73// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init) m_entry_value_uninit is initialized in the the c'tor via iox2_entry_handle_mut_loan_uninit
74template <ServiceType S, typename KeyType, typename ValueType>
75inline EntryValueUninit<S, KeyType, ValueType>::EntryValueUninit(iox2_entry_handle_mut_h entry_handle) {
76 iox2_entry_handle_mut_loan_uninit(
77 entry_handle, &m_entry_value_uninit, &m_handle, sizeof(ValueType), alignof(ValueType));
78}
79
80// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init,hicpp-member-init) m_entry_value_uninit will be initialized in the move assignment operator
81template <ServiceType S, typename KeyType, typename ValueType>
83 *this = std::move(rhs);
84}
85
86namespace internal {
87extern "C" {
88void iox2_entry_value_uninit_move(iox2_entry_value_uninit_t*, iox2_entry_value_uninit_t*, iox2_entry_value_uninit_h*);
89}
90} // namespace internal
91
92template <ServiceType S, typename KeyType, typename ValueType>
94 if (this != &rhs) {
95 drop();
96
97 internal::iox2_entry_value_uninit_move(&rhs.m_entry_value_uninit, &m_entry_value_uninit, &m_handle);
98 rhs.m_handle = nullptr;
99 }
100
101 return *this;
102}
103
104template <ServiceType S, typename KeyType, typename ValueType>
108
109template <ServiceType S, typename KeyType, typename ValueType>
112 new (&self.value_mut()) ValueType(std::forward<ValueType>(value));
113
114 iox2_entry_handle_mut_h entry_handle_mut_handle = nullptr;
115 iox2_entry_value_uninit_update(self.take_handle_ownership(), nullptr, &entry_handle_mut_handle);
116
117 EntryHandleMut<S, KeyType, ValueType> entry_handle_mut(entry_handle_mut_handle);
118 return entry_handle_mut;
119}
120
121template <ServiceType S, typename KeyType, typename ValueType>
123 iox2_entry_handle_mut_h entry_handle_mut_handle = nullptr;
124
125 iox2_entry_value_uninit_discard(self.take_handle_ownership(), nullptr, &entry_handle_mut_handle);
126
127 EntryHandleMut<S, KeyType, ValueType> entry_handle_mut(entry_handle_mut_handle);
128 return entry_handle_mut;
129}
130
131template <ServiceType S, typename KeyType, typename ValueType>
133 void* value_ptr = nullptr;
134 iox2_entry_value_uninit_value_mut(&m_handle, &value_ptr);
135 return *static_cast<ValueType*>(value_ptr);
136}
137
138template <ServiceType S, typename KeyType, typename ValueType>
141 iox2_entry_handle_mut_h entry_handle_mut_handle = nullptr;
142 iox2_entry_value_uninit_update(self.take_handle_ownership(), nullptr, &entry_handle_mut_handle);
143
144 EntryHandleMut<S, KeyType, ValueType> entry_handle_mut(entry_handle_mut_handle);
145 return entry_handle_mut;
146}
147
148template <ServiceType S, typename KeyType, typename ValueType>
149inline void EntryValueUninit<S, KeyType, ValueType>::drop() {
150 if (m_handle != nullptr) {
151 iox2_entry_value_uninit_drop(m_handle);
152 m_handle = nullptr;
153 }
154}
155
156template <ServiceType S, typename KeyType, typename ValueType>
157inline auto EntryValueUninit<S, KeyType, ValueType>::take_handle_ownership() -> iox2_entry_value_uninit_h {
158 auto* result = m_handle;
159 m_handle = nullptr;
160 return result;
161}
162} // namespace iox2
163
164#endif
A handle for direct write access to a specific blackboard value.
Wrapper around an uninitialized entry value that can be used for a zero-copy update.
auto value_mut() -> ValueType &
EntryValueUninit(EntryValueUninit &&rhs) noexcept
EntryValueUninit(const EntryValueUninit &)=delete
friend auto update_with_copy(EntryValueUninit< ST, KeyT, ValueT > &&self, ValueT value) -> EntryHandleMut< ST, KeyT, ValueT >
auto operator=(EntryValueUninit &&rhs) noexcept -> EntryValueUninit &
friend auto discard(EntryValueUninit< ST, KeyT, ValueT > &&self) -> EntryHandleMut< ST, KeyT, ValueT >
Discard the [EntryValueUninit] and returns the original [EntryHandleMut].
friend auto assume_init_and_update(EntryValueUninit< ST, KeyT, ValueT > &&self) -> EntryHandleMut< ST, KeyT, ValueT >
auto operator=(const EntryValueUninit &) -> EntryValueUninit &=delete
friend auto loan_uninit(EntryHandleMut< ST, KeyT, ValueT > &&) -> EntryValueUninit< ST, KeyT, ValueT >
auto assume_init_and_update(EntryValueUninit< S, KeyType, ValueType > &&self) -> EntryHandleMut< S, KeyType, ValueType >
auto update_with_copy(EntryValueUninit< S, KeyType, ValueType > &&self, ValueType value) -> EntryHandleMut< S, KeyType, ValueType >
auto discard(EntryValueUninit< S, KeyType, ValueType > &&self) -> EntryHandleMut< S, KeyType, ValueType >