17 #ifndef IOX_UTILS_CXX_LIST_HPP
18 #define IOX_UTILS_CXX_LIST_HPP
23 #include "iceoryx_utils/platform/platform_correction.hpp"
54 template <
typename T, u
int64_t Capacity>
64 using iterator = IteratorBase<false>;
65 using const_iterator = IteratorBase<true>;
67 using size_type = decltype(Capacity);
101 iterator
begin() noexcept;
105 const_iterator
begin() const noexcept;
109 const_iterator
cbegin() const noexcept;
114 iterator
end() noexcept;
119 const_iterator
end() const noexcept;
124 const_iterator
cend() const noexcept;
128 bool empty() const noexcept;
132 bool full() const noexcept;
138 size_type
size() const noexcept;
142 size_type
capacity() const noexcept;
146 size_type
max_size() const noexcept;
156 const T&
front() const noexcept;
166 const T&
back() const noexcept;
200 void clear() noexcept;
208 iterator
erase(const_iterator iter) noexcept;
214 size_type
remove(const T& data) noexcept;
220 template <typename UnaryPredicate>
221 size_type
remove_if(UnaryPredicate pred) noexcept;
226 template <typename... ConstructorArgs>
232 template <typename... ConstructorArgs>
239 template <typename... ConstructorArgs>
240 iterator
emplace(const_iterator iter, ConstructorArgs&&... args) noexcept;
246 iterator
insert(const_iterator citer, const T& data) noexcept;
252 iterator
insert(const_iterator citer, T&& data) noexcept;
257 template <
bool IsConstIterator = true>
262 using iterator_category = std::bidirectional_iterator_tag;
263 using value_type =
typename std::conditional<IsConstIterator, const T, T>::type;
264 using difference_type = void;
265 using pointer =
typename std::conditional<IsConstIterator, const T*, T*>::type;
266 using reference =
typename std::conditional<IsConstIterator, const T&, T&>::type;
271 IteratorBase(
const IteratorBase<false>& iter) noexcept;
277 IteratorBase&
operator=(
const IteratorBase<false>& rhs) noexcept;
282 IteratorBase& operator++() noexcept;
287 IteratorBase& operator--() noexcept;
296 template <
bool IsConstIteratorOther>
297 bool operator==(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
305 template <
bool IsConstIteratorOther>
306 bool operator!=(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
310 reference operator*()
const noexcept;
314 pointer operator->()
const noexcept;
318 using parentListPointer =
319 typename std::conditional<IsConstIterator, const list<T, Capacity>*,
list<T, Capacity>*>::type;
326 explicit IteratorBase(parentListPointer parent, size_type idx) noexcept;
330 friend class IteratorBase<true>;
331 friend class list<T, Capacity>;
332 parentListPointer m_list;
333 size_type m_iterListNodeIdx;
342 void init() noexcept;
343 T* getDataPtrFromIdx(const size_type idx) noexcept;
344 const T* getDataPtrFromIdx(const size_type idx) const noexcept;
346 bool isValidElementIdx(const size_type idx) const noexcept;
347 bool handleInvalidElement(const size_type idx) const noexcept;
348 bool handleInvalidIterator(const const_iterator& iter) const noexcept;
349 bool isInvalidIterOrDifferentLists(const const_iterator& iter) const noexcept;
350 size_type& getPrevIdx(const size_type idx) noexcept;
351 size_type& getNextIdx(const size_type idx) noexcept;
352 size_type& getPrevIdx(const const_iterator& iter) noexcept;
353 size_type& getNextIdx(const const_iterator& iter) noexcept;
354 const size_type& getPrevIdx(const size_type idx) const noexcept;
355 const size_type& getNextIdx(const size_type idx) const noexcept;
356 const size_type& getPrevIdx(const const_iterator& iter) const noexcept;
357 const size_type& getNextIdx(const const_iterator& iter) const noexcept;
358 void setPrevIdx(const size_type idx, const size_type prevIdx) noexcept;
359 void setNextIdx(const size_type idx, const size_type nextIdx) noexcept;
361 static
void errorMessage(const
char* source, const
char* msg) noexcept;
367 static constexpr size_type BEGIN_END_LINK_INDEX{size_type(Capacity)};
368 static constexpr size_type NODE_LINK_COUNT{size_type(Capacity) + 1U};
369 static constexpr size_type INVALID_INDEX{NODE_LINK_COUNT};
374 size_type m_freeListHeadIdx{0U};
380 NodeLink m_links[NODE_LINK_COUNT];
381 using element_t = uint8_t[
sizeof(T)];
382 alignas(T) element_t m_data[Capacity];
384 size_type m_size{0U};
390 #include "iceoryx_utils/internal/cxx/list.inl"
C++11 compatible bi-directional list implementation.
Definition: list.hpp:56
size_type max_size() const noexcept
list meta information, maximum number of elements the list can contain
Definition: list.inl:196
size_type capacity() const noexcept
list meta information, maximum number of elements the list can contain
Definition: list.inl:190
bool pop_front() noexcept
remove the first element from the begining of the list element destructor will be invoked
Definition: list.inl:400
iterator erase(const_iterator iter) noexcept
remove next element from linked iterator position element destructors will be invoked recursive calls...
Definition: list.inl:255
list() noexcept
constructor for an empty list (of T-types elements)
Definition: list.inl:29
T & emplace_front(ConstructorArgs &&... args) noexcept
construct element inplace at begining of list
Definition: list.inl:204
size_type size() const noexcept
list meta information on filling
Definition: list.inl:184
void clear() noexcept
remove all elements from the list, list will be empty element destructors will be invoked
Definition: list.inl:429
const_iterator cend() const noexcept
default list operation to retrieve an const_iterator to end of list (behind last valid element) Termi...
Definition: list.inl:165
bool push_back(const T &data) noexcept
add element to the end of the list
Definition: list.inl:378
iterator emplace(const_iterator iter, ConstructorArgs &&... args) noexcept
construct element inplace at iterator position
Definition: list.inl:218
iterator end() noexcept
default list operation to retrieve an interator to end of list (behind last valid element) Terminated...
Definition: list.inl:155
iterator insert(const_iterator citer, const T &data) noexcept
insert element before iterator position
Definition: list.inl:416
bool pop_back() noexcept
remove the last element from the end of the list element destructor will be invoked
Definition: list.inl:408
const_iterator cbegin() const noexcept
default list operation to retrieve an const_iterator to first list element
Definition: list.inl:148
T & front() noexcept
Returns a reference to the first element in the container. calling front() on an empty list will term...
Definition: list.inl:323
bool full() const noexcept
list meta information on filling
Definition: list.inl:178
list & operator=(list &&rhs) noexcept
move assignment, list is cleared and initialized, elements are moved from source list any existing el...
T & back() noexcept
Returns a reference to the last element in the container. calling back() on an empty list will termin...
Definition: list.inl:339
list & operator=(const list &rhs) noexcept
copy assignment, each element is copied (added) to the constructed list any existing elements in 'thi...
iterator begin() noexcept
default list operation to retrieve an interator to first list element
Definition: list.inl:138
size_type remove(const T &data) noexcept
remove all elements which matches the given comparing element (compare by value) requires a the templ...
Definition: list.inl:292
T & emplace_back(ConstructorArgs &&... args) noexcept
construct element inplace at end of list
Definition: list.inl:211
bool empty() const noexcept
list meta information on filling
Definition: list.inl:172
bool push_front(const T &data) noexcept
add element to the beginning of the list
Definition: list.inl:355
size_type remove_if(UnaryPredicate pred) noexcept
remove all elements which matches the provided comparison function requires a the template type T to ...
Definition: list.inl:300
~list()
destructs the list and also calls the destructor of all contained elements
Definition: list.inl:131
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28