A class for the core of a doubly linked list (pointers to neighbours).
The double_list_links
class provides the fundamental structure for a doubly linked list node, inheriting the pair of pointers to the next and previous elements and the associated access methods from double_list_links_base
. The constructor initialises the pointers to form an empty list, where both pointers refer to the node itself.
This class is intended for use as the core linking mechanism within doubly linked lists, supporting efficient insertion and removal operations.
Definition at line 295 of file lists.h.
micro_os_plus::utils::double_list_links::double_list_links |
( |
| ) |
|
|
constexpr |
Construct a list node (initialise the pointers).
The constructor for double_list_links
is used for regular (non-static) list link nodes. It explicitly initialises the node by calling initialize()
, which sets both the previous_
and next_
pointers to point to this node itself, marking it as unlinked and ready for use in a list. This ensures that dynamically allocated or automatic list nodes always start in a known, safe state, regardless of their memory contents prior to construction.
- Note
- For statically allocated nodes, the constructor is intentionally left empty to allow BSS zero-initialisation. For dynamically allocated nodes, explicit initialisation is required to avoid undefined pointer values.
- 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 intrusive_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.
Definition at line 254 of file lists-inlines.h.
void micro_os_plus::utils::double_list_links_base::initialize |
( |
void | | ) |
|
|
constexprinherited |
Initialise the node links.
- Parameters
- None.
- Returns
- Nothing.
Sets both the previous_
and next_
pointers to point to this node itself, marking the node as unlinked. This state is used to indicate that the node is not currently part of any list.
This method is called during initialisation and after a node is unlinked from a list, ensuring the node is in a safe, standalone state and cannot be traversed as part of a list.
- Note
- After unlinking a node from a list, it must be returned to this state to prevent accidental access through stale links.
Definition at line 113 of file lists-inlines.h.
void micro_os_plus::utils::double_list_links_base::initialize_once |
( |
void | | ) |
|
|
inherited |
Initialise the node links only if not already initialised.
- Parameters
- None.
- Returns
- Nothing.
If the statically allocated list is still in the initial uninitialised state (with both pointers nullptr
), this method initialises the list to the empty state, with both pointers pointing to itself.
For non-statically initialised lists, this method is ineffective, since the node is always initialised at construct time.
- Note
- This method must be manually called for a statically allocated list before inserting elements or performing any other operations.
Definition at line 83 of file lists.cpp.
Link the new node as next.
- Parameters
-
[in] | node | Pointer to the node to be linked as next. |
- Returns
- Nothing.
Insert the new node between the next pointer and the node pointed by it. This operation is used by lists to link new nodes to the list head. The new node's previous_
pointer is set to the current node, and its next_
pointer is set to the current node's next_
. The neighbouring nodes are updated to point to the new node, maintaining the integrity of the double-linked list.
Definition at line 101 of file lists.cpp.
Link the new node as previous.
- Parameters
-
[in] | node | Pointer to the node to be linked as previous. |
- Returns
- Nothing.
Insert the new node between the previous pointer and the node pointed by it. Used by lists to link new nodes to the list tail. The new node's next_
pointer is set to the current node, and its previous_
pointer is set to the current node's previous_
. The neighbouring nodes are updated to point to the new node, maintaining the integrity of the double-linked list.
Definition at line 127 of file lists.cpp.
bool micro_os_plus::utils::double_list_links_base::linked |
( |
void | | ) |
const |
|
inherited |
Check if the node is linked to a doubly linked list.
- Parameters
- None.
- Return values
-
true | The node is linked with both pointers. |
false | The node is not linked. |
To be linked, both pointers must point to different nodes than itself (double list requirement). If either next_
or previous_
points to this
, the node is considered unlinked (empty state). This method checks the node's linkage status for safe list operations.
Definition at line 176 of file lists.cpp.
bool micro_os_plus::utils::double_list_links_base::uninitialized |
( |
void | | ) |
const |
|
inherited |
Check if the node is uninitialised.
- Parameters
- None.
- Return values
-
true | The links are not initialised. |
false | The links are initialised. |
An uninitialized node is a node with its pointers set to nullptr
. Only statically allocated nodes in their initial state are considered uninitialized. Regular (dynamically or automatically allocated) nodes are always initialized during construction, so this method will only return true
for statically allocated nodes that have not yet been initialized.
Definition at line 58 of file lists.cpp.
void micro_os_plus::utils::double_list_links_base::unlink |
( |
void | | ) |
|
|
inherited |
Remove this node from the list.
- Parameters
- None.
- Returns
- Nothing.
Update both neighbours to point to each other, effectively removing the node from the list. The node is then returned to the initial state (empty), with both pointers pointing to itself. This operation is safe to call even if the node is already unlinked.
Definition at line 151 of file lists.cpp.