Don't omit frame pointer on msvc builds.
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_
45 unsigned int freeNode;
49 FastLink(unsigned int maxsize) : m_Size(0), m_FirstLink(0), m_FreeNodes(0), m_LastLink(0), m_UsableIndex(0)
52 m_Nodes = new FastLinkNode[m_MaxSize+1];
55 bool push_back(const T & obj)
57 unsigned int new_node = GetFreeIndex();
62 m_Nodes[new_node].obj = obj;
63 m_Nodes[new_node].next = 0;
66 m_Nodes[new_node].prev = 0;
67 m_FirstLink = new_node;
68 m_LastLink = new_node;
70 m_Nodes[new_node].prev = m_LastLink;
71 m_Nodes[m_LastLink].next = new_node;
72 m_LastLink = new_node;
82 unsigned int GetFreeIndex()
86 return m_Nodes[m_FreeNodes--].freeNode;
88 if (m_UsableIndex >= m_MaxSize)
99 friend class FastLink;
106 iterator(const FastLink *_link, unsigned int _position)
109 position = _position;
112 bool operator ==(const iterator &where) const
114 return (link == where.link && position == where.position);
116 bool operator !=(const iterator &where) const
118 return (link != where.link || position != where.position);
122 return link->m_Nodes[position].obj;
124 const T & operator *() const
126 return link->m_Nodes[position].obj;
128 iterator & operator++()
130 position = link->m_Nodes[position].next;
134 const FastLink *link;
135 unsigned int position;
138 iterator begin() const
140 return iterator(this, m_FirstLink);
144 return iterator(this, 0);
146 void remove(const T & obj)
148 for (iterator iter=begin(); iter!=end(); ++iter)
157 iterator erase(const iterator &where)
159 /* Whoa, this better be right! */
160 assert(where.link == this);
162 iterator iter(where.link, where.position);
165 unsigned int index = where.position;
167 /* Each case is different, we have no sentinel.
168 * CASE: We're the HEAD AND the TAIL */
169 if (index == m_FirstLink
170 && index == m_LastLink)
176 else if (index == m_FirstLink)
178 m_FirstLink = m_Nodes[index].next;
179 m_Nodes[m_FirstLink].prev = 0;
182 else if (index == m_LastLink)
184 m_LastLink = m_Nodes[index].prev;
185 m_Nodes[m_LastLink].next = 0;
187 /* We're in the middle! */
190 /* Patch forward reference */
191 m_Nodes[m_Nodes[index].next].prev = m_Nodes[index].prev;
192 /* Patch backward reference */
193 m_Nodes[m_Nodes[index].prev].next = m_Nodes[index].next;
196 /* Add us to the free list */
197 m_Nodes[++m_FreeNodes].freeNode = index;
203 #if defined MENU_DEBUG
209 unsigned int m_FirstLink;
210 unsigned int m_FreeNodes;
211 unsigned int m_LastLink;
212 unsigned int m_MaxSize;
213 unsigned int m_UsableIndex;
214 FastLinkNode *m_Nodes;
217 #endif //_INCLUDE_SOURCEMOD_FASTLINK_H_