ReactOS  0.4.14-dev-1007-g90d795b
list.cpp
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS HTTP Daemon
4  * FILE: list.cpp
5  * PURPOSE: A doubly linked list implementation
6  * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7  * REVISIONS:
8  * CSH 01/09/2000 Created
9  * NOTES: The linked list does it's own heap management for
10  * better performance
11  * TODO: - InsertBefore(), InsertAfter(), Move()
12  */
13 #include <windows.h>
14 #include <list.h>
15 
16 // **************************** CListNode ****************************
17 
20 
21 // Default constructor
23 {
24  Element = NULL;
25  Next = NULL;
26  Prev = NULL;
27 }
28 
29 // Constructor with element and next as starter values
31 {
32  Element = element;
33  Next = next;
34  Prev = prev;
35 }
36 
37 void* CListNode::operator new(size_t size)
38 {
39  PVOID p;
40  if (hHeap == NULL) {
41  SYSTEM_INFO inf;
42  GetSystemInfo(&inf);
43  hHeap = HeapCreate(0, inf.dwAllocationGranularity, 0);
44  }
45  if ((p = HeapAlloc(hHeap, 0, size)) != NULL)
46  nRef++;
47  return p;
48 }
49 
50 VOID CListNode::operator delete(void* p)
51 {
52  if (HeapFree(hHeap, 0, p) != FALSE)
53  nRef--;
54  if (nRef == 0) {
55  HeapDestroy(hHeap);
56  hHeap = NULL;
57  }
58 }
59 
60 // Set element
62 {
63  Element = element;
64 }
65 
66 // Set pointer to next node in list
68 {
69  Next = next;
70 }
71 
72 // Set pointer to previous node in list
74 {
75  Prev = prev;
76 }
77 
78 // Get element of node
80 {
81  return Element;
82 }
83 
84 // Get pointer to next node in list
86 {
87  return Next;
88 }
89 
90 // Get pointer to previous node in list
92 {
93  return Prev;
94 }
DWORD dwAllocationGranularity
Definition: winbase.h:1139
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45
CListNode()
Definition: list.cpp:22
operator
static HANDLE hHeap
Definition: list.h:30
static INT nRef
Definition: list.h:31
int32_t INT
Definition: typedefs.h:57
BOOL WINAPI HeapDestroy(HANDLE hHeap)
Definition: heapmem.c:85
smooth NULL
Definition: ftsmooth.c:416
CListNode * GetPrev()
Definition: list.cpp:91
VOID SetElement(PVOID element)
Definition: list.cpp:61
GLsizeiptr size
Definition: glext.h:5919
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
CListNode * GetNext()
Definition: list.cpp:85
PVOID GetElement()
Definition: list.cpp:79
PVOID Element
Definition: list.h:27
CListNode * Next
Definition: list.h:28
static unsigned __int64 next
Definition: rand_nt.c:6
CListNode * Prev
Definition: list.h:29
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:142
VOID SetNext(CListNode *next)
Definition: list.cpp:67
Definition: list.h:12
GLfloat GLfloat p
Definition: glext.h:8902
VOID SetPrev(CListNode *prev)
Definition: list.cpp:73
#define HeapFree(x, y, z)
Definition: compat.h:402