![]() |
utils-lists 4.0.2
The µOS++ Intrusive Lists
|
A class template for a list of nodes which store the links inside themselves as intrusive nodes. More...
#include <micro-os-plus/utils/lists.h>
Public Types | |
using | difference_type = ptrdiff_t |
Type of pointer difference. | |
using | is_statically_allocated |
Type indicating if the links node is statically allocated. | |
using | iterator = intrusive_list_iterator<T, N, MP, U> |
Type of iterator over the values. | |
using | iterator_pointer = N* |
Type of reference to the iterator internal pointer. | |
using | links_type = L |
Type of the list links node object where the pointers to the list head and tail are stored. | |
using | pointer = value_type* |
Type of pointer to object pointed to by the iterator. | |
using | reference = value_type& |
Type of reference to object pointed to by the iterator. | |
using | value_type = U |
Type of value pointed to by the iterator. | |
Public Member Functions | |
constexpr | intrusive_list () |
Construct an intrusive doubly linked list. | |
intrusive_list (const intrusive_list &)=delete | |
Deleted copy constructor. | |
intrusive_list (intrusive_list &&)=delete | |
Deleted move constructor. | |
constexpr | ~intrusive_list () |
Destruct the list. | |
iterator | begin () const |
Iterator begin. | |
void | clear (void) |
Clear the list. | |
constexpr bool | empty (void) const |
Check if the list is empty. | |
iterator | end () const |
Iterator begin. | |
constexpr pointer | head (void) const |
Get the list head. | |
void | initialize_once (void) |
Initialize the list only at first run. | |
void | link_head (reference node) |
Add a node to the head of the list. | |
void | link_tail (reference node) |
Add a node to the tail of the list. | |
constexpr const links_type * | links_pointer (void) const |
Get the address of the node storing the list links. | |
intrusive_list & | operator= (const intrusive_list &)=delete |
Deleted copy assignment operator. | |
intrusive_list & | operator= (intrusive_list &&)=delete |
Deleted move assignment operator. | |
constexpr pointer | tail (void) const |
Get the list tail. | |
bool | uninitialized (void) const |
Check if the list is uninitialised (only statically allocated lists can be uninitialised). | |
pointer | unlink_head (void) |
Unlink the first element from the list. | |
pointer | unlink_tail (void) |
Unlink the last element from the list. | |
Protected Member Functions | |
pointer | get_pointer (iterator_pointer node) const |
Get the address of the object from the intrusive node pointer. | |
Protected Attributes | |
links_type | links_ |
The list top node used to point to head and tail nodes. | |
A class template for a list of nodes which store the links inside themselves as intrusive nodes.
T | Type of object that includes the intrusive node. |
N | Type of intrusive node with the next & previous links. |
MP | Name of the intrusive node member in object T. |
L | Type of the links node (one of double_list_links or static_double_list_links ). |
U | Type stored in the list, derived from T. |
This class implements an intrusive doubly linked list, where each object stores its own link node as a member. The list maintains a pair of head and tail pointers, allowing efficient insertion, removal, and iteration. The intrusive approach eliminates the need for separate node allocations, as the links are embedded within the objects themselves.
The template parameter MP
specifies the member pointer to the intrusive node within the object, enabling the list to compute the address of the parent object from the node pointer. This design supports both regular and statically allocated lists, depending on the type used for L
.
Iterators provide access to the objects in the list, supporting bidirectional traversal.
For statically allocated lists, set L=static_double_list_links.
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::difference_type = ptrdiff_t |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::is_statically_allocated |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::iterator = intrusive_list_iterator<T, N, MP, U> |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::iterator_pointer = N* |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::links_type = L |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::pointer = value_type* |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::reference = value_type& |
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::value_type = U |
|
constexpr |
Construct an intrusive doubly linked list.
The default constructor for intrusive_list
creates an empty intrusive list. No initialisation of internal pointers is performed here; for statically allocated lists, the pointers are expected to be zero-initialised by the runtime, while for dynamically allocated lists, initialisation is handled by the base class or explicit methods.
Definition at line 961 of file lists-inlines.h.
|
delete |
Deleted copy constructor.
Copying of intrusive_list
instances is explicitly disallowed to prevent accidental duplication, which could compromise the integrity of the list structure.
|
delete |
Deleted move constructor.
Moving of intrusive_list
instances is explicitly disallowed to avoid invalid or inconsistent links within the list that could result from moving lists.
|
constexpr |
Destruct the list.
The destructor for intrusive_list
does not perform any cleanup or pointer manipulation. List management and node unlinking are handled elsewhere, so the destructor is intentionally left empty to avoid unnecessary writes or side effects during object destruction.
Definition at line 973 of file lists-inlines.h.
|
inline |
Iterator begin.
Returns an iterator to the first element in the intrusive list. The iterator points to the node after the internal links node (the head). For statically allocated lists, the initialisation check is handled by the links class. If the list is empty, the iterator will compare equal to end()
.
Definition at line 1076 of file lists-inlines.h.
|
inherited |
Clear the list.
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.
Definition at line 816 of file lists-inlines.h.
|
constexpr |
Check if the list is empty.
true | The list has no nodes. |
false | The list has at least one node. |
Checks whether the intrusive list contains any nodes. This method delegates to the underlying double list implementation to determine if the list is empty. The list is considered empty if there are no elements linked.
Definition at line 1004 of file lists-inlines.h.
|
inline |
Iterator begin.
Returns an iterator to the position after the last element in the intrusive 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.
Definition at line 1094 of file lists-inlines.h.
|
inlineprotected |
Get the address of the object from the intrusive node pointer.
node | Pointer to the intrusive node. |
Computes and returns a pointer to the parent object that contains the intrusive node referenced by the given node pointer. This is achieved by calculating the offset of the intrusive node member within the parent object type and subtracting it from the node's address. This allows retrieval of the full object from just the node pointer, enabling intrusive list traversal and manipulation.
Definition at line 1119 of file lists-inlines.h.
|
constexprinherited |
Get the list head.
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.
Definition at line 826 of file lists-inlines.h.
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::initialize_once | ( | void | ) |
Initialize the list only at first run.
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.
Definition at line 990 of file lists-inlines.h.
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_head | ( | reference | node | ) |
Add a node to the head of the list.
[in] | node | Reference to a list node. |
Adds a new node to the beginning (head) of the intrusive list. The offset of the intrusive node member within the containing object is computed, and the node is linked before the current head node. This operation does not check for duplicate nodes or whether the node is already linked elsewhere. For statically allocated lists, the initialisation check is handled by the links class.
Definition at line 1046 of file lists-inlines.h.
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_tail | ( | reference | node | ) |
Add a node to the tail of the list.
[in] | node | Reference to a list node. |
Adds a new node to the end (tail) of the intrusive list. The offset of the intrusive node member within the containing object is computed, and the node is linked after the current tail node. This operation does not check for duplicate nodes or whether the node is already linked elsewhere. For statically allocated lists, the initialisation check is handled by the links class.
Definition at line 1020 of file lists-inlines.h.
|
inlineconstexprinherited |
|
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.
|
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.
|
constexprinherited |
Get the list tail.
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.
Definition at line 836 of file lists-inlines.h.
|
inherited |
Check if the list is uninitialised (only statically allocated lists can be uninitialised).
true | The list was not initialised. |
false | The list was initialised. |
An uninitialized node is a node with any of the pointers set to nullptr
. Only statically allocated nodes in the initial state are considered uninitialized. For dynamically allocated lists, this method always returns false
since their nodes are explicitly initialized during construction.
Definition at line 783 of file lists-inlines.h.
intrusive_list< T, N, MP, L, U >::pointer micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_head | ( | void | ) |
Unlink the first element from the list.
Removes and unlinks the first element from the intrusive list. If the list is empty, this operation is a no-op and returns a pointer to the internal links node. The method unlinks the node at the head of the list and returns a pointer to the parent object containing the unlinked node.
Definition at line 1145 of file lists-inlines.h.
intrusive_list< T, N, MP, L, U >::pointer micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_tail | ( | void | ) |
Unlink the last element from the list.
Removes and unlinks the last element from the intrusive list. If the list is empty, this operation is a no-op and returns a pointer to the internal links node. The method unlinks the node at the tail of the list and returns a pointer to the parent object containing the unlinked node.
Definition at line 1167 of file lists-inlines.h.
|
protectedinherited |
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.