SatCat5
satcat5::util::List< T > Class Template Referencefinal

Detailed Description

template<class T>
class satcat5::util::List< T >

Templated linked-list class.

See also
list.h, util::ListCore. This class implements a singly-linked list of objects.

Definition at line 210 of file list.h.

#include <list.h>

Inheritance diagram for satcat5::util::List< T >:
[legend]

Public Member Functions

constexpr List ()
 Construct an empty list.
 
constexpr List (T *item)
 Construct list with one item.
 
 ~List ()
 Destructor requires no action.
 
T * head () const
 
void add (T *item)
 Add new item to front or back, whichever is simpler.
 
void add_list (satcat5::util::List< T > &other)
 Add each item from "list2" onto "list1", destroying "list2". More...
 
void add_safe (T *item)
 Check if list already contains item before adding. More...
 
bool contains (const T *item) const
 Scan the list, looking for the item in question.
 
T * get_index (unsigned idx)
 Fetch the Nth item from the linked list. More...
 
bool has_loop () const
 Check if the linked list loops back on itself, using the two-pointer "tortoise and hare" algorithm.
 
void insert_after (T *where, T *item)
 Insert a new item just after the designated position.
 
bool is_empty () const
 Is this list empty?
 
unsigned len () const
 Traverse the linked list to count its length.
 
T * next (const T *item) const
 Fetch pointer to the next item.
 
T * pop_front ()
 Remove the item at the head of the list.
 
void push_front (T *item)
 Add a new item at the head of the list.
 
void push_back (T *item)
 Add a new item at the tail of the list.
 
void remove (T *item)
 Remove the designated item from the list.
 
void reset (T *item=0)
 Discard list contents and reset to empty or a single item.
 

Protected Attributes

T * m_head
 Pointer to first item, zero if empty.
 

Member Function Documentation

◆ add_list()

template<class T >
void satcat5::util::List< T >::add_list ( satcat5::util::List< T > &  other)
inline

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

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

Definition at line 226 of file list.h.

◆ add_safe()

template<class T >
void satcat5::util::List< T >::add_safe ( T *  item)
inline

Check if list already contains item before adding.

Adding the same item twice can create an infinite loop.

Definition at line 231 of file list.h.

◆ get_index()

template<class T >
T* satcat5::util::List< T >::get_index ( unsigned  idx)
inline

Fetch the Nth item from the linked list.

Returns
null pointer if index >= length.

Definition at line 240 of file list.h.


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