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 
18 HANDLE CListNode::hHeap = NULL;
19 INT    CListNode::nRef = 0;
20 
21 // Default constructor
22 CListNode::CListNode()
23 {
24 	Element = NULL;
25 	Next = NULL;
26 	Prev = NULL;
27 }
28 
29 // Constructor with element and next as starter values
30 CListNode::CListNode(PVOID element, CListNode *next, CListNode *prev)
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
61 VOID CListNode::SetElement(PVOID element)
62 {
63 	Element = element;
64 }
65 
66 // Set pointer to next node in list
67 VOID CListNode::SetNext(CListNode *next)
68 {
69 	Next = next;
70 }
71 
72 // Set pointer to previous node in list
73 VOID CListNode::SetPrev(CListNode *prev)
74 {
75 	Prev = prev;
76 }
77 
78 // Get element of node
79 PVOID CListNode::GetElement()
80 {
81 	return Element;
82 }
83 
84 // Get pointer to next node in list
85 CListNode *CListNode::GetNext()
86 {
87 	return Next;
88 }
89 
90 // Get pointer to previous node in list
91 CListNode *CListNode::GetPrev()
92 {
93 	return Prev;
94 }
95