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 $
34 // //////////////////////////////////////////////////////////////
36 // //////////////////////////////////////////////////////////////
38 ListEntry::~ListEntry()
42 OrderList::~OrderList()
54 while (f_cursor != NULL) {
56 f_cursor = f_cursor->f_next;
67 OrderList::add(ListEntry *node, AddCode where, bool mvcursor)
76 if (f_cursor == f_tail)
82 if (f_cursor == f_head)
97 if ((mvcursor) || (f_cursor == NULL))
112 int status = OLIST_OK;
115 if ((node == f_head) && (node == f_tail)) {
119 status = OLIST_LAST_REMOVD;
121 else if (node == f_head) {
122 f_head = node->f_next;
123 f_cursor = node->f_next;
124 f_cursor->f_prev = NULL;
125 status = OLIST_HEAD_REMOVD;
127 else if (node == f_tail) {
128 f_tail = node->f_prev;
129 f_cursor = node->f_prev;
130 f_cursor->f_next = NULL;
131 status = OLIST_TAIL_REMOVD;
134 node->f_prev->f_next = node->f_next;
135 node->f_next->f_prev = node->f_prev;
136 f_cursor = node->f_next;
150 // int status = OLIST_OK;
153 if ((node == f_head) && (node == f_tail)) {
157 // status = OLIST_LAST_REMOVD;
159 else if (node == f_head) {
160 f_head = node->f_next;
161 f_cursor = node->f_next;
162 f_cursor->f_prev = NULL;
163 // status = OLIST_HEAD_REMOVD;
165 else if (node == f_tail) {
166 f_tail = node->f_prev;
167 f_cursor = node->f_prev;
168 f_cursor->f_next = NULL;
169 // status = OLIST_TAIL_REMOVD;
172 node->f_prev->f_next = node->f_next;
173 node->f_next->f_prev = node->f_prev;
174 f_cursor = node->f_next;
187 if (f_cursor != NULL)
188 f_cursor = f_cursor->f_next;
196 int status = OLIST_ERROR;
199 if (f_cursor != NULL) {
200 index = f_cursor->f_prev;
212 int status = OLIST_ERROR;
214 if (f_head != NULL) {
224 int status = OLIST_ERROR;
226 if (f_tail != NULL) {
234 OrderList::iterate(bool (*fn)(ListEntry *, void *), void *usr_def)
236 // NOTE: keep this routine in sync with iterate below !
238 bool keep_going = TRUE;
239 ListEntry *entry = NULL;
241 // Iterate from head (arbitrary choice)
243 while ((index != NULL) && (keep_going)) {
244 keep_going = (*fn) (index, usr_def);
248 index = index->f_next;
253 OrderList::iterate(bool (*fn)(OrderList *, ListEntry *, void *), void *usr_def)
255 // NOTE: keep this routine in sync with iterate above
258 bool keep_going = TRUE;
259 ListEntry *entry = NULL;
261 // Iterate from head (arbitrary choice)
263 while ((index != NULL) && (keep_going)) {
264 keep_going = (*fn) (this, index, usr_def);
268 index = index->f_next;
273 // //////////////////////////////////////////////////////////////
275 // //////////////////////////////////////////////////////////////
278 OrderList::insertNew(ListEntry *node)
288 OrderList::insertAfter(ListEntry *node)
290 f_cursor->f_next->f_prev = node;
291 node->f_next = f_cursor->f_next;
292 f_cursor->f_next = node;
293 node->f_prev = f_cursor;
298 OrderList::insertBefore(ListEntry *node)
300 f_cursor->f_prev->f_next = node;
301 node->f_prev = f_cursor->f_prev;
302 f_cursor->f_prev = node;
303 node->f_next = f_cursor;
308 OrderList::insertTail(ListEntry *node)
314 tnode->f_next = node;
315 node->f_prev = tnode;
321 OrderList::insertHead(ListEntry *node)
327 tnode->f_prev = node;
328 node->f_next = tnode;