10#ifndef STK_LINKED_LIST_H_
11#define STK_LINKED_LIST_H_
35template <
class T,
bool _ClosedLoop>
class DListHead;
108 operator T *() {
return static_cast<T *
>(
this); }
115 operator const T *()
const {
return static_cast<const T *
>(
this); }
339 entry->
Link(
this, next, prev);
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Namespace of STK package.
Internal utility namespace containing data structure helpers (linked lists, etc.) used by the kernel ...
Intrusive doubly-linked list container. Manages a collection of DListEntry nodes embedded in host obj...
size_t GetSize() const
Get the number of entries currently in the list.
void RelinkTo(DListHead &to)
Move all entries from this list to the back of to, preserving order.
DLEntryType * m_first
Pointer to the first (front) entry, or NULL when empty.
size_t m_count
Number of entries currently in the list.
void Link(DLEntryType *entry, DLEntryType *next=nullptr, DLEntryType *prev=nullptr)
Insert entry into the list between prev and next.
DListEntry< T, _ClosedLoop > DLEntryType
Convenience alias for the node type stored in this list.
void Clear()
Remove and unlink all entries. After this call the list is empty.
void LinkFront(DLEntryType &entry)
Prepend entry to the front of the list (reference overload).
DLEntryType * PopBack()
Remove and return the last entry.
void LinkFront(DLEntryType *entry)
Prepend entry to the front of the list (pointer overload).
DLEntryType * GetFirst() const
Get the first (front) entry without removing it.
bool IsEmpty() const
Check whether the list contains no entries.
void UpdateEnds()
Repair the boundary and circular pointers after every structural change.
DListHead()
Construct an empty list head (count = 0, first = last = NULL).
void Unlink(DLEntryType *entry)
Remove entry from this list.
DLEntryType * PopFront()
Remove and return the first entry.
void LinkBack(DLEntryType &entry)
Append entry to the back of the list (reference overload).
DLEntryType * GetLast() const
Get the last (back) entry without removing it.
DLEntryType * m_last
Pointer to the last (back) entry, or NULL when empty.
void LinkBack(DLEntryType *entry)
Append entry to the back of the list (pointer overload).
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...
DLEntryType * m_next
Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
DLEntryType * GetPrev() const
Get the previous entry in the list.
DLHeadType * GetHead() const
Get the list head this entry currently belongs to.
bool IsLinked() const
Check whether this entry is currently a member of any list.
DLEntryType * m_prev
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).
DListHead< T, _ClosedLoop > DLHeadType
Convenience alias for the corresponding list head type.
DLHeadType * m_head
Owning list head, or NULL when the entry is not linked.
void Link(DLHeadType *head, DLEntryType *next, DLEntryType *prev)
Wire this entry into a list between prev and next.
DLEntryType * GetNext() const
Get the next entry in the list.
DListEntry< T, _ClosedLoop > DLEntryType
Convenience alias for this entry type. Used to avoid repeating the full template spelling.
void Unlink()
Remove this entry from its current list.
DListEntry()
Construct an unlinked entry. All pointers initialised to NULL.
~DListEntry()
Protected non-virtual destructor.