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
19
PGENERIC_LIST
20
CreateGenericList
(
VOID
)
21
{
22
PGENERIC_LIST
List
;
23
24
List
=
RtlAllocateHeap
(
ProcessHeap
, 0,
sizeof
(
GENERIC_LIST
));
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
36
DestroyGenericList
(
37
IN
OUT
PGENERIC_LIST
List
,
38
IN
BOOLEAN
FreeData)
39
{
40
PGENERIC_LIST_ENTRY
ListEntry;
41
PLIST_ENTRY
Entry
;
42
43
/* Release list entries */
44
while
(!
IsListEmpty
(&
List
->ListHead))
45
{
46
Entry
=
RemoveHeadList
(&
List
->ListHead);
47
ListEntry =
CONTAINING_RECORD
(
Entry
,
GENERIC_LIST_ENTRY
,
Entry
);
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 */
58
RtlFreeHeap
(
ProcessHeap
, 0,
List
);
59
}
60
61
BOOLEAN
62
AppendGenericListEntry
(
63
IN
OUT
PGENERIC_LIST
List
,
64
IN
PVOID
Data
,
65
IN
BOOLEAN
Current)
66
{
67
PGENERIC_LIST_ENTRY
Entry
;
68
69
Entry
=
RtlAllocateHeap
(
ProcessHeap
, 0,
sizeof
(
GENERIC_LIST_ENTRY
));
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
87
SetCurrentListEntry
(
88
IN
PGENERIC_LIST
List
,
89
IN
PGENERIC_LIST_ENTRY
Entry
)
90
{
91
if
(!
Entry
|| (
Entry
->List !=
List
))
92
return
;
93
List
->CurrentEntry =
Entry
;
94
}
95
96
PGENERIC_LIST_ENTRY
97
GetCurrentListEntry
(
98
IN
PGENERIC_LIST
List
)
99
{
100
return
List
->CurrentEntry;
101
}
102
103
PGENERIC_LIST_ENTRY
104
GetFirstListEntry
(
105
IN
PGENERIC_LIST
List
)
106
{
107
if
(
IsListEmpty
(&
List
->ListHead))
108
return
NULL
;
109
110
return
CONTAINING_RECORD
(
List
->ListHead.Flink,
GENERIC_LIST_ENTRY
,
Entry
);
111
}
112
113
PGENERIC_LIST_ENTRY
114
GetNextListEntry
(
115
IN
PGENERIC_LIST_ENTRY
Entry
)
116
{
117
PLIST_ENTRY
Next =
Entry
->
Entry
.Flink;
118
119
if
(Next == &
Entry
->List->ListHead)
120
return
NULL
;
121
122
return
CONTAINING_RECORD
(Next,
GENERIC_LIST_ENTRY
,
Entry
);
123
}
124
125
PVOID
126
GetListEntryData
(
127
IN
PGENERIC_LIST_ENTRY
Entry
)
128
{
129
return
Entry
->Data;
130
}
131
132
ULONG_PTR
133
GetListEntryUiData
(
134
IN
PGENERIC_LIST_ENTRY
Entry
)
135
{
136
return
Entry
->UiData;
137
}
138
139
ULONG
140
GetNumberOfListEntries
(
141
IN
PGENERIC_LIST
List
)
142
{
143
return
List
->NumOfEntries;
144
}
145
146
/* EOF */
BOOLEAN
unsigned char BOOLEAN
Definition:
ProcessorBind.h:185
ProcessHeap
HANDLE ProcessHeap
Definition:
servman.c:15
RtlAllocateHeap
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition:
heap.c:590
RtlFreeHeap
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition:
heap.c:608
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
InsertTailList
#define InsertTailList(ListHead, Entry)
Definition:
env_spec_w32.h:1003
IsListEmpty
#define IsListEmpty(ListHead)
Definition:
env_spec_w32.h:954
RemoveHeadList
#define RemoveHeadList(ListHead)
Definition:
env_spec_w32.h:964
InitializeListHead
#define InitializeListHead(ListHead)
Definition:
env_spec_w32.h:944
void
Definition:
nsiface.idl:2307
CreateGenericList
PGENERIC_LIST CreateGenericList(VOID)
Definition:
genlist.c:20
GetListEntryUiData
ULONG_PTR GetListEntryUiData(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:133
SetCurrentListEntry
VOID SetCurrentListEntry(IN PGENERIC_LIST List, IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:87
GetFirstListEntry
PGENERIC_LIST_ENTRY GetFirstListEntry(IN PGENERIC_LIST List)
Definition:
genlist.c:104
AppendGenericListEntry
BOOLEAN AppendGenericListEntry(IN OUT PGENERIC_LIST List, IN PVOID Data, IN BOOLEAN Current)
Definition:
genlist.c:62
DestroyGenericList
VOID DestroyGenericList(IN OUT PGENERIC_LIST List, IN BOOLEAN FreeData)
Definition:
genlist.c:36
GetCurrentListEntry
PGENERIC_LIST_ENTRY GetCurrentListEntry(IN PGENERIC_LIST List)
Definition:
genlist.c:97
GetNumberOfListEntries
ULONG GetNumberOfListEntries(IN PGENERIC_LIST List)
Definition:
genlist.c:140
GetListEntryData
PVOID GetListEntryData(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:126
GetNextListEntry
PGENERIC_LIST_ENTRY GetNextListEntry(IN PGENERIC_LIST_ENTRY Entry)
Definition:
genlist.c:114
Data
Definition:
sort_test.cpp:77
Entry
base of all file and directory entries
Definition:
entries.h:83
Entry::Entry
Entry(ENTRY_TYPE etype)
Definition:
entries.cpp:35
_GENERIC_LIST_ENTRY
Definition:
genlist.h:11
_GENERIC_LIST_ENTRY::Data
PVOID Data
Definition:
genlist.h:14
_GENERIC_LIST
Definition:
genlist.h:19
_LIST_ENTRY
Definition:
typedefs.h:120
ULONG_PTR
uint32_t ULONG_PTR
Definition:
typedefs.h:65
IN
#define IN
Definition:
typedefs.h:39
CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field)
Definition:
typedefs.h:260
ULONG
uint32_t ULONG
Definition:
typedefs.h:59
OUT
#define OUT
Definition:
typedefs.h:40
genlist.h
List
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition:
wdfresource.h:550
base
setup
lib
utils
genlist.c
Generated on Wed Oct 30 2024 06:02:27 for ReactOS by
1.9.6