2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $XConsortium: OrderList.C /main/6 1996/08/21 15:41:43 drk $
31 // //////////////////////////////////////////////////////////////
33 // //////////////////////////////////////////////////////////////
35 ListEntry::~ListEntry()
39 OrderList::~OrderList()
51 while (f_cursor != NULL) {
53 f_cursor = f_cursor->f_next;
64 OrderList::add(ListEntry *node, AddCode where, bool mvcursor)
73 if (f_cursor == f_tail)
79 if (f_cursor == f_head)
94 if ((mvcursor) || (f_cursor == NULL))
109 int status = OLIST_OK;
112 if ((node == f_head) && (node == f_tail)) {
116 status = OLIST_LAST_REMOVD;
118 else if (node == f_head) {
119 f_head = node->f_next;
120 f_cursor = node->f_next;
121 f_cursor->f_prev = NULL;
122 status = OLIST_HEAD_REMOVD;
124 else if (node == f_tail) {
125 f_tail = node->f_prev;
126 f_cursor = node->f_prev;
127 f_cursor->f_next = NULL;
128 status = OLIST_TAIL_REMOVD;
131 node->f_prev->f_next = node->f_next;
132 node->f_next->f_prev = node->f_prev;
133 f_cursor = node->f_next;
147 // int status = OLIST_OK;
150 if ((node == f_head) && (node == f_tail)) {
154 // status = OLIST_LAST_REMOVD;
156 else if (node == f_head) {
157 f_head = node->f_next;
158 f_cursor = node->f_next;
159 f_cursor->f_prev = NULL;
160 // status = OLIST_HEAD_REMOVD;
162 else if (node == f_tail) {
163 f_tail = node->f_prev;
164 f_cursor = node->f_prev;
165 f_cursor->f_next = NULL;
166 // status = OLIST_TAIL_REMOVD;
169 node->f_prev->f_next = node->f_next;
170 node->f_next->f_prev = node->f_prev;
171 f_cursor = node->f_next;
184 if (f_cursor != NULL)
185 f_cursor = f_cursor->f_next;
193 int status = OLIST_ERROR;
196 if (f_cursor != NULL) {
197 index = f_cursor->f_prev;
209 int status = OLIST_ERROR;
211 if (f_head != NULL) {
221 int status = OLIST_ERROR;
223 if (f_tail != NULL) {
231 OrderList::iterate(bool (*fn)(ListEntry *, void *), void *usr_def)
233 // NOTE: keep this routine in sync with iterate below !
235 bool keep_going = TRUE;
236 ListEntry *entry = NULL;
238 // Iterate from head (arbitrary choice)
240 while ((index != NULL) && (keep_going)) {
241 keep_going = (*fn) (index, usr_def);
245 index = index->f_next;
250 OrderList::iterate(bool (*fn)(OrderList *, ListEntry *, void *), void *usr_def)
252 // NOTE: keep this routine in sync with iterate above
255 bool keep_going = TRUE;
256 ListEntry *entry = NULL;
258 // Iterate from head (arbitrary choice)
260 while ((index != NULL) && (keep_going)) {
261 keep_going = (*fn) (this, index, usr_def);
265 index = index->f_next;
270 // //////////////////////////////////////////////////////////////
272 // //////////////////////////////////////////////////////////////
275 OrderList::insertNew(ListEntry *node)
285 OrderList::insertAfter(ListEntry *node)
287 f_cursor->f_next->f_prev = node;
288 node->f_next = f_cursor->f_next;
289 f_cursor->f_next = node;
290 node->f_prev = f_cursor;
295 OrderList::insertBefore(ListEntry *node)
297 f_cursor->f_prev->f_next = node;
298 node->f_prev = f_cursor->f_prev;
299 f_cursor->f_prev = node;
300 node->f_next = f_cursor;
305 OrderList::insertTail(ListEntry *node)
311 tnode->f_next = node;
312 node->f_prev = tnode;
318 OrderList::insertHead(ListEntry *node)
324 tnode->f_prev = node;
325 node->f_next = tnode;