uLib  User mode C/C++ extended API library for Win32 programmers.
ListEx.h
Go to the documentation of this file.
1 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 // Project: uLib - User mode utility library.
3 // Module: Double-linked list class with mutually exclusive access.
4 // Author: Copyright (c) Love Nystrom
5 // License: NNOSL (BSD descendant, see NNOSL.txt in the base directory).
6 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 
8 #ifndef __ListEx_h_incl__
9 #define __ListEx_h_incl__
10 
11 #include <uLib/Common.h>
12 #include <uLib/ListFunc.h>
13 
15 //-----------------------------------------------------------------------------
16 // DLinkListEx - Preliminary
17 //-----------------------------------------------------------------------------
20 
21 #define DLX_DEF_SPINCOUNT 3967
22 
23 
29 class DLinkListEx : public DLinkList {
30 protected:
31  CRITICAL_SECTION _csect;
32 public:
33  DLinkListEx( DWORD SpinCount = DLX_DEF_SPINCOUNT );
34  DLinkListEx( PLIST_ENTRY ListHead, DWORD SpinCount = DLX_DEF_SPINCOUNT );
35  ~DLinkListEx();
36 
49 
50  bool Lock( bool Wait = false );
51  void Unlock();
52  DWORD SetLockSpinCount( DWORD SpinCount );
53 
54  // Add entries to list
55 
56  PLIST_ENTRY Append( PLIST_ENTRY Entry );
58  PLIST_ENTRY operator += ( PLIST_ENTRY Entry ) { return Append( Entry ); }
59  PLIST_ENTRY operator -= ( PLIST_ENTRY Entry ) { return RemoveEntry( Entry ); }
60 
61  // AppendList appends another list to the end of this.
62 
63  UINT AppendList( IN PLIST_ENTRY ListToAppend, OPTOUT PLIST_ENTRY* ppFirst );
64  UINT AppendList( PDLinkList ListToAppend, OPTOUT PLIST_ENTRY* ppFirst );
65  UINT operator += ( PDLinkList ListToAppend ) { return AppendList( ListToAppend, NULL ); }
66 
67  // Return Entry if removed, else NULL.
68 
70  PLIST_ENTRY RemoveFirst() { return RemoveEntry( Flink ); }
71  PLIST_ENTRY RemoveLast() { return RemoveEntry( Blink ); }
72 
73  void RemoveAll( PDListFunc ItemAction, void* UserData = NULL );
74 
75  PLIST_ENTRY FirstThat( PDListFunc Match, void* UserData = NULL );
76  PLIST_ENTRY LastThat( PDListFunc Match, void* UserData = NULL );
77  bool ForEach( PDListFunc Action, void* UserData = NULL );
78 
79  void QuickSort( PDListComp Compare, void* UserData = NULL );
80 
81  // Transfer this to a standard NT listhead.
82 
83  UINT ExportToListHead( PLIST_ENTRY ListHead );
84  UINT ImportFromListHead( IN PLIST_ENTRY ListHead, OPTOUT PLIST_ENTRY* ppFirst );
85 
86  // Transfer to a circular list.
87 
88  UINT ExportToHeadlessList( PLIST_ENTRY* Target );
89  UINT ImportHeadlessList( IN PLIST_ENTRY Circular, OPTOUT PLIST_ENTRY* ppFirst );
90 };
91 
94 #endif//ndef __ListEx_h_incl__
95 // EOF
PLIST_ENTRY FirstThat(PDListFunc Match, void *UserData=NULL)
Definition: ListCls.cpp:287
unsigned long DWORD
Definition: Common.h:414
UINT ExportToListHead(PLIST_ENTRY ListHead)
Definition: ListCls.cpp:431
UINT ImportFromListHead(IN PLIST_ENTRY ListHead, OPTOUT PLIST_ENTRY *ppFirst)
Definition: ListCls.cpp:446
PLIST_ENTRY LastThat(PDListFunc Match, void *UserData=NULL)
Definition: ListCls.cpp:302
UINT ImportHeadlessList(IN PLIST_ENTRY Circular, OPTOUT PLIST_ENTRY *ppFirst)
Definition: ListCls.cpp:472
PLIST_ENTRY operator+=(PLIST_ENTRY Entry)
Definition: ListFunc.h:222
bool ForEach(PDListFunc Action, void *UserData=NULL)
Definition: ListCls.cpp:317
#define OPTOUT
Definition: Common.h:264
UINT AppendList(IN PLIST_ENTRY ListToAppend, OPTOUT PLIST_ENTRY *ppFirst)
Definition: ListCls.cpp:116
PLIST_ENTRY RemoveLast()
Definition: ListCls.cpp:236
struct _LIST_ENTRY * PLIST_ENTRY
bool(__stdcall * PDListFunc)(PLIST_ENTRY Entry, void *UserData)
Definition: ListFunc.h:152
PLIST_ENTRY Prepend(PLIST_ENTRY Entry)
Definition: ListCls.cpp:103
PLIST_ENTRY Append(PLIST_ENTRY Entry)
Definition: ListCls.cpp:90
int(__stdcall * PDListComp)(PLIST_ENTRY X, PLIST_ENTRY Y, void *UserData)
Definition: ListFunc.h:159
void QuickSort(PDListComp Compare, void *UserData=NULL)
Definition: ListCls.cpp:335
void RemoveAll(PDListFunc ItemAction, void *UserData=NULL)
Definition: ListCls.cpp:241
class DLinkList * PDLinkList
Definition: ListFunc.h:143
Common include; Added types, small "ubiquitous" utilities, et c.
PLIST_ENTRY operator -=(PLIST_ENTRY Entry)
Definition: ListFunc.h:223
UINT ExportToHeadlessList(PLIST_ENTRY *Circular)
Definition: ListCls.cpp:462
PLIST_ENTRY RemoveFirst()
Definition: ListCls.cpp:231
PLIST_ENTRY RemoveEntry(PLIST_ENTRY Entry)
Definition: ListCls.cpp:213