ReactOS  0.4.13-dev-259-g5ca9c9c
genlist.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Setup Library
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Generic list functions
5  * COPYRIGHT: Copyright 2008-2018 Christoph von Wittich <christoph at reactos.org>
6  */
7 
8 /* INCLUDES *****************************************************************/
9 
10 #include "precomp.h"
11 
12 #include "genlist.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
17 /* FUNCTIONS ****************************************************************/
18 
21 {
23 
25  if (List == NULL)
26  return NULL;
27 
28  InitializeListHead(&List->ListHead);
29  List->NumOfEntries = 0;
30  List->CurrentEntry = NULL;
31 
32  return List;
33 }
34 
35 VOID
38  IN BOOLEAN FreeData)
39 {
40  PGENERIC_LIST_ENTRY ListEntry;
42 
43  /* Release list entries */
44  while (!IsListEmpty(&List->ListHead))
45  {
46  Entry = RemoveHeadList(&List->ListHead);
48 
49  /* Release user data */
50  if (FreeData && ListEntry->Data != NULL)
51  RtlFreeHeap(ProcessHeap, 0, ListEntry->Data);
52 
53  /* Release list entry */
54  RtlFreeHeap(ProcessHeap, 0, ListEntry);
55  }
56 
57  /* Release list head */
59 }
60 
61 BOOLEAN
64  IN PVOID Data,
65  IN BOOLEAN Current)
66 {
68 
70  if (Entry == NULL)
71  return FALSE;
72 
73  Entry->List = List;
74  Entry->Data = Data;
75  Entry->UiData = 0;
76 
77  InsertTailList(&List->ListHead, &Entry->Entry);
78  ++List->NumOfEntries;
79 
80  if (Current || List->CurrentEntry == NULL)
81  List->CurrentEntry = Entry;
82 
83  return TRUE;
84 }
85 
86 VOID
90 {
91  if (!Entry || (Entry->List != List))
92  return;
93  List->CurrentEntry = Entry;
94 }
95 
99 {
100  return List->CurrentEntry;
101 }
102 
106 {
107  if (IsListEmpty(&List->ListHead))
108  return NULL;
109 
111 }
112 
116 {
117  PLIST_ENTRY Next = Entry->Entry.Flink;
118 
119  if (Next == &Entry->List->ListHead)
120  return NULL;
121 
123 }
124 
125 PVOID
128 {
129  return Entry->Data;
130 }
131 
132 ULONG_PTR
135 {
136  return Entry->UiData;
137 }
138 
139 ULONG
142 {
143  return List->NumOfEntries;
144 }
145 
146 /* EOF */
Definition: genlist.h:10
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:104
ULONG GetNumberOfListEntries(IN PGENERIC_LIST List)
Definition: genlist.c:140
struct _Entry Entry
Definition: kefuncs.h:640
VOID DestroyGenericList(IN OUT PGENERIC_LIST List, IN BOOLEAN FreeData)
Definition: genlist.c:36
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
PVOID Data
Definition: genlist.h:14
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
PVOID GetListEntryData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:126
Entry(ENTRY_TYPE etype)
Definition: entries.cpp:35
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:114
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
PGENERIC_LIST CreateGenericList(VOID)
Definition: genlist.c:20
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY List
Definition: psmgr.c:57
BOOLEAN AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PVOID Data, IN BOOLEAN Current)
Definition: genlist.c:62
Definition: typedefs.h:117
ULONG_PTR GetListEntryUiData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:133
HANDLE ProcessHeap
Definition: servman.c:15
VOID SetCurrentListEntry(IN PGENERIC_LIST List, IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:87
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
base of all file and directory entries
Definition: entries.h:82
PGENERIC_LIST_ENTRY GetCurrentListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:97