Skip to content

Commit f93a0e6

Browse files
authored
Merge pull request #2501 from ekxide/iox-2499-cxx-14-for-hoofs-subset
iox-#2499: C++14 support for 'iceoryx_hoofs' subset
2 parents 2304cb2 + 2f6834a commit f93a0e6

File tree

106 files changed

+2964
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2964
-341
lines changed

iceoryx_hoofs/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ configure_file(
2222
src = "cmake/iceoryx_hoofs_deployment.hpp.in",
2323
out = "generated/include/iox/iceoryx_hoofs_deployment.hpp",
2424
config_constants = {
25+
"IOX_HOOFS_SUBSET": "0",
2526
"IOX_MAX_NAMED_PIPE_MESSAGE_SIZE": "4096",
2627
"IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES": "10",
2728
# FIXME: for values see "iceoryx_hoofs/cmake/IceoryxHoofsDeployment.cmake" ... for now some nice defaults

iceoryx_hoofs/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ iox_add_library(
103103
posix/vocabulary/source/user_name.cpp
104104
)
105105

106+
if(IOX_USE_HOOFS_SUBSET_ONLY)
107+
set(IOX_HOOFS_SUBSET 1)
108+
else()
109+
set(IOX_HOOFS_SUBSET 0)
110+
endif()
111+
106112
if(NOT IOX_USE_HOOFS_SUBSET_ONLY)
107113
target_sources(
108114
iceoryx_hoofs

iceoryx_hoofs/cmake/iceoryx_hoofs_deployment.hpp.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "iox/iceoryx_hoofs_types.hpp"
2121

22+
#define IOX_HOOFS_SUBSET @IOX_HOOFS_SUBSET@
23+
2224
namespace iox
2325
{
2426
namespace build

iceoryx_hoofs/concurrent/buffer/include/iox/detail/spsc_sofi.inl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ inline std::pair<uint64_t, uint64_t> SpscSofi<ValueType, CapacityValue>::getRead
6868
template <class ValueType, uint64_t CapacityValue>
6969
inline uint64_t SpscSofi<ValueType, CapacityValue>::size() const noexcept
7070
{
71-
auto [readPosition, writePosition] = getReadWritePositions();
72-
return writePosition - readPosition;
71+
auto positions = getReadWritePositions();
72+
return std::get<1>(positions) - std::get<0>(positions);
7373
}
7474

7575
template <class ValueType, uint64_t CapacityValue>
@@ -92,8 +92,8 @@ inline bool SpscSofi<ValueType, CapacityValue>::setCapacity(const uint64_t newSi
9292
template <class ValueType, uint64_t CapacityValue>
9393
inline bool SpscSofi<ValueType, CapacityValue>::empty() const noexcept
9494
{
95-
auto [readPosition, writePosition] = getReadWritePositions();
96-
return readPosition == writePosition;
95+
auto positions = getReadWritePositions();
96+
return std::get<0>(positions) == std::get<1>(positions);
9797
}
9898

9999
template <class ValueType, uint64_t CapacityValue>

iceoryx_hoofs/container/include/iox/detail/fixed_position_container.inl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define IOX_HOOFS_CONTAINER_DETAIL_FIXED_POSITION_CONTAINER_INL
2020

2121
#include "iox/fixed_position_container.hpp"
22+
#include "iox/iceoryx_hoofs_deployment.hpp"
2223

2324
namespace iox
2425
{
@@ -97,7 +98,11 @@ inline void FixedPositionContainer<T, CAPACITY>::copy_and_move_impl(RhsType&& rh
9798
constexpr bool is_move = Helper::is_move;
9899

99100
// status array is not yet initialized for constructor creation
101+
#if IOX_HOOFS_SUBSET
102+
if (is_ctor)
103+
#else
100104
if constexpr (is_ctor)
105+
#endif
101106
{
102107
for (IndexType i = 0; i < CAPACITY; ++i)
103108
{
@@ -153,7 +158,11 @@ inline void FixedPositionContainer<T, CAPACITY>::copy_and_move_impl(RhsType&& rh
153158
m_size = rhs.m_size;
154159

155160
// reset rhs if is_move is true
161+
#if IOX_HOOFS_SUBSET
162+
if (is_move)
163+
#else
156164
if constexpr (is_move)
165+
#endif
157166
{
158167
rhs.clear();
159168
}

iceoryx_hoofs/container/include/iox/detail/vector.inl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define IOX_HOOFS_CONTAINER_VECTOR_INL
1919

2020
#include "iox/assertions.hpp"
21+
#include "iox/iceoryx_hoofs_deployment.hpp"
2122
#include "iox/vector.hpp"
2223

2324
#include <cstring> // std::memcpy, std::memmove
@@ -88,12 +89,14 @@ inline vector<T, Capacity>& vector<T, Capacity>::operator=(const vector& rhs) no
8889
uint64_t i{0U};
8990
const uint64_t rhsSize{rhs.size()};
9091

92+
#if not IOX_HOOFS_SUBSET
9193
if constexpr (std::is_trivially_copyable<T>::value)
9294
{
9395
std::memcpy(data(), rhs.data(), static_cast<size_t>(rhsSize) * sizeof(T));
9496
i = rhsSize;
9597
}
9698
else
99+
#endif
97100
{
98101
const uint64_t minSize{algorithm::minVal(m_size, rhsSize)};
99102

@@ -127,12 +130,14 @@ inline vector<T, Capacity>& vector<T, Capacity>::operator=(vector&& rhs) noexcep
127130
uint64_t i{0U};
128131
const uint64_t rhsSize{rhs.size()};
129132

133+
#if not IOX_HOOFS_SUBSET
130134
if constexpr (std::is_trivially_copyable<T>::value)
131135
{
132136
std::memcpy(data(), rhs.data(), static_cast<size_t>(rhsSize) * sizeof(T));
133137
i = rhsSize;
134138
}
135139
else
140+
#endif
136141
{
137142
const uint64_t minSize{algorithm::minVal(m_size, rhsSize)};
138143

@@ -189,7 +194,11 @@ inline bool vector<T, Capacity>::emplace_back(Targs&&... args) noexcept
189194
{
190195
if (m_size < Capacity)
191196
{
197+
#if IOX_HOOFS_SUBSET
198+
if (std::is_trivial<T>::value)
199+
#else
192200
if constexpr (std::is_trivial<T>::value)
201+
#endif
193202
{
194203
at_unchecked(m_size++) = T{std::forward<Targs>(args)...};
195204
}
@@ -217,6 +226,8 @@ inline bool vector<T, Capacity>::emplace(const uint64_t position, Targs&&... arg
217226
{
218227
return emplace_back(std::forward<Targs>(args)...);
219228
}
229+
230+
#if not IOX_HOOFS_SUBSET
220231
if constexpr (std::is_trivial<T>::value)
221232
{
222233
resize(size() + 1U);
@@ -225,13 +236,18 @@ inline bool vector<T, Capacity>::emplace(const uint64_t position, Targs&&... arg
225236
at_unchecked(position) = T{std::forward<Targs>(args)...};
226237
}
227238
else
239+
#endif
228240
{
229241
IOX_DISCARD_RESULT(emplace_back(std::move(at_unchecked(sizeBeforeEmplace - 1U))));
230242
for (uint64_t i{sizeBeforeEmplace - 1U}; i > position; --i)
231243
{
232244
at_unchecked(i) = std::move(at_unchecked(i - 1U));
233245
}
246+
#if IOX_HOOFS_SUBSET
247+
if (!std::is_trivially_destructible<T>::value)
248+
#else
234249
if constexpr (!std::is_trivially_destructible<T>::value)
250+
#endif
235251
{
236252
at_unchecked(position).~T();
237253
}
@@ -259,7 +275,11 @@ inline bool vector<T, Capacity>::pop_back() noexcept
259275
{
260276
if (m_size > 0U)
261277
{
278+
#if IOX_HOOFS_SUBSET
279+
if (std::is_trivial<T>::value)
280+
#else
262281
if constexpr (std::is_trivial<T>::value)
282+
#endif
263283
{
264284
m_size--;
265285
}
@@ -407,6 +427,7 @@ inline bool vector<T, Capacity>::erase(iterator position) noexcept
407427
// AXIVION Next Line AutosarC++19_03-M5.0.9 : False positive. Pointer arithmetic occurs here.
408428
uint64_t index{static_cast<uint64_t>(position - begin())};
409429
uint64_t n{index};
430+
#if not IOX_HOOFS_SUBSET
410431
if constexpr (std::is_trivially_copyable<T>::value)
411432
{
412433
if constexpr (!(std::is_trivially_destructible<T>::value))
@@ -417,6 +438,7 @@ inline bool vector<T, Capacity>::erase(iterator position) noexcept
417438
std::memmove(data() + n, data() + n + 1U, static_cast<size_t>(dataLen) * sizeof(T));
418439
}
419440
else
441+
#endif
420442
{
421443
while ((n + 1U) < size())
422444
{
@@ -452,7 +474,11 @@ inline const T& vector<T, Capacity>::at_unchecked(const uint64_t index) const no
452474
template <typename T, uint64_t Capacity>
453475
inline void vector<T, Capacity>::clearFrom(const uint64_t startPosition) noexcept
454476
{
477+
#if IOX_HOOFS_SUBSET
478+
if (std::is_trivially_destructible<T>::value)
479+
#else
455480
if constexpr (std::is_trivially_destructible<T>::value)
481+
#endif
456482
{
457483
m_size = startPosition;
458484
}

iceoryx_hoofs/container/include/iox/fixed_position_container.hpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,55 +127,55 @@ class FixedPositionContainer final
127127

128128
/// @brief Checks if the container is empty
129129
/// @return 'true' if the container is empty, 'false' otherwise
130-
[[nodiscard]] bool empty() const noexcept;
130+
IOX_NO_DISCARD bool empty() const noexcept;
131131

132132
/// @brief Checks if the container is full
133133
/// @return 'true' if the container is full, 'false' otherwise
134-
[[nodiscard]] bool full() const noexcept;
134+
IOX_NO_DISCARD bool full() const noexcept;
135135

136136
/// @brief Get the number of used slots in the container
137137
/// @return the number of used slots
138-
[[nodiscard]] uint64_t size() const noexcept;
138+
IOX_NO_DISCARD uint64_t size() const noexcept;
139139

140140
/// @brief Get the capacity of the container
141141
/// @return the number of available slots
142-
[[nodiscard]] constexpr uint64_t capacity() const noexcept;
142+
IOX_NO_DISCARD constexpr uint64_t capacity() const noexcept;
143143

144144
/// @brief Get the iterator to the element pointed to by the index
145145
/// @param[in] index of the element the for the iterator
146146
/// @return iterator pointing to the element at index or end iterator if index was out of bounds or index pointed to
147147
/// an empty slot
148-
[[nodiscard]] Iterator iter_from_index(const IndexType index);
148+
IOX_NO_DISCARD Iterator iter_from_index(const IndexType index);
149149

150150
/// @brief Get the const iterator to the element pointed to by the index
151151
/// @param[in] index of the element the for the iterator
152152
/// @return iterator pointing to the element at index or end iterator if index was out of bounds or index pointed to
153153
/// an empty slot
154-
[[nodiscard]] ConstIterator iter_from_index(const IndexType index) const;
154+
IOX_NO_DISCARD ConstIterator iter_from_index(const IndexType index) const;
155155

156156
/// @brief Get an iterator pointing to the beginning of the container
157157
/// @return iterator pointing to the beginning of the container
158-
[[nodiscard]] Iterator begin() noexcept;
158+
IOX_NO_DISCARD Iterator begin() noexcept;
159159

160160
/// @brief Get a const iterator pointing to the beginning of the container
161161
/// @return const iterator pointing to the beginning of the container
162-
[[nodiscard]] ConstIterator begin() const noexcept;
162+
IOX_NO_DISCARD ConstIterator begin() const noexcept;
163163

164164
/// @brief Get a const iterator pointing to the beginning of the container
165165
/// @return const iterator pointing to the beginning of the container
166-
[[nodiscard]] ConstIterator cbegin() const noexcept;
166+
IOX_NO_DISCARD ConstIterator cbegin() const noexcept;
167167

168168
/// @brief Get an iterator pointing to the end of the container
169169
/// @return iterator pointing to the end of the container
170-
[[nodiscard]] Iterator end() noexcept;
170+
IOX_NO_DISCARD Iterator end() noexcept;
171171

172172
/// @brief Get a const iterator pointing to the end of the container
173173
/// @return const iterator pointing to the end of the container
174-
[[nodiscard]] ConstIterator end() const noexcept;
174+
IOX_NO_DISCARD ConstIterator end() const noexcept;
175175

176176
/// @brief Get a const iterator pointing to the end of the container
177177
/// @return const iterator pointing to the end of the container
178-
[[nodiscard]] ConstIterator cend() const noexcept;
178+
IOX_NO_DISCARD ConstIterator cend() const noexcept;
179179

180180
private:
181181
enum class SlotStatus : uint8_t
@@ -237,7 +237,7 @@ class FixedPositionContainer final
237237
/// @attention aborts if the iterator
238238
/// - is an 'end' iterator
239239
/// - the slot the iterator point to is not in use
240-
[[nodiscard]] Value& operator*() const
240+
IOX_NO_DISCARD Value& operator*() const
241241
{
242242
IOX_ENFORCE(m_index <= Index::LAST, "Access with invalid index!");
243243
IOX_ENFORCE(m_container.get().m_status[m_index] == SlotStatus::USED, "Invalid access! Slot not in use!");
@@ -249,7 +249,7 @@ class FixedPositionContainer final
249249
/// @attention aborts if the iterator
250250
/// - is an 'end' iterator
251251
/// - the slot the iterator point to is not in use
252-
[[nodiscard]] Value* operator->() const
252+
IOX_NO_DISCARD Value* operator->() const
253253
{
254254
IOX_ENFORCE(m_index <= Index::LAST, "Access with invalid index!");
255255
IOX_ENFORCE(m_container.get().m_status[m_index] == SlotStatus::USED, "Invalid access! Slot not in use!");
@@ -261,7 +261,7 @@ class FixedPositionContainer final
261261
/// @attention aborts if the iterator
262262
/// - is an 'end' iterator
263263
/// - the slot the iterator point to is not in use
264-
[[nodiscard]] Value* to_ptr() const
264+
IOX_NO_DISCARD Value* to_ptr() const
265265
{
266266
IOX_ENFORCE(m_index <= Index::LAST, "Access with invalid index!");
267267
IOX_ENFORCE(m_container.get().m_status[m_index] == SlotStatus::USED, "Invalid access! Slot not in use!");
@@ -271,31 +271,31 @@ class FixedPositionContainer final
271271
/// @brief Get the index of the element the iterator points to
272272
/// @return index of the element the iterator points to
273273
/// @attention this can point out of the container in case of the 'end' iterator
274-
[[nodiscard]] IndexType to_index() const
274+
IOX_NO_DISCARD IndexType to_index() const
275275
{
276276
return m_index;
277277
}
278278

279279
/// @brief Check if the iterator origins from the provided container
280280
/// @param[in] container to determine the origin of the iterator
281281
/// @return 'true' if the iterator origins from the provide container, 'false' otherwise
282-
[[nodiscard]] bool origins_from(const Container& container) const
282+
IOX_NO_DISCARD bool origins_from(const Container& container) const
283283
{
284284
return &m_container.get() == &container;
285285
}
286286

287287
/// @brief Compares iterators for equality
288288
/// @return 'true' if iterators are the same, 'false' otherwise
289289
template <IterMutability RHS_TYPE>
290-
[[nodiscard]] bool operator==(const IteratorBase<RHS_TYPE>& rhs) const
290+
IOX_NO_DISCARD bool operator==(const IteratorBase<RHS_TYPE>& rhs) const
291291
{
292292
return origins_from(rhs.m_container.get()) && (m_index == rhs.m_index);
293293
}
294294

295295
/// @brief Compares iterators for non-equality
296296
/// @return 'true' if iterators are not the same, 'false' otherwise
297297
template <IterMutability RHS_TYPE>
298-
[[nodiscard]] bool operator!=(const IteratorBase<RHS_TYPE>& rhs) const
298+
IOX_NO_DISCARD bool operator!=(const IteratorBase<RHS_TYPE>& rhs) const
299299
{
300300
return !(*this == rhs);
301301
}

iceoryx_hoofs/container/include/iox/uninitialized_array.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "iox/iceoryx_hoofs_types.hpp"
2222

23-
#include <cstddef>
2423
#include <cstdint>
2524

2625
namespace iox
@@ -38,7 +37,7 @@ struct ZeroedBuffer
3837
// AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation
3938
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
4039
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
41-
std::byte data[sizeof(ElementType)];
40+
byte data[sizeof(ElementType)];
4241
};
4342
// AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation
4443
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
@@ -58,7 +57,7 @@ struct NonZeroedBuffer
5857
// AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation
5958
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
6059
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
61-
std::byte data[sizeof(ElementType)];
60+
byte data[sizeof(ElementType)];
6261
};
6362
// AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation
6463
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used

0 commit comments

Comments
 (0)