Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::IntrusiveDoubleLinkedList< T > Struct Template Reference

An Intrusive Double Linked List. More...

#include <IntrusiveDoubleLinkedList.h>

Public Member Functions

bool isEmpty () const
 Return true if the linked list is empty.
 
T * dequeueFront ()
 Removes and returns the first element of the linked list.
 
void clear ()
 Clears this linked list removing links between all linked list elements.
 
void appendBack (IntrusiveDoubleLinkedList &other)
 Appends another list at the back of current list.
 
void queueBack (T &item)
 Appends item to the back of this linked list.
 
void remove (T &item)
 Removes item from this linked list.
 

Public Attributes

T * back = nullptr
 
T * front = nullptr
 

Detailed Description

template<typename T>
struct SC::IntrusiveDoubleLinkedList< T >

An Intrusive Double Linked List.

Template Parameters
TThe Type being linked. It must declare two pointers to itself named next and prev.

This is an useful data structure when we want to delegate the allocation strategy to caller.
Both Async and Process use this data structure to store requests.

Note
Include Internal/IntrusiveDoubleLinkedList.inl in the .cpp where any of the methods will be used.
struct Node
{
Node* next = nullptr; // <-- Required by IntrusiveDoubleLinkedList
Node* prev = nullptr; // <-- Required by IntrusiveDoubleLinkedList
int data = 0;
};
Node items[2];
items[0].data = 0;
items[1].data = 1;
SC_TRY(queue.isEmpty());
queue.queueBack(items[0]);
queue.queueBack(items[1]);
SC_TRY(not queue.isEmpty());
Node* first = queue.dequeueFront();
SC_TRY(first->data == 0);
SC_TRY(not queue.isEmpty());
Node* second = queue.dequeueFront();
SC_TRY(second->data == 1);
SC_TRY(queue.isEmpty());

Member Function Documentation

◆ appendBack()

template<typename T >
void SC::IntrusiveDoubleLinkedList< T >::appendBack ( IntrusiveDoubleLinkedList< T > & other)

Appends another list at the back of current list.

◆ clear()

template<typename T >
void SC::IntrusiveDoubleLinkedList< T >::clear ( )

Clears this linked list removing links between all linked list elements.

◆ dequeueFront()

template<typename T >
T * SC::IntrusiveDoubleLinkedList< T >::dequeueFront ( )
nodiscard

Removes and returns the first element of the linked list.

◆ isEmpty()

template<typename T >
bool SC::IntrusiveDoubleLinkedList< T >::isEmpty ( ) const
inlinenodiscard

Return true if the linked list is empty.

◆ queueBack()

template<typename T >
void SC::IntrusiveDoubleLinkedList< T >::queueBack ( T & item)

Appends item to the back of this linked list.

◆ remove()

template<typename T >
void SC::IntrusiveDoubleLinkedList< T >::remove ( T & item)

Removes item from this linked list.


The documentation for this struct was generated from the following file: