10#ifndef STK_LINKED_LIST_H_
11#define STK_LINKED_LIST_H_
35template <
class T,
bool TClosedLoop>
class DListHead;
134 operator T *() {
return static_cast<T *
>(
this); }
141 operator const T *()
const {
return static_cast<const T *
>(
this); }
388 entry->
Link(
this, next, prev);
464 template <
typename TTargetType,
typename TSourceType>
470 return static_cast<TTargetType *
>(lentry);
#define STK_STATIC_ASSERT_N(NAME, X)
Compile-time assertion with a user-defined name suffix.
#define __stk_forceinline
Forces compiler to always inline the decorated function, regardless of optimisation level.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define __stk_constexpr_cpp17
constexpr definition for C++17 and above.
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...
DLEntryType * GetLast()
Get the last (back) entry without removing it.
DLEntryType * m_first
Pointer to the first (front) entry, or NULL when empty.
void LinkBack(DLEntryType *entry)
Append entry to the back of the list (pointer overload).
void Unlink(DLEntryType *entry)
Remove entry from this list.
DListHead()
Construct an empty list head (count = 0, first = last = NULL).
void Clear()
Remove and unlink all entries. After this call the list is empty.
const DLEntryType * GetFirst() const
Get the first (front) entry without removing it.
const DLEntryType * GetLast() const
Get the last (back) entry without removing it.
void LinkBack(DLEntryType &entry)
Append entry to the back of the list (reference overload).
void RelinkTo(DListHead &to)
Move all entries from this list to the back of to, preserving order.
void UpdateEnds()
Repair the boundary and circular pointers after every structural change.
void LinkFront(DLEntryType *entry)
Prepend entry to the front of the list (pointer overload).
DLEntryType * PopBack()
Remove and return the last entry.
size_t GetSize() const
Get the number of entries currently in the list.
DLEntryType * PopFront()
Remove and return the first entry.
DLEntryType * m_last
Pointer to the last (back) entry, or NULL when empty.
DLEntryType * GetFirst()
Get the first (front) entry without removing it.
DListEntry< T, TClosedLoop > DLEntryType
Convenience alias for the node type stored in this list.
bool IsEmpty() const
Check whether the list contains no entries.
void Link(DLEntryType *entry, DLEntryType *next=nullptr, DLEntryType *prev=nullptr)
Insert entry into the list between prev and next.
void LinkFront(DLEntryType &entry)
Prepend entry to the front of the list (reference overload).
size_t m_count
Number of entries currently in the list.
Intrusive doubly-linked list node. Embed this as a base class in any object (T) that needs to partici...
DListEntry< T, TClosedLoop > DLEntryType
Convenience alias for this entry type. Used to avoid repeating the full template spelling.
DLHeadType * m_head
Owning list head, or NULL when the entry is not linked.
~DListEntry()=default
Protected non-virtual destructor.
const DLHeadType * GetHead() const
Get the list head this entry currently belongs to.
void Unlink()
Remove this entry from its current list.
DLEntryType * GetNext()
Get the next entry in the list.
DLEntryType * m_next
Next entry in the list, or NULL (open list boundary) / first entry (closed loop).
const DLEntryType * GetPrev() const
Get the previous entry in the list.
DLEntryType * m_prev
Previous entry in the list, or NULL (open list boundary) / last entry (closed loop).
DLHeadType * GetHead()
Get the list head this entry currently belongs to.
void Link(DLHeadType *head, DLEntryType *next, DLEntryType *prev)
Wire this entry into a list between prev and next.
DLEntryType * GetPrev()
Get the previous entry in the list.
DListEntry()
Construct an unlinked entry. All pointers initialized to NULL.
bool IsLinked() const
Check whether this entry is currently a member of any list.
DListHead< T, TClosedLoop > DLHeadType
Convenience alias for the corresponding list head type.
const DLEntryType * GetNext() const
Get the next entry in the list.
Helper for casting list entries to concrete (parent) types.
static __stk_forceinline TTargetType * ListEntryToParent(TSourceType *const lentry)
Safely casts an intrusive list entry to its concrete parent container object type.