SatCat5
satcat5::util::ListCore Class Reference

Detailed Description

Helper functions for manipulating singly-linked lists.

See also
list.h, util::List.

This class defines a set of template functions for manipulating singly-linked lists. They are packaged into a single class to make it easier to "friend" the entire group.

Most users should instantiate and use the util::List class, rather than calling these functions directly. The base class is provided for edge-cases that must use bare pointers, such as the global linked lists used in "polling.h".

Definition at line 52 of file list.h.

#include <list.h>

Static Public Member Functions

template<class T >
static void add (T *&list, T *item)
 Add new item to front or back, whichever is simpler.
 
template<class T >
static void add_list (T *&list1, T *&list2)
 Add each item from "list2" onto "list1", destroying "list2". More...
 
template<class T >
static void add_safe (T *&list, T *item)
 Check if list already contains item before adding. More...
 
template<class T >
static bool contains (const T *list, const T *item)
 Scan the list, looking for the item in question.
 
template<class T >
static T ** find_ptr (T **list, const T *item)
 Find the link pointing to the designated item. More...
 
template<class T >
static T * get_index (T *list, unsigned idx)
 Fetch the Nth item from the linked list. More...
 
template<class T >
static bool has_loop (const T *list)
 Check if the linked list loops back on itself, using the two-pointer "tortoise and hare" algorithm.
 
template<class T >
static void insert_after (T *where, T *item)
 Insert a new item just after the designated position.
 
template<class T >
static unsigned len (const T *list)
 Traverse the linked list to count its length.
 
template<class T >
static T * next (const T *item)
 Fetch pointer to the next item. More...
 
template<class T >
static T * pop_front (T *&list)
 Remove the item at the head of the list.
 
template<class T >
static void push_front (T *&list, T *item)
 Add a new item at the head of the list.
 
template<class T >
static void push_back (T *&list, T *item)
 Add a new item at the tail of the list.
 
template<class T >
static void remove (T *&list, T *item)
 Remove the designated item from the list.
 
template<class T >
static void reset (T *&list, T *item)
 Discard list contents and reset to empty or a single item.
 
template<class T >
static bool pre_test_reset (T *&list, T *item)
 Check if a list contains exactly the specified item. More...
 

Member Function Documentation

◆ add_list()

template<class T >
static void satcat5::util::ListCore::add_list ( T *&  list1,
T *&  list2 
)
inlinestatic

Add each item from "list2" onto "list1", destroying "list2".

Items are pushed to the front or back in any convenient order.

Definition at line 63 of file list.h.

◆ add_safe()

template<class T >
static void satcat5::util::ListCore::add_safe ( T *&  list,
T *  item 
)
inlinestatic

Check if list already contains item before adding.

Adding the same item twice can create an infinite loop.

Definition at line 72 of file list.h.

◆ find_ptr()

template<class T >
static T** satcat5::util::ListCore::find_ptr ( T **  list,
const T *  item 
)
inlinestatic

Find the link pointing to the designated item.

Returns
A reference to "m_next" in the previous list item, a reference to the head-of-list pointer, or NULL.

Definition at line 92 of file list.h.

◆ get_index()

template<class T >
static T* satcat5::util::ListCore::get_index ( T *  list,
unsigned  idx 
)
inlinestatic

Fetch the Nth item from the linked list.

Returns
null pointer if index >= length.

Definition at line 104 of file list.h.

◆ next()

template<class T >
static T* satcat5::util::ListCore::next ( const T *  item)
inlinestatic

Fetch pointer to the next item.

This may be required for access to private member variables.

Definition at line 151 of file list.h.

◆ pre_test_reset()

template<class T >
static bool satcat5::util::ListCore::pre_test_reset ( T *&  list,
T *  item 
)
inlinestatic

Check if a list contains exactly the specified item.

If it does not, call reset to forcibly enter that state.

Returns
True if a reset() was required. (Unit testing only, not recommended for production.)

Definition at line 200 of file list.h.


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