uLib
User mode C/C++ extended API library for Win32 programmers.
|
#include <uLib/ListFunc.h>
DLinkList is a semi-circular double linked list manipulation class.
That is, the first and last entries always point to the list head, not to each other.
The protected LIST_ENTRY is the list head.
One of it's more powerful features is DLinkList::QuickSort(),
which performs it's work by swapping links, not node data,
meaning You can sort large nodes without performance penalty.
Definition at line 184 of file ListFunc.h.
Public Data | |
UINT | Count |
bool | SafeRemove |
Additional Inherited Members | |
![]() | |
struct _LIST_ENTRY * | Flink |
struct _LIST_ENTRY * | Blink |
DLinkList::DLinkList | ( | bool | Safe = true | ) |
Default constructor.
Definition at line 70 of file ListCls.cpp.
DLinkList::DLinkList | ( | PLIST_ENTRY | ListHead, |
bool | Safe | ||
) |
Special constuctor to pick up (re-head) a plain NT list head.
See also ImportFromListHead(), ExportToListHead().
Definition at line 77 of file ListCls.cpp.
DLinkList::~DLinkList | ( | ) |
DLinkList doesn't need a destructor since it doesn't allocate anything.
However, it is included, to emit a debugger message if the list is not empty.
Definition at line 83 of file ListCls.cpp.
PDLinkList DLinkList::operator= | ( | PLIST_ENTRY | ListHead | ) |
operator=( PLIST_ENTRY ListHead ) usurps the ListHead list.
The DLinkList instance must be empty before using this operator.
Definition at line 407 of file ListCls.cpp.
|
inline |
Append an entry.
Definition at line 222 of file ListFunc.h.
|
inline |
Remove an entry.
Definition at line 223 of file ListFunc.h.
|
inline |
Definition at line 225 of file ListFunc.h.
bool DLinkList::Exist | ( | PLIST_ENTRY | Entry | ) |
Returns true if Entry is found.
Definition at line 145 of file ListCls.cpp.
|
inline |
Definition at line 228 of file ListFunc.h.
|
inline |
Definition at line 229 of file ListFunc.h.
PLIST_ENTRY DLinkList::GetNext | ( | PLIST_ENTRY | Current | ) |
GetNext() and GetPrev() provides fully circular access to this list.
For performance reasons, these two does not validate Current,
so be sure to use an entry that is in the list, lest Hell break loose.
Definition at line 191 of file ListCls.cpp.
PLIST_ENTRY DLinkList::GetPrev | ( | PLIST_ENTRY | Current | ) |
See GetNext().
Definition at line 202 of file ListCls.cpp.
PLIST_ENTRY DLinkList::Append | ( | PLIST_ENTRY | Entry | ) |
Insert at tail, i.e InsertTailList
Definition at line 90 of file ListCls.cpp.
PLIST_ENTRY DLinkList::Prepend | ( | PLIST_ENTRY | Entry | ) |
Insert at head, i.e InsertHeadList
Definition at line 103 of file ListCls.cpp.
PLIST_ENTRY DLinkList::RemoveEntry | ( | PLIST_ENTRY | Entry | ) |
Returns Entry if removed, else NULL.
Definition at line 213 of file ListCls.cpp.
PLIST_ENTRY DLinkList::RemoveFirst | ( | ) |
Remove at head.
Definition at line 231 of file ListCls.cpp.
PLIST_ENTRY DLinkList::RemoveLast | ( | ) |
Remove at tail.
Definition at line 236 of file ListCls.cpp.
void DLinkList::RemoveAll | ( | PDListFunc | ItemAction, |
void * | UserData = NULL |
||
) |
RemoveAll removes all entries from the list, calling ItemAction for each.
Use ItemAction to e.g. delete your entries, or any other cleanup you need.
If ItemAction returns false, the remaining operation is aborted.
If ItemAction is NULL, the entries are just removed, which might leak. See also PDListFunc
Definition at line 241 of file ListCls.cpp.
|
inline |
Definition at line 258 of file ListFunc.h.
|
inline |
Push() / Pull() = FIFO (Queue)
Definition at line 259 of file ListFunc.h.
|
inline |
Definition at line 260 of file ListFunc.h.
PLIST_ENTRY DLinkList::operator [] | ( | size_t | Index | ) |
Indexed access (can be slow).
Definition at line 277 of file ListCls.cpp.
bool DLinkList::ForEach | ( | PDListFunc | Action, |
void * | UserData = NULL |
||
) |
ForEach invokes the Action callback on each list entry.
Note: ForEach is not intended for clearing a list, use RemoveAll() for that.
See PDListFunc for callback details.
Definition at line 317 of file ListCls.cpp.
PLIST_ENTRY DLinkList::FirstThat | ( | PDListFunc | Match, |
void * | UserData = NULL |
||
) |
Find the first matching entry, as determined by the Match callback.
See also ForEach().
Definition at line 287 of file ListCls.cpp.
PLIST_ENTRY DLinkList::LastThat | ( | PDListFunc | Match, |
void * | UserData = NULL |
||
) |
Find the last matching entry, as determined by the Match callback.
See also ForEach().
Definition at line 302 of file ListCls.cpp.
void DLinkList::QuickSort | ( | PDListComp | Compare, |
void * | UserData = NULL |
||
) |
Quicksort the list by swapping links, not node data (so you can sort large Entries).
The Compare function should return a C tristate comparison value -x/0/+x.
UserData (optional) can be anything your comparator might need, or NULL.
See PDListComp for callback details.
Definition at line 335 of file ListCls.cpp.
UINT DLinkList::AppendList | ( | IN PLIST_ENTRY | ListToAppend, |
OPTOUT PLIST_ENTRY * | ppFirst | ||
) |
AppendList appends another list to the end of this.
ListToAppend | The list head of the list to append. (This differs from the DDK AppendTailList function, which expects a headless list as it's source argument.) |
ppFirst | If provided, recieves a pointer to the first added entry. |
Definition at line 116 of file ListCls.cpp.
UINT DLinkList::AppendList | ( | IN PDLinkList | ListToAppend, |
OPTOUT PLIST_ENTRY * | ppFirst | ||
) |
See AppendList().
Definition at line 139 of file ListCls.cpp.
|
inline |
Definition at line 309 of file ListFunc.h.
UINT DLinkList::ExportToListHead | ( | PLIST_ENTRY ListHead | OUT | ) |
ExportToListHead transfers this to a plain NT listhead.
After ExportToListHead, the list's head pointers will refer to ListHead,
not this, so you must access the entries through ListHead.
Definition at line 431 of file ListCls.cpp.
UINT DLinkList::ImportFromListHead | ( | IN PLIST_ENTRY | ListHead, |
OPTOUT PLIST_ENTRY * | ppFirst | ||
) |
ImportFromListHead adds all entries from ListHead to this list.
See also AppendList()
Definition at line 446 of file ListCls.cpp.
UINT DLinkList::ExportToHeadlessList | ( | PLIST_ENTRY * | Circular | ) |
[SPECIAL] ExportToHeadlessList transfers this to a headless (i.e. circular) list.
See also ExportToListHead(), ImportHeadlessList().
Definition at line 462 of file ListCls.cpp.
UINT DLinkList::ImportHeadlessList | ( | IN PLIST_ENTRY | Circular, |
OPTOUT PLIST_ENTRY * | ppFirst | ||
) |
[SPECIAL] ImportHeadlessList usurps a circular list into 'this'.
If 'this' is empty, Circular simply becomes this "headed" list,
otherwise Circular is appended at the end of this list.
Definition at line 472 of file ListCls.cpp.
UINT DLinkList::Count |
Nr of items in the linked list.
Definition at line 186 of file ListFunc.h.
bool DLinkList::SafeRemove |
Set true to check existence before removing an entry.
RemoveEntry is much faster without this, but the programmer must be sure to not try removing an item which isn't in the list.
Doing so is an error and will create a mess (cross-linked list) and cause undefined behavior.
When true, RemoveEntry() calls Exist() before commencing removal.
This protects against cross-link errors, but the list has to be traversed, possibly in it's entirety,
each time an item is removed, which can take a long time, especially when removing many entries from a big list.
RemoveAll() has been implemented to be efficient even with SafeRemove on,
by always removing the first item, which makes Exist as fast as possible.
Definition at line 187 of file ListFunc.h.