ReactOS 0.4.15-dev-7906-g1b85a5f
list.h
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS HTTP Daemon
4 * FILE: include/list.h
5 */
6#ifndef __LIST_H
7#define __LIST_H
8
9#include <windows.h>
10#include <iterator.h>
11
12class CListNode {
13public:
14 CListNode();
17 void* operator new(size_t s);
18 VOID operator delete(void* p);
19
22 VOID SetPrev(CListNode *prev);
26private:
30 static HANDLE hHeap;
31 static INT nRef;
32};
33
34template <class Item> class CList {
35public:
36 //CList(CList&);
40
42 LONG Count() const;
43 Item& Get(const LONG index) const;
44 // Can throw bad_alloc
50private:
55};
56
57template <class Item> class CListIterator : public CIterator<Item> {
58public:
60 virtual VOID First();
61 virtual VOID Next();
62 virtual BOOL IsDone() const;
63 virtual Item CurrentItem() const;
64private:
67};
68
69// ****************************** CList ******************************
70
71// Default constructor
72template <class Item>
74{
75 // Create dummy nodes
76 Trailer = new CListNode;
77 Header = new CListNode;
78 Header->SetNext(Trailer);
79 Trailer->SetPrev(Header);
80}
81
82// Default destructor
83template <class Item>
85{
86 RemoveAll();
87 delete Trailer;
88 delete Header;
89}
90
91// Create an iterator for the list
92template <class Item>
94{
95 return new CListIterator<Item>((CList<Item> *) this);
96}
97
98// Return number of elements in list
99template <class Item>
101{
102 return NodeCount;
103}
104
105// Return element at index
106template <class Item>
108{
110
111 if ((index < 0) || (index >= NodeCount))
112 return NULL;
113
114 node = Header;
115 for (int i = 0; i <= index; i++)
116 node = node->GetNext();
117
118 return (Item *) node->GetElement();
119}
120
121// Insert an element into the list
122template <class Item>
124{
126
127 node = new CListNode((PVOID)element, Trailer, Trailer->GetPrev());
128 Trailer->GetPrev()->SetNext(node);
129 Trailer->SetPrev(node);
130 NodeCount++;
131}
132
133// Remove an element from the list
134template <class Item>
136{
138
139 node = Search(element);
140 if (node != NULL) {
141 node->GetPrev()->SetNext(node->GetNext());
142 node->GetNext()->SetPrev(node->GetPrev());
143 NodeCount--;
144 delete node;
145 }
146}
147
148// Remove all elements in list
149template <class Item>
151{
153 CListNode *tmp;
154
155 node = Header->GetNext();
156 while (node != Trailer) {
157 tmp = node->GetNext();
158 delete node;
159 node = tmp;
160 }
161 Header->SetNext(Trailer);
162 Trailer->SetPrev(Header);
163 NodeCount = 0;
164}
165
166// Return header node
167template <class Item>
169{
170 return Header;
171}
172
173// Return trailer node
174template <class Item>
176{
177 return Trailer;
178}
179
180// Searches for a node that contains the element. Returns NULL if element is not found
181template <class Item>
183{
185
186 node = Header;
187 while (((node = node->GetNext()) != Trailer) && (node->GetElement() != element));
188 if (node != Trailer)
189 return node;
190 else
191 return NULL;
192}
193
194
195// ************************** CListIterator **************************
196
197// Default constructor
198template <class Item>
200{
201 First();
202}
203
204// Go to first element in list
205template <class Item>
207{
208 Current = List->GetHeader()->GetNext();
209}
210
211// Go to next element in list
212template <class Item>
214{
215 if (!IsDone())
216 Current = Current->GetNext();
217}
218
219// Return FALSE when there are more elements in list and TRUE when there are no more
220template <class Item>
222{
223 return (Current == List->GetTrailer());
224}
225
226// Return current element
227template <class Item>
229{
230 return IsDone()? NULL : (Item) Current->GetElement();
231}
232
233#endif /* __LIST_H */
#define index(s, c)
Definition: various.h:29
virtual VOID First()
Definition: list.h:206
CListNode * Current
Definition: list.h:66
CListIterator(const CList< Item > *list)
Definition: list.h:199
const CList< Item > * List
Definition: list.h:65
virtual VOID Next()
Definition: list.h:213
virtual BOOL IsDone() const
Definition: list.h:221
virtual Item CurrentItem() const
Definition: list.h:228
Definition: list.h:12
CListNode * GetPrev()
Definition: list.cpp:91
CListNode(VOID *element, CListNode *next, CListNode *prev)
VOID SetNext(CListNode *next)
Definition: list.cpp:67
CListNode * Prev
Definition: list.h:29
static HANDLE hHeap
Definition: list.h:30
PVOID Element
Definition: list.h:27
CListNode()
Definition: list.cpp:22
VOID SetElement(PVOID element)
Definition: list.cpp:61
static INT nRef
Definition: list.h:31
VOID SetPrev(CListNode *prev)
Definition: list.cpp:73
~CListNode()
Definition: list.h:16
CListNode * GetNext()
Definition: list.cpp:85
PVOID GetElement()
Definition: list.cpp:79
CListNode * Next
Definition: list.h:28
Definition: list.h:34
CList()
Definition: list.h:73
CListNode * GetHeader() const
Definition: list.h:168
CListNode * Trailer
Definition: list.h:54
CList & operator=(CList &)
CListNode * Search(Item &element) const
Definition: list.h:182
LONG NodeCount
Definition: list.h:52
LONG Count() const
Definition: list.h:100
VOID Insert(Item &element)
Definition: list.h:123
CIterator< Item > * CreateIterator() const
Definition: list.h:93
CListNode * Header
Definition: list.h:53
VOID Remove(Item &element)
Definition: list.h:135
Item & Get(const LONG index) const
Definition: list.h:107
CListNode * GetTrailer() const
Definition: list.h:175
~CList()
Definition: list.h:84
VOID RemoveAll()
Definition: list.h:150
Definition: Header.h:9
Definition: list.h:37
#define NULL
Definition: types.h:112
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble s
Definition: gl.h:2039
GLuint index
Definition: glext.h:6031
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
static unsigned __int64 next
Definition: rand_nt.c:6
int32_t INT
Definition: typedefs.h:58
Definition: dlist.c:348
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550