ReactOS 0.4.16-dev-197-g92996da
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
35VOID
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
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
86VOID
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
110 return CONTAINING_RECORD(List->ListHead.Flink, GENERIC_LIST_ENTRY, Entry);
111}
112
116{
117 PLIST_ENTRY Next = Entry->Entry.Flink;
118
119 if (Next == &Entry->List->ListHead)
120 return NULL;
121
123}
124
125PVOID
128{
129 return Entry->Data;
130}
131
135{
136 return Entry->UiData;
137}
138
139ULONG
142{
143 return List->NumOfEntries;
144}
145
146/* EOF */
unsigned char BOOLEAN
HANDLE ProcessHeap
Definition: servman.c:15
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define InsertTailList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
PGENERIC_LIST CreateGenericList(VOID)
Definition: genlist.c:20
ULONG_PTR GetListEntryUiData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:133
VOID SetCurrentListEntry(IN PGENERIC_LIST List, IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:87
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:104
BOOLEAN AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PVOID Data, IN BOOLEAN Current)
Definition: genlist.c:62
VOID DestroyGenericList(IN OUT PGENERIC_LIST List, IN BOOLEAN FreeData)
Definition: genlist.c:36
PGENERIC_LIST_ENTRY GetCurrentListEntry(IN PGENERIC_LIST List)
Definition: genlist.c:97
ULONG GetNumberOfListEntries(IN PGENERIC_LIST List)
Definition: genlist.c:140
PVOID GetListEntryData(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:126
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition: genlist.c:114
base of all file and directory entries
Definition: entries.h:83
Entry(ENTRY_TYPE etype)
Definition: entries.cpp:35
Definition: genlist.h:11
PVOID Data
Definition: genlist.h:14
Definition: typedefs.h:120
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550