utils-lists 4.0.0
µOS++ C++ intrusive lists utilities
Loading...
Searching...
No Matches
micro_os_plus::utils::double_list< T, L > Class Template Reference

A class template for a double linked list of nodes. More...

#include <micro-os-plus/utils/lists.h>

+ Inheritance diagram for micro_os_plus::utils::double_list< T, L >:

Public Types

using is_statically_allocated
 Type indicating that the links node is statically allocated.
 
using iterator = double_list_iterator<value_type>
 Type of iterator over the values.
 
using iterator_pointer = value_type*
 Type of reference to the iterator internal pointer.
 
using links_type = L
 Type of the 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 = T
 Type of value "pointed to" by the iterator.
 

Public Member Functions

 double_list ()
 Construct a double linked list.
 
constexpr ~double_list ()
 Destruct the list.
 
iterator begin () const
 Iterator begin.
 
void clear (void)
 Clear the list.
 
bool empty (void) const
 Check if the list is empty.
 
iterator end () const
 Iterator end.
 
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_typelinks_pointer () const
 Get the address of the node storing the list links.
 
constexpr pointer tail (void) const
 Get the list tail.
 
bool uninitialized (void) const
 Check if the list is uninitialised (only statically allocated can be).
 

Protected Attributes

links_type links_
 The list top node used to point to head and tail nodes.
 

Detailed Description

template<class T, class L = double_list_links>
class micro_os_plus::utils::double_list< T, L >

A class template for a double linked list of nodes.

Template Parameters
TType of the elements linked into the list, derived from class double_list_links_base.
LType of the links node (one of double_list_links or static_double_list_links).

A double linked list is a pair of head/tail pointers, allowing to iterate over the nodes.

Note
Currently only forward iterators are provided, but there is no problem to add reverse iterators, if needed.

The list elements (of type T) should be derived from the double_list_links_base class, (usually from double_list_links) extended with the payload, that may be either the actual content or a pointer to the content.

The iterators return pointers to the list elements, i.e. to the beginning of the objects of type T.

Note
The class does not use inheritance, but composition for the links node, to avoid inheriting unwanted methods from it.

Definition at line 486 of file lists.h.

Member Typedef Documentation

◆ is_statically_allocated

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::is_statically_allocated
Initial value:
typename links_type::is_statically_allocated

Type indicating that the links node is statically allocated.

Definition at line 528 of file lists.h.

◆ iterator

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::iterator = double_list_iterator<value_type>

Type of iterator over the values.

Definition at line 518 of file lists.h.

◆ iterator_pointer

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::iterator_pointer = value_type*

Type of reference to the iterator internal pointer.

Definition at line 523 of file lists.h.

◆ links_type

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::links_type = L

Type of the links node object where the pointers to the list head and tail are stored.

Definition at line 498 of file lists.h.

◆ pointer

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::pointer = value_type*

Type of pointer to object "pointed to" by the iterator.

Definition at line 508 of file lists.h.

◆ reference

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::reference = value_type&

Type of reference to object "pointed to" by the iterator.

Definition at line 513 of file lists.h.

◆ value_type

template<class T , class L = double_list_links>
using micro_os_plus::utils::double_list< T, L >::value_type = T

Type of value "pointed to" by the iterator.

Definition at line 503 of file lists.h.

Constructor & Destructor Documentation

◆ double_list()

template<class T , class L >
micro_os_plus::utils::double_list< T, L >::double_list ( )

Construct a double linked list.

For non-statically allocated lists, the initial list status is empty.

Statically allocated remain uninitialised.

Definition at line 268 of file inlines.h.

◆ ~double_list()

template<class T , class L >
constexpr micro_os_plus::utils::double_list< T, L >::~double_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.

Note
In debug mode, the code warns if the list is not empty when destroyed.

Definition at line 296 of file inlines.h.

Member Function Documentation

◆ begin()

template<class T , class L >
double_list< T, L >::iterator micro_os_plus::utils::double_list< T, L >::begin ( ) const

Iterator begin.

Returns
An iterator positioned at the first element.

Definition at line 421 of file inlines.h.

◆ clear()

template<class T , class L >
void micro_os_plus::utils::double_list< T, L >::clear ( void )

Clear the list.

Parameters
None.
Returns
Nothing.

Initialise the mandatory node with links to itself.

Definition at line 371 of file inlines.h.

◆ empty()

template<class T , class L >
bool micro_os_plus::utils::double_list< T, L >::empty ( void ) const

Check if the list is empty.

Parameters
None.
Return values
trueThe list has no nodes.
falseThe list has at least one node.

Definition at line 359 of file inlines.h.

◆ end()

template<class T , class L >
double_list< T, L >::iterator micro_os_plus::utils::double_list< T, L >::end ( ) const

Iterator end.

Returns
An iterator positioned after the last element.

Definition at line 433 of file inlines.h.

◆ head()

template<class T , class L >
constexpr double_list< T, L >::pointer micro_os_plus::utils::double_list< T, L >::head ( void ) const
constexpr

Get the list head.

Parameters
None.
Returns
Pointer to the head node.

Definition at line 381 of file inlines.h.

◆ initialize_once()

template<class T , class L >
void micro_os_plus::utils::double_list< T, L >::initialize_once ( void )

Initialize the list only at first run.

Parameters
None.
Returns
Nothing.

If the statically allocated list is still in the initial uninitialised state (with both pointers null), initialise the list to the empty state, with both pointers pointing to itself.

For non-statically initialised lists, this method is ineffective.

Note
Must be manually called for statically allocated list before inserting elements, or any other operations.

Definition at line 349 of file inlines.h.

◆ link_head()

template<class T , class L >
void micro_os_plus::utils::double_list< T, L >::link_head ( reference node)

Add a node to the head of the list.

Definition at line 408 of file inlines.h.

◆ link_tail()

template<class T , class L >
void micro_os_plus::utils::double_list< T, L >::link_tail ( reference node)

Add a node to the tail of the list.

Definition at line 395 of file inlines.h.

◆ links_pointer()

template<class T , class L = double_list_links>
constexpr const links_type * micro_os_plus::utils::double_list< T, L >::links_pointer ( ) const
inlineconstexpr

Get the address of the node storing the list links.

Returns
A pointer to the list head object.

Definition at line 654 of file lists.h.

◆ tail()

template<class T , class L >
constexpr double_list< T, L >::pointer micro_os_plus::utils::double_list< T, L >::tail ( void ) const
constexpr

Get the list tail.

Parameters
None.
Returns
Pointer to the tail node.

Definition at line 388 of file inlines.h.

◆ uninitialized()

template<class T , class L >
bool micro_os_plus::utils::double_list< T, L >::uninitialized ( void ) const

Check if the list is uninitialised (only statically allocated can be).

Parameters
None.
Return values
trueThe list was not initialised.
falseThe 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 uninitialized.

Definition at line 322 of file inlines.h.

Member Data Documentation

◆ links_

template<class T , class L = double_list_links>
links_type micro_os_plus::utils::double_list< T, L >::links_
protected

The list top node used to point to head and tail nodes.

The node next pointer points to the list head, and the previous pointer points to the list tail.

To simplify processing, the list always has these pointers set, with an empty list node pointing to itself.

Definition at line 673 of file lists.h.


The documentation for this class was generated from the following files: