Fixed outputname null pointer crash in sdktools (
bug 4422, r=fyren)
3 * =============================================================================
5 * Copyright (C) 2004-2008 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_SOURCEMOD_FASTLINK_H_
33 #define _INCLUDE_SOURCEMOD_FASTLINK_H_
40 friend class iterator;
46 unsigned int freeNode;
50 FastLink(unsigned int maxsize) : m_Size(0), m_FirstLink(0), m_FreeNodes(0), m_LastLink(0), m_UsableIndex(0)
53 m_Nodes = new FastLinkNode[m_MaxSize+1];
56 bool push_back(const T & obj)
58 unsigned int new_node = GetFreeIndex();
63 m_Nodes[new_node].obj = obj;
64 m_Nodes[new_node].next = 0;
67 m_Nodes[new_node].prev = 0;
68 m_FirstLink = new_node;
69 m_LastLink = new_node;
71 m_Nodes[new_node].prev = m_LastLink;
72 m_Nodes[m_LastLink].next = new_node;
73 m_LastLink = new_node;
83 unsigned int GetFreeIndex()
87 return m_Nodes[m_FreeNodes--].freeNode;
89 if (m_UsableIndex >= m_MaxSize)
100 friend class FastLink;
107 iterator(const FastLink *_link, unsigned int _position)
110 position = _position;
113 bool operator ==(const iterator &where) const
115 return (link == where.link && position == where.position);
117 bool operator !=(const iterator &where) const
119 return (link != where.link || position != where.position);
123 return link->m_Nodes[position].obj;
125 const T & operator *() const
127 return link->m_Nodes[position].obj;
129 iterator & operator++()
131 position = link->m_Nodes[position].next;
135 const FastLink *link;
136 unsigned int position;
139 iterator begin() const
141 return iterator(this, m_FirstLink);
145 return iterator(this, 0);
147 void remove(const T & obj)
149 for (iterator iter=begin(); iter!=end(); ++iter)
158 iterator erase(const iterator &where)
160 /* Whoa, this better be right! */
161 assert(where.link == this);
163 iterator iter(where.link, where.position);
166 unsigned int index = where.position;
168 /* Each case is different, we have no sentinel.
169 * CASE: We're the HEAD AND the TAIL */
170 if (index == m_FirstLink
171 && index == m_LastLink)
177 else if (index == m_FirstLink)
179 m_FirstLink = m_Nodes[index].next;
180 m_Nodes[m_FirstLink].prev = 0;
183 else if (index == m_LastLink)
185 m_LastLink = m_Nodes[index].prev;
186 m_Nodes[m_LastLink].next = 0;
188 /* We're in the middle! */
191 /* Patch forward reference */
192 m_Nodes[m_Nodes[index].next].prev = m_Nodes[index].prev;
193 /* Patch backward reference */
194 m_Nodes[m_Nodes[index].prev].next = m_Nodes[index].next;
197 /* Add us to the free list */
198 m_Nodes[++m_FreeNodes].freeNode = index;
204 #if defined MENU_DEBUG
210 unsigned int m_FirstLink;
211 unsigned int m_FreeNodes;
212 unsigned int m_LastLink;
213 unsigned int m_MaxSize;
214 unsigned int m_UsableIndex;
215 FastLinkNode *m_Nodes;
218 #endif //_INCLUDE_SOURCEMOD_FASTLINK_H_