OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
qOS::list Class Reference

A list object (Generic double-linked) More...

#include <list.hpp>

Inheritance diagram for qOS::list:
[legend]
Collaboration diagram for qOS::list:
[legend]

Public Member Functions

 list () noexcept
 
bool insert (void *const xNode, const listPosition p=listPosition::AT_BACK) noexcept
 Insert an item into the list.
 
bool remove (void *const xNode) noexcept
 If the node is member of a list, the node will be removed from it.
 
void * remove (const listPosition p, void *const xNode=nullptr) noexcept
 Remove an item from the list.
 
void * getFront (void) const noexcept
 Get a pointer to the front item of the list.
 
void * getBack (void) const noexcept
 Get a pointer to the back item of the list.
 
bool isEmpty (void) const noexcept
 Check if the list is empty.
 
size_t length (void) const noexcept
 Get the number of items inside the list.
 
bool sort (listCompareFcn_t f) noexcept
 Sort the double linked list using the f function to determine the order. The sorting algorithm used by this function compares pairs of adjacent nodes by calling the specified f function with pointers to them as arguments. The sort is performed only modifying node's links without data swapping, improving performance if nodes have a large storage.
 
bool swap (void *node1, void *node2) noexcept
 Swap two nodes that belongs to the list by changing its own links.
 
bool move (list &src, const listPosition p=listPosition::AT_BACK) noexcept
 Moves(or merge) the entire list src to the given list. After the move operation, this function leaves empty the list given by src.
 
void clean (void) noexcept
 Clean up the entire list leaving it empty.
 
listIterator begin (void) noexcept
 Returns an iterator pointing to the first element in the list container.
 
listIterator end (void) noexcept
 Returns an iterator pointing to the last element in the list container.
 
listIterator from (void *offset) noexcept
 Returns an iterator pointing to the element given by offset in the list container.
 

Additional Inherited Members

- Protected Member Functions inherited from qOS::node
listgetContainer (void) noexcept
 Get a pointer to the list in which this node is contained.
 
 node ()
 

Detailed Description

A list object (Generic double-linked)

Constructor & Destructor Documentation

◆ list()

qOS::list::list ( )
noexcept

Member Function Documentation

◆ begin()

listIterator qOS::list::begin ( void )
noexcept

Returns an iterator pointing to the first element in the list container.

Returns
An iterator to the beginning of the sequence container.

◆ clean()

void qOS::list::clean ( void )
noexcept

Clean up the entire list leaving it empty.

◆ end()

listIterator qOS::list::end ( void )
noexcept

Returns an iterator pointing to the last element in the list container.

Returns
An iterator to the latest item of the sequence container.

◆ from()

listIterator qOS::list::from ( void * offset)
noexcept

Returns an iterator pointing to the element given by offset in the list container.

Returns
An iterator to the offset of the sequence container.

◆ getBack()

void * qOS::list::getBack ( void ) const
noexcept

Get a pointer to the back item of the list.

Returns
A pointer to the back node. nullptr if the list is empty

◆ getFront()

void * qOS::list::getFront ( void ) const
noexcept

Get a pointer to the front item of the list.

Returns
A pointer to the front node. nullptr if the list is empty

◆ insert()

bool qOS::list::insert ( void *const xNode,
const listPosition p = listPosition::AT_BACK )
noexcept

Insert an item into the list.

Parameters
[in]xNodeA pointer to the node to be inserted
[in]pThe position where the node will be inserted. Could be listPosition::AT_FRONT, listPosition::AT_BACK or any other index number where the node will be inserted after.
Returns
true if the item was successfully added to the list, otherwise returns false

◆ isEmpty()

bool qOS::list::isEmpty ( void ) const
noexcept

Check if the list is empty.

Returns
true if the list is empty, false if it is not.

◆ length()

size_t qOS::list::length ( void ) const
noexcept

Get the number of items inside the list.

Returns
The number of items of the list.

◆ move()

bool qOS::list::move ( list & src,
const listPosition p = listPosition::AT_BACK )
noexcept

Moves(or merge) the entire list src to the given list. After the move operation, this function leaves empty the list given by src.

Parameters
[in]srcSource list to be moved.
[in]pThe position where src list will be inserted. Could be listPosition::AT_FRONT, listPosition::AT_BACK or any other index number.
Returns
true if the move operation is performed successfully, otherwise returns false

◆ remove() [1/2]

void * qOS::list::remove ( const listPosition p,
void *const xNode = nullptr )
noexcept

Remove an item from the list.

Parameters
[in]pThe position of the node that will be removed. Could be listPosition::AT_FRONT, listPosition::AT_BACK or any other index number.
[in]xNodeA pointer to the node to be deleted (to ignore pass nullptr ).
Returns
A pointer to the removed node. nullptr if removal can not be performed.

◆ remove() [2/2]

bool qOS::list::remove ( void *const xNode)
noexcept

If the node is member of a list, the node will be removed from it.

Parameters
[in]xNodeA pointer to the node.
Returns
true on Success. false if removal can't be performed.

◆ sort()

bool qOS::list::sort ( listCompareFcn_t f)
noexcept

Sort the double linked list using the f function to determine the order. The sorting algorithm used by this function compares pairs of adjacent nodes by calling the specified f function with pointers to them as arguments. The sort is performed only modifying node's links without data swapping, improving performance if nodes have a large storage.

Note
The function modifies the content of the list by reordering its elements as defined by f.
Parameters
[in]fPointer to a function that compares two nodes. This function is called repeatedly by list::sort() to compare two nodes. It shall follow the following prototype:
bool CompareFcn( listCompareHandle_t h )

The function defines the order of the elements by returning a Boolean data, where a true value indicates that element pointed by node1 goes after the element pointed to by node2.

Returns
true if at least one reordering is performed over the list.

◆ swap()

bool qOS::list::swap ( void * node1,
void * node2 )
noexcept

Swap two nodes that belongs to the list by changing its own links.

Note
The list containing nodes will be updated if any node is part of the boundaries.
Parameters
[in]node1Pointer to the first node.
[in]node2Pointer to the second node.
Returns
true if the swap operation is performed. Otherwise returns false.