18 #ifndef IOX_HOOFS_CXX_LIST_HPP
19 #define IOX_HOOFS_CXX_LIST_HPP
21 #include "iceoryx_hoofs/cxx/helplets.hpp"
26 #include "iceoryx_hoofs/platform/platform_correction.hpp"
57 template <
typename T, u
int64_t Capacity>
67 using iterator = IteratorBase<false>;
68 using const_iterator = IteratorBase<true>;
70 using size_type = decltype(Capacity);
108 const_iterator
begin() const noexcept;
122 const_iterator
end() const noexcept;
127 const_iterator
cend() const noexcept;
141 size_type
size() const noexcept;
169 const T&
back() const noexcept;
211 iterator
erase(const_iterator iter) noexcept;
217 size_type
remove(const T& data) noexcept;
223 template <typename UnaryPredicate>
229 template <typename... ConstructorArgs>
235 template <typename... ConstructorArgs>
242 template <typename... ConstructorArgs>
243 iterator
emplace(const_iterator iter, ConstructorArgs&&... args) noexcept;
249 iterator
insert(const_iterator citer, const T& data) noexcept;
255 iterator
insert(const_iterator citer, T&& data) noexcept;
260 template <
bool IsConstIterator = true>
265 using iterator_category = std::bidirectional_iterator_tag;
266 using value_type =
typename std::conditional<IsConstIterator, const T, T>::type;
267 using difference_type = void;
268 using pointer =
typename std::conditional<IsConstIterator, const T*, T*>::type;
269 using reference =
typename std::conditional<IsConstIterator, const T&, T&>::type;
274 IteratorBase(
const IteratorBase<false>& iter) noexcept;
280 IteratorBase&
operator=(
const IteratorBase<false>& rhs) noexcept;
285 IteratorBase& operator++() noexcept;
290 IteratorBase& operator--() noexcept;
299 template <
bool IsConstIteratorOther>
300 bool operator==(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
308 template <
bool IsConstIteratorOther>
309 bool operator!=(
const IteratorBase<IsConstIteratorOther>& rhs)
const noexcept;
313 reference operator*()
const noexcept;
317 pointer operator->()
const noexcept;
321 using parentListPointer =
322 typename std::conditional<IsConstIterator, const list<T, Capacity>*,
list<T, Capacity>*>::type;
329 explicit IteratorBase(parentListPointer parent, size_type idx) noexcept;
333 friend class IteratorBase<true>;
334 friend class list<T, Capacity>;
335 parentListPointer m_list;
336 size_type m_iterListNodeIdx;
345 void init() noexcept;
346 T* getDataPtrFromIdx(const size_type idx) noexcept;
347 const T* getDataPtrFromIdx(const size_type idx) const noexcept;
349 bool isValidElementIdx(const size_type idx) const noexcept;
350 bool isInvalidIterator(const const_iterator& iter) const noexcept;
351 bool isInvalidIterOrDifferentLists(const const_iterator& iter) const noexcept;
352 size_type& getPrevIdx(const size_type idx) noexcept;
353 size_type& getNextIdx(const size_type idx) noexcept;
354 size_type& getPrevIdx(const const_iterator& iter) noexcept;
355 size_type& getNextIdx(const const_iterator& iter) noexcept;
356 const size_type& getPrevIdx(const size_type idx) const noexcept;
357 const size_type& getNextIdx(const size_type idx) const noexcept;
358 const size_type& getPrevIdx(const const_iterator& iter) const noexcept;
359 const size_type& getNextIdx(const const_iterator& iter) const noexcept;
360 void setPrevIdx(const size_type idx, const size_type prevIdx) noexcept;
361 void setNextIdx(const size_type idx, const size_type nextIdx) noexcept;
363 static
void errorMessage(const
char* source, const
char* msg) noexcept;
369 static constexpr size_type BEGIN_END_LINK_INDEX{size_type(Capacity)};
370 static constexpr size_type NODE_LINK_COUNT{size_type(Capacity) + 1U};
371 static constexpr size_type INVALID_INDEX{NODE_LINK_COUNT};
376 size_type m_freeListHeadIdx{0U};
382 NodeLink m_links[NODE_LINK_COUNT];
383 using element_t = uint8_t[
sizeof(T)];
384 alignas(T) element_t m_data[Capacity];
386 size_type m_size{0U};
392 #include "iceoryx_hoofs/internal/cxx/list.inl"
C++11 compatible bi-directional list implementation.
Definition: list.hpp:59
size_type remove(const T &data) noexcept
remove all elements which matches the given comparing element (compare by value) requires a the templ...
iterator erase(const_iterator iter) noexcept
remove next element from linked iterator position element destructors will be invoked recursive calls...
bool pop_front() noexcept
remove the first element from the begining of the list element destructor will be invoked
size_type capacity() const noexcept
list meta information, maximum number of elements the list can contain
list() noexcept
constructor for an empty list (of T-types elements)
void clear() noexcept
remove all elements from the list, list will be empty element destructors will be invoked
size_type remove_if(UnaryPredicate pred) noexcept
remove all elements which matches the provided comparison function requires a the template type T to ...
bool push_back(const T &data) noexcept
add element to the end of the list
iterator begin() noexcept
default list operation to retrieve an interator to first list element
const_iterator cend() const noexcept
default list operation to retrieve an const_iterator to end of list (behind last valid element) Termi...
T & back() noexcept
Returns a reference to the last element in the container. calling back() on an empty list will termin...
T & emplace_back(ConstructorArgs &&... args) noexcept
construct element inplace at end of list
iterator emplace(const_iterator iter, ConstructorArgs &&... args) noexcept
construct element inplace at iterator position
iterator end() noexcept
default list operation to retrieve an interator to end of list (behind last valid element) Terminated...
size_type max_size() const noexcept
list meta information, maximum number of elements the list can contain
bool pop_back() noexcept
remove the last element from the end of the list element destructor will be invoked
size_type size() const noexcept
list meta information on filling
T & front() noexcept
Returns a reference to the first element in the container. calling front() on an empty list will term...
T & emplace_front(ConstructorArgs &&... args) noexcept
construct element inplace at begining of list
bool full() const noexcept
list meta information on filling
list & operator=(const list &rhs) noexcept
copy assignment, each element is copied (added) to the constructed list any existing elements in 'thi...
iterator insert(const_iterator citer, const T &data) noexcept
insert element before iterator position
bool empty() const noexcept
list meta information on filling
bool push_front(const T &data) noexcept
add element to the beginning of the list
const_iterator cbegin() const noexcept
default list operation to retrieve an const_iterator to first list element
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29