4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
40 * Double-Double circular linked list
41 * For storing an object is two lists simultaneously
43 class SG_QList : public SG_DList
50 template<typename T> class iterator
56 typedef iterator<T> _myT;
57 iterator(SG_QList& head, SG_QList* current=NULL) : m_head(head) { m_current = (T*)current; }
62 m_current = (T*)m_head.QPeek();
66 m_current = (T*)m_head.QBack();
70 return (m_current == (T*)m_head.Self());
72 bool add_back(T* item)
74 return m_current->QAddBack(item);
82 m_current = (T*)m_current->QPeek();
87 // no check on NULL! make sure you don't try to increment beyond end
88 m_current = (T*)m_current->QBack();
93 SG_QList() : SG_DList()
95 m_fqlink = m_bqlink = this;
97 SG_QList(const SG_QList& other) : SG_DList()
99 m_fqlink = m_bqlink = this;
106 inline bool QEmpty() // Check for empty queue
108 return ( m_fqlink == this );
110 bool QAddBack( SG_QList *item ) // Add to the back
114 item->m_bqlink = m_bqlink;
115 item->m_fqlink = this;
116 m_bqlink->m_fqlink = item;
120 bool QAddFront( SG_QList *item ) // Add to the back
124 item->m_fqlink = m_fqlink;
125 item->m_bqlink = this;
126 m_fqlink->m_bqlink = item;
130 SG_QList *QRemove() // Remove from the front
136 SG_QList* item = m_fqlink;
137 m_fqlink = item->m_fqlink;
138 m_fqlink->m_bqlink = this;
139 item->m_fqlink = item->m_bqlink = item;
142 bool QDelink() // Remove from the middle
146 m_bqlink->m_fqlink = m_fqlink;
147 m_fqlink->m_bqlink = m_bqlink;
148 m_fqlink = m_bqlink = this;
151 inline SG_QList *QPeek() // Look at front without removing
155 inline SG_QList *QBack() // Look at front without removing
161 #ifdef WITH_CXX_GUARDEDALLOC
163 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_QList"); }
164 void operator delete( void *mem ) { MEM_freeN(mem); }