added sourcemod's VDF file. yay
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SM_QUEUE_H
33 #define _INCLUDE_SM_QUEUE_H
39 using namespace SourceHook;
42 A circular, doubly-linked List with one sentinel node
46 m_Head->next = m_Head;
47 m_Head->prev = m_Head;
68 friend class iterator;
77 // Initializes the sentinel node.
78 QueueNode *_Initialize()
80 QueueNode *n = (QueueNode *)malloc(sizeof(QueueNode));
86 Queue() : m_Head(_Initialize()), m_Size(0)
90 Queue(const Queue &src) : m_Head(_Initialize()), m_Size(0)
93 for (iter=src.begin(); iter!=src.end(); iter++)
103 // Don't forget to free the sentinel
110 while (!m_FreeNodes.empty())
112 free(m_FreeNodes.front());
117 void push(const T &obj)
121 if (m_FreeNodes.empty())
123 node = (QueueNode *)malloc(sizeof(QueueNode));
125 node = m_FreeNodes.front();
129 /* Copy the object */
130 new (&node->obj) T(obj);
132 /* Install into the Queue */
133 node->prev = m_Head->prev;
135 m_Head->prev->next = node;
148 QueueNode *node = m_Head->next;
150 m_Head->next = m_Head;
151 m_Head->prev = m_Head;
153 // Iterate through the nodes until we find g_Head (the sentinel) again
154 while (node != m_Head)
158 m_FreeNodes.push(node);
166 return (m_Size == 0);
172 CStack<QueueNode *> m_FreeNodes;
182 iterator(const Queue &src)
186 iterator(QueueNode *n) : m_This(n)
189 iterator(const iterator &where)
191 m_This = where.m_This;
194 iterator & operator--()
197 m_This = m_This->prev;
201 iterator operator--(int)
205 m_This = m_This->prev;
210 iterator & operator++()
213 m_This = m_This->next;
217 iterator operator++(int)
221 m_This = m_This->next;
225 const T & operator * () const
236 return &(m_This->obj);
238 const T * operator -> () const
240 return &(m_This->obj);
243 bool operator != (const iterator &where) const
245 return (m_This != where.m_This);
247 bool operator ==(const iterator &where) const
249 return (m_This == where.m_This);
255 iterator begin() const
257 return iterator(m_Head->next);
262 return iterator(m_Head);
265 iterator erase(iterator &where)
267 QueueNode *pNode = where.m_This;
268 iterator iter(where);
272 // Works for all cases: empty Queue, erasing first element, erasing tail, erasing in the middle...
273 pNode->prev->next = pNode->next;
274 pNode->next->prev = pNode->prev;
277 m_FreeNodes.push(pNode);
283 void remove(const T & obj)
286 for (b=begin(); b!=end(); b++)
295 template <typename U>
296 iterator find(const U & equ) const
299 for (iter=begin(); iter!=end(); iter++)
301 if ( (*iter) == equ )
308 Queue & operator =(const Queue &src)
312 for (iter=src.begin(); iter!=src.end(); iter++)
314 push_back( (*iter) );
321 iterator i = begin();
328 iterator iter = begin();
333 #endif //_INCLUDE_SM_QUEUE_H