doubly_list Class Template
A class template for a doubly linked list of nodes. More...
Declaration
class micro_os_plus::utils::doubly_list<T, L> { ... }
Included Headers
Public Member Typedefs Index
template < ... > | |
| using | is_statically_allocated = typename links_type::is_statically_allocated |
|
Type indicating if the links node is statically allocated. More... | |
template < ... > | |
| using | iterator = doubly_list_iterator< value_type > |
|
Type of iterator over the values. More... | |
template < ... > | |
| using | iterator_pointer = value_type * |
|
Type of reference to the iterator internal pointer. More... | |
template < ... > | |
| using | links_type = L |
|
Type of the links node object where the pointers to the list head and tail are stored. More... | |
template < ... > | |
| using | pointer = value_type * |
|
Type of pointer to object pointed to by the iterator. More... | |
template < ... > | |
| using | reference = value_type & |
|
Type of reference to object pointed to by the iterator. More... | |
template < ... > | |
| using | reverse_iterator = std::reverse_iterator< iterator > |
|
Type of reverse iterator over the values. More... | |
template < ... > | |
| using | value_type = T |
|
Type of value pointed to by the iterator. More... | |
Public Constructors Index
template < ... > | |
| doubly_list () noexcept | |
|
Construct a doubly linked list. More... | |
template < ... > | |
| doubly_list (const doubly_list &)=delete | |
|
Deleted copy constructor. More... | |
template < ... > | |
| doubly_list (doubly_list &&)=delete | |
|
Deleted move constructor. More... | |
Public Destructor Index
template < ... > | |
| constexpr | ~doubly_list () |
|
Destruct the list. More... | |
Public Operators Index
template < ... > | |
| doubly_list & | operator= (const doubly_list &)=delete |
|
Deleted copy assignment operator. More... | |
template < ... > | |
| doubly_list & | operator= (doubly_list &&)=delete |
|
Deleted move assignment operator. More... | |
Public Member Functions Index
template < ... > | |
| iterator | begin () const noexcept |
|
Iterator begin. More... | |
template < ... > | |
| void | clear (void) noexcept |
|
Clear the list. More... | |
template < ... > | |
| constexpr bool | empty (void) const noexcept |
|
Check if the list is empty. More... | |
template < ... > | |
| iterator | end () const noexcept |
|
Iterator end. More... | |
template < ... > | |
| constexpr pointer | head (void) const noexcept |
|
Get the list head. More... | |
template < ... > | |
| bool | initialise_once (void) noexcept |
|
Initialise the list only at first run. More... | |
template < ... > | |
| bool | initialised (void) const noexcept |
|
Check if the list is initialised (only statically allocated lists can be uninitialised). More... | |
template < ... > | |
| void | link_head (reference node) noexcept |
|
Add a node to the head of the list. More... | |
template < ... > | |
| void | link_tail (reference node) noexcept |
|
Add a node to the tail of the list. More... | |
template < ... > | |
| constexpr const links_type * | links_pointer (void) const noexcept |
|
Get the address of the node storing the list links. More... | |
template < ... > | |
| reverse_iterator | rbegin () const noexcept |
|
Reverse iterator begin. More... | |
template < ... > | |
| reverse_iterator | rend () const noexcept |
|
Reverse iterator end. More... | |
template < ... > | |
| constexpr pointer | tail (void) const noexcept |
|
Get the list tail. More... | |
Protected Member Attributes Index
template < ... > | |
| links_type | links_ |
|
The list top node used to point to head and tail nodes. More... | |
Description
A class template for a doubly linked list of nodes.
- Template Parameters
-
T Type of the elements linked into the list, derived from class doubly_list_links_base.
L Type of the links node (either doubly_list_links or static_doubly_list_links).
This class implements a generic doubly linked list, maintaining a pair of head and tail pointers to allow efficient iteration and manipulation of nodes. The list elements (of type T) must be derived from doubly_list_links_base (typically from doubly_list_links) and extended with the required payload, which may be the actual content or a pointer to it.
The class uses composition for the links node, rather than inheritance, to avoid inheriting unwanted methods. Iterators return pointers to the list elements, enabling traversal of the list in a manner similar to standard containers.
Definition at line 250 of file doubly-list.h.
Public Member Typedefs
is_statically_allocated
|
Type indicating if the links node is statically allocated.
Definition at line 292 of file doubly-list.h.
iterator
|
Type of iterator over the values.
Definition at line 277 of file doubly-list.h.
iterator_pointer
|
Type of reference to the iterator internal pointer.
Definition at line 287 of file doubly-list.h.
links_type
|
Type of the links node object where the pointers to the list head and tail are stored.
Definition at line 257 of file doubly-list.h.
pointer
|
Type of pointer to object pointed to by the iterator.
Definition at line 267 of file doubly-list.h.
reference
|
Type of reference to object pointed to by the iterator.
Definition at line 272 of file doubly-list.h.
reverse_iterator
|
Type of reverse iterator over the values.
Definition at line 282 of file doubly-list.h.
value_type
|
Type of value pointed to by the iterator.
Definition at line 262 of file doubly-list.h.
Public Constructors
doubly_list()
| noexcept |
Construct a doubly linked list.
For non-statically allocated lists, the initial list status is empty after construction, meaning the list is ready for use and contains no nodes.
For statically allocated lists, the list remains uninitialised after construction, with its internal pointers set to nullptr. Such lists require explicit initialisation (typically via initialise_once()) before use.
This constructor does not clear or modify the internal pointers for statically allocated lists, relying on zero-initialisation by the runtime. For dynamically allocated lists, it calls clear() to ensure the list is in a valid empty state.
- The rule of five
The copy constructor, move constructor, copy assignment operator, and move assignment operator are explicitly deleted to prevent accidental copying or moving of doubly_list objects. This ensures the integrity of the list structure, as duplicating or moving lists could result in invalid or inconsistent links within the list.
Declaration at line 298 of file doubly-list.h, definition at line 270 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::clear.
Referenced by micro_os_plus::utils::doubly_list< T, L >::doubly_list, micro_os_plus::utils::doubly_list< T, L >::doubly_list, micro_os_plus::utils::doubly_list< T, L >::operator= and micro_os_plus::utils::doubly_list< T, L >::operator=.
doubly_list()
| delete |
Deleted copy constructor.
Copying of doubly_list instances is explicitly disallowed to prevent accidental duplication, which could compromise the integrity of the list structure.
Definition at line 308 of file doubly-list.h.
Reference micro_os_plus::utils::doubly_list< T, L >::doubly_list.
doubly_list()
| delete |
Deleted move constructor.
Moving of doubly_list instances is explicitly disallowed to avoid invalid or inconsistent links within the list that could result from moving lists.
Definition at line 318 of file doubly-list.h.
Reference micro_os_plus::utils::doubly_list< T, L >::doubly_list.
Public Destructor
~doubly_list()
| constexpr |
Destruct the list.
Normally at this point there must be no nodes in the list. However, for statically allocated lists, this might not be always true due to their lifetime and initialization patterns.
In debug mode, the destructor emits a warning if the list is not empty when destroyed, helping to catch potential resource leaks or logic errors in list management.
Declaration at line 346 of file doubly-list.h, definition at line 300 of file doubly-list-inlines.h.
Public Operators
operator=()
| delete |
Deleted copy assignment operator.
Copy assignment is explicitly disallowed to prevent accidental overwriting of list objects, which could lead to corruption of the list structure.
Definition at line 329 of file doubly-list.h.
Reference micro_os_plus::utils::doubly_list< T, L >::doubly_list.
operator=()
| delete |
Deleted move assignment operator.
Move assignment is explicitly disallowed to avoid invalid or inconsistent links within the list that could result from moving lists.
Definition at line 340 of file doubly-list.h.
References micro_os_plus::utils::doubly_list< T, L >::doubly_list, micro_os_plus::utils::doubly_list< T, L >::begin, micro_os_plus::utils::doubly_list< T, L >::clear, micro_os_plus::utils::doubly_list< T, L >::empty, micro_os_plus::utils::doubly_list< T, L >::end, micro_os_plus::utils::doubly_list< T, L >::head, micro_os_plus::utils::doubly_list< T, L >::initialise_once, micro_os_plus::utils::doubly_list< T, L >::initialised, micro_os_plus::utils::doubly_list< T, L >::link_head, micro_os_plus::utils::doubly_list< T, L >::link_tail, micro_os_plus::utils::doubly_list< T, L >::links_pointer, micro_os_plus::utils::doubly_list< T, L >::rbegin, micro_os_plus::utils::doubly_list< T, L >::rend and micro_os_plus::utils::doubly_list< T, L >::tail.
Public Member Functions
begin()
| nodiscard noexcept |
Iterator begin.
- Returns
An iterator to the first element.
Returns an iterator to the first element in the list. For statically allocated lists, asserts that the list is already initialised. The iterator will point to the node after the internal links node (the head). If the list is empty, the iterator will compare equal to end().
Declaration at line 442 of file doubly-list.h, definition at line 495 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator= and micro_os_plus::utils::doubly_list< T, L >::rend.
clear()
| noexcept |
Clear the list.
- Parameters
None.
- Returns
Nothing.
The clear() method initialises the mandatory internal links node so that both its previous_ and next_ pointers refer to itself. This marks the list as empty and ensures it is in a safe, known state, ready for new insertions. This operation is typically used to reset the list, removing all elements and breaking any existing links.
Declaration at line 392 of file doubly-list.h, definition at line 394 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::doubly_list and micro_os_plus::utils::doubly_list< T, L >::operator=.
empty()
| nodiscard constexpr noexcept |
Check if the list is empty.
- Parameters
None.
- Return Values
-
true The list has no nodes.
false The list has at least one node.
Checks whether the list contains any nodes. The list is considered empty if the internal links node is not linked to any other nodes. This method provides a fast way to determine if the list has elements or is currently empty.
Declaration at line 381 of file doubly-list.h, definition at line 378 of file doubly-list-inlines.h.
Referenced by micro_os_plus::utils::doubly_list< T, L >::~doubly_list, micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::empty and micro_os_plus::utils::doubly_list< T, L >::operator=.
end()
| nodiscard noexcept |
Iterator end.
- Returns
An iterator positioned after the last element.
Returns an iterator to the position after the last element in the list (the end iterator). This iterator points to the internal links node, which acts as a sentinel. It is used as the past-the-end marker in iteration and comparison operations. The end iterator does not reference any valid list element.
Declaration at line 450 of file doubly-list.h, definition at line 519 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator= and micro_os_plus::utils::doubly_list< T, L >::rbegin.
head()
| nodiscard constexpr noexcept |
Get the list head.
- Parameters
None.
- Returns
Pointer to the head node.
Returns a pointer to the first node in the list. If the list is empty, this will point to the internal links node itself, which can be used to detect the end of the list during iteration. The returned pointer should be checked against end() or the sentinel node to determine if the list contains any elements.
Declaration at line 402 of file doubly-list.h, definition at line 413 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::link_head, micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_head and micro_os_plus::utils::doubly_list< T, L >::operator=.
initialise_once()
| noexcept |
Initialise the list only at first run.
- Parameters
None.
- Returns
true if the list was initialised, false otherwise.
If the statically allocated list is still in the initial uninitialised state (with both pointers null), this method initialises the list to the empty state, with both pointers pointing to itself. For non-statically initialised lists, this method has no effect.
Must be manually called for statically allocated lists before inserting elements or performing any other operations.
Declaration at line 370 of file doubly-list.h, definition at line 353 of file doubly-list-inlines.h.
Referenced by micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::initialise_once and micro_os_plus::utils::doubly_list< T, L >::operator=.
initialised()
| nodiscard noexcept |
Check if the list is initialised (only statically allocated lists can be uninitialised).
- Parameters
None.
- Return Values
-
true The list was initialised.
false The list was not initialised.
An uninitialised node is a node with any of the pointers set to nullptr. Only statically allocated nodes in the initial state are considered uninitialised. For dynamically allocated lists, this method always returns true since their nodes are explicitly initialised during construction.
Declaration at line 359 of file doubly-list.h, definition at line 327 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator=.
link_head()
| noexcept |
Add a node to the head of the list.
- Parameters
-
[in] node Reference to the node to add.
- Returns
Nothing.
Adds a new node to the beginning (head) of the list. For statically allocated lists, asserts that the list is already initialised. The new node is linked before the current head node, updating the list structure accordingly. This operation does not check for duplicate nodes or whether the node is already linked elsewhere.
Declaration at line 432 of file doubly-list.h, definition at line 469 of file doubly-list-inlines.h.
References micro_os_plus::utils::doubly_list< T, L >::head and micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator=.
link_tail()
| noexcept |
Add a node to the tail of the list.
- Parameters
-
[in] node Reference to the node to add.
- Returns
Nothing.
Adds a new node to the end (tail) of the list. For statically allocated lists, asserts that the list is already initialised. The new node is linked after the current tail node, updating the list structure accordingly. This operation does not check for duplicate nodes or whether the node is already linked elsewhere.
Declaration at line 422 of file doubly-list.h, definition at line 443 of file doubly-list-inlines.h.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator=.
links_pointer()
| nodiscard constexpr noexcept |
Get the address of the node storing the list links.
- Parameters
None.
- Returns
A pointer to the internal links node.
Returns the address of the links_ member. This method is required by derived classes (such as intrusive_list) when constructing their end() iterator, where a direct reference to the protected member is not accessible.
Returns the address of the links_ member directly. This method is required by derived classes (such as intrusive_list) when constructing their end() iterator, where a direct reference to the protected member is not accessible from the derived scope.
Declaration at line 484 of file doubly-list.h, definition at line 567 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::end and micro_os_plus::utils::doubly_list< T, L >::operator=.
rbegin()
| nodiscard noexcept |
Reverse iterator begin.
- Returns
A reverse iterator positioned at the last element.
Returns a reverse iterator to the last element in the list. Equivalent to reverse_iterator{ end() }. Traversal proceeds from the tail towards the head.
Declaration at line 458 of file doubly-list.h, definition at line 540 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::end.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator=.
rend()
| nodiscard noexcept |
Reverse iterator end.
- Returns
A reverse iterator positioned before the first element.
Returns a reverse iterator to the position before the first element in the list. Equivalent to reverse_iterator{ begin() }. Used as the past-the-end marker for reverse-direction iteration.
Declaration at line 466 of file doubly-list.h, definition at line 553 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::begin.
Referenced by micro_os_plus::utils::doubly_list< T, L >::operator=.
tail()
| nodiscard constexpr noexcept |
Get the list tail.
- Parameters
None.
- Returns
Pointer to the tail node.
Returns a pointer to the last node in the list. If the list is empty, this will point to the internal links node itself, which can be used to detect the end of the list during reverse iteration. The returned pointer should be checked against the sentinel node to determine if the list contains any elements.
Declaration at line 412 of file doubly-list.h, definition at line 428 of file doubly-list-inlines.h.
Reference micro_os_plus::utils::doubly_list< T, L >::links_.
Referenced by micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_tail and micro_os_plus::utils::doubly_list< T, L >::operator=.
Protected Member Attributes
links_
| protected |
The list top node used to point to head and tail nodes.
This member stores the internal links node for the list. The next pointer of this node points to the head of the list, and the previous pointer points to the tail. For an empty list, both pointers refer to the node itself, simplifying list management and boundary checks.
Definition at line 499 of file doubly-list.h.
Referenced by micro_os_plus::utils::doubly_list< T, L >::begin, micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::begin, micro_os_plus::utils::doubly_list< T, L >::clear, micro_os_plus::utils::doubly_list< T, L >::end, micro_os_plus::utils::doubly_list< T, L >::head, micro_os_plus::utils::doubly_list< T, L >::initialised, micro_os_plus::utils::doubly_list< T, L >::link_head, micro_os_plus::utils::doubly_list< T, L >::links_pointer, micro_os_plus::utils::doubly_list< T, L >::tail, micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_head and micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_tail.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.