17 #ifndef IOX_UTILS_CXX_FORWARD_LIST_HPP
18 #define IOX_UTILS_CXX_FORWARD_LIST_HPP
23 #include "iceoryx_utils/platform/platform_correction.hpp"
53 template <
typename T, u
int64_t Capacity>
63 using iterator = IteratorBase<false>;
64 using const_iterator = IteratorBase<true>;
66 using size_type = decltype(Capacity);
115 iterator
begin() noexcept;
119 const_iterator
begin() const noexcept;
123 const_iterator
cbegin() const noexcept;
128 iterator
end() noexcept;
133 const_iterator
end() const noexcept;
138 const_iterator
cend() const noexcept;
142 bool empty() const noexcept;
146 bool full() const noexcept;
152 size_type
size() const noexcept;
156 size_type
capacity() const noexcept;
160 size_type
max_size() const noexcept;
170 const T&
front() const noexcept;
189 void clear() noexcept;
197 iterator
erase_after(const_iterator beforeToBeErasedIter) noexcept;
203 size_type
remove(const T& data) noexcept;
209 template <typename UnaryPredicate>
210 size_type
remove_if(UnaryPredicate pred) noexcept;
215 template <typename... ConstructorArgs>
222 template <typename... ConstructorArgs>
223 iterator
emplace_after(const_iterator afterToBeEmplacedIter, ConstructorArgs&&... args) noexcept;
229 iterator
insert_after(const_iterator citer, const T& data) noexcept;
235 iterator
insert_after(const_iterator citer, T&& data) noexcept;
240 template <
bool IsConstIterator = true>
245 using iterator_category = std::forward_iterator_tag;
246 using value_type =
typename std::conditional<IsConstIterator, const T, T>::type;
247 using difference_type = void;
248 using pointer =
typename std::conditional<IsConstIterator, const T*, T*>::type;
249 using reference =
typename std::conditional<IsConstIterator, const T&, T&>::type;
254 IteratorBase(
const IteratorBase<false>& iter) noexcept;
260 IteratorBase&
operator=(
const IteratorBase<false>& rhs) noexcept;
265 IteratorBase& operator++() noexcept;
273 template <
bool IsConstIteratorOther>
274 bool operator==(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
282 template <
bool IsConstIteratorOther>
283 bool operator!=(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
287 reference operator*()
const noexcept;
291 pointer operator->()
const noexcept;
295 using parentListPointer =
typename std::
303 explicit IteratorBase(parentListPointer parent, size_type idx) noexcept;
307 friend class IteratorBase<true>;
309 parentListPointer m_list;
310 size_type m_iterListNodeIdx;
319 void init() noexcept;
320 T* getDataPtrFromIdx(const size_type idx) noexcept;
321 const T* getDataPtrFromIdx(const size_type idx) const noexcept;
323 bool isValidElementIdx(const size_type idx) const noexcept;
324 bool handleInvalidElement(const size_type idx) const noexcept;
325 bool handleInvalidIterator(const const_iterator& iter) const noexcept;
326 bool isInvalidIterOrDifferentLists(const const_iterator& iter) const noexcept;
327 bool isInvalidElement(const size_type idx) const noexcept;
328 void setInvalidElement(const size_type idx, const
bool value) noexcept;
329 size_type& getNextIdx(const size_type idx) noexcept;
330 const size_type& getNextIdx(const size_type idx) const noexcept;
331 size_type& getNextIdx(const const_iterator& iter) noexcept;
332 const size_type& getNextIdx(const const_iterator& iter) const noexcept;
333 void setNextIdx(const size_type idx, const size_type nextIdx) noexcept;
334 static
void errorMessage(const
char* source, const
char* msg) noexcept;
344 static constexpr size_type BEFORE_BEGIN_INDEX{Capacity};
345 static constexpr size_type END_INDEX{size_type(Capacity) + 1U};
346 static constexpr size_type NODE_LINK_COUNT{size_type(Capacity) + 2U};
350 size_type m_freeListHeadIdx{0U};
352 NodeLink m_links[NODE_LINK_COUNT];
353 using element_t = uint8_t[
sizeof(T)];
354 alignas(T) element_t m_data[Capacity];
356 size_type m_size{0U};
362 #include "iceoryx_utils/internal/cxx/forward_list.inl"
C++11 compatible uni-directional forward list implementation.
Definition: forward_list.hpp:55
const_iterator cend() const noexcept
default list operation to retrieve an const_iterator to end of list (behind last valid element) Termi...
Definition: forward_list.inl:173
T & front() noexcept
Returns a reference to the first element in the container. calling front() on an empty list will term...
Definition: forward_list.inl:324
void clear() noexcept
remove all elements from the list, list will be empty element destructors will be invoked
Definition: forward_list.inl:385
forward_list() noexcept
constructor for an empty list (of T-types elements)
Definition: forward_list.inl:29
bool full() const noexcept
list meta information on filling
Definition: forward_list.inl:186
T & emplace_front(ConstructorArgs &&... args) noexcept
construct element inplace at begining of list
Definition: forward_list.inl:212
size_type max_size() const noexcept
list meta information, maximum number of elements the list can contain
Definition: forward_list.inl:204
size_type remove_if(UnaryPredicate pred) noexcept
remove all elements which matches the provided comparison function requires a the template type T to ...
Definition: forward_list.inl:299
iterator before_begin() noexcept
retrieve an interator before first element only allowed for usage in erase_after, insert_after,...
Definition: forward_list.inl:130
size_type remove(const T &data) noexcept
remove all elements which matches the given comparing element (compare by value) requires a the templ...
Definition: forward_list.inl:291
bool push_front(const T &data) noexcept
add element to the beginning of the list
Definition: forward_list.inl:340
iterator erase_after(const_iterator beforeToBeErasedIter) noexcept
remove next element from linked iterator position element destructors will be invoked recursive calls...
Definition: forward_list.inl:256
size_type capacity() const noexcept
list meta information, maximum number of elements the list can contain
Definition: forward_list.inl:198
forward_list & operator=(const forward_list &rhs) noexcept
copy assignment, each element is copied (added) to the constructed list any existing elements in 'thi...
size_type size() const noexcept
list meta information on filling
Definition: forward_list.inl:192
const_iterator cbegin() const noexcept
default list operation to retrieve an const_iterator to first list element
Definition: forward_list.inl:156
iterator emplace_after(const_iterator afterToBeEmplacedIter, ConstructorArgs &&... args) noexcept
construct element inplace after the pointed-to element
Definition: forward_list.inl:220
bool empty() const noexcept
list meta information on filling
Definition: forward_list.inl:180
~forward_list()
destructs the list and also calls the destructor of all contained elements
Definition: forward_list.inl:123
iterator insert_after(const_iterator citer, const T &data) noexcept
insert element after iterator position
Definition: forward_list.inl:370
forward_list & operator=(forward_list &&rhs) noexcept
move assignment, list is cleared and initialized, elements are moved from source list any existing el...
bool pop_front() noexcept
remove the first element from the begining of the list element destructor will be invoked
Definition: forward_list.inl:362
iterator begin() noexcept
default list operation to retrieve an interator to first list element
Definition: forward_list.inl:146
const_iterator cbefore_begin() const noexcept
const_iterator an interator before first element only allowed for usage in erase_after,...
Definition: forward_list.inl:140
iterator end() noexcept
default list operation to retrieve an interator to end of list (behind last valid element) Terminated...
Definition: forward_list.inl:163
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28