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 librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $TOG: CC_Listbase.C /main/4 1998/04/17 11:44:10 mgreess $
25 * $TOG: CC_Listbase.C /main/4 1998/04/17 11:44:10 mgreess $
26 * $TOG: CC_Listbase.C /main/4 1998/04/17 11:44:10 mgreess $
27 * $TOG: CC_Listbase.C /main/4 1998/04/17 11:44:10 mgreess $
29 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
30 * All rights reserved. Unpublished -- rights reserved under
31 * the Copyright Laws of the United States. USE OF A COPYRIGHT
32 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
35 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
36 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
37 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
38 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
41 * RESTRICTED RIGHTS LEGEND
42 * Use, duplication, or disclosure by the Government is subject
43 * to the restrictions as set forth in subparagraph (c)(l)(ii)
44 * of the Rights in Technical Data and Computer Software clause
45 * at DFARS 252.227-7013.
47 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
52 #include "Exceptions.hh"
53 #include "cc_exceptions.h"
54 #include "CC_Listbase.h"
56 // /////////////////////////////////////////////////////////////////
57 // CC_Listbase::insert - append a new link to the end of the list
58 // /////////////////////////////////////////////////////////////////
61 CC_Listbase::insert (CC_Link_base *element)
64 throw(CASTCCEXCEPT ccException());
68 f_tail = f_head = element;
71 f_tail->f_next = element;
72 element->f_prev = f_tail;
80 // /////////////////////////////////////////////////////////////////
81 // CC_Listbase::insert - insert a new link into the list
82 // /////////////////////////////////////////////////////////////////
85 CC_Listbase::prepend (CC_Link_base *element)
89 throw(CASTCCEXCEPT ccException());
96 element->f_next = f_head;
97 f_head->f_prev = element;
108 // /////////////////////////////////////////////////////////////////
109 // CC_Listbase::remove - remove element pointed to by iterator
110 // /////////////////////////////////////////////////////////////////
112 CC_Listbase::remove (CC_List_Iterator_base &iterator)
114 // Make sure the iterator points to this this.
115 if (iterator.f_list != this)
116 throw (CASTCCEXCEPT ccException());
118 // Make sure the iterator is pointing to an element.
119 if (iterator.f_current == NULL)
122 // NOTE: If two iterators are active in the list at the same time
123 // it is possible to blow away an element that another iterator
124 // is pointing at (either previous or current). We could make this
125 // safer by only marking elements as deleted for now, then actually
126 // delete the items when there are no more iterators pointing at it.
127 // 19:41 22-Jul-93 DJB
129 // Link around the link we're removing.
130 if (iterator.f_previous != NULL) {
131 iterator.f_previous->f_next = iterator.f_current->f_next;
132 if ( f_tail != iterator.f_current ) {
133 iterator.f_current->f_next->f_prev = iterator.f_previous;
136 else { // must be at the head
137 f_head = iterator.f_current->f_next;
139 f_head->f_prev = NULL;
143 if (iterator.f_current == f_tail) {
144 f_tail = iterator.f_previous;
146 f_tail->f_next = NULL;
151 // Increment the iterator.
152 CC_Link_base *entry = iterator.f_current;
153 iterator.f_current = iterator.f_current->f_next;
161 CC_Listbase::removeFirst()
165 CC_Link_base *remove_item = f_head;
166 f_head = f_head->f_next;
167 remove_item->f_next = NULL;
170 f_head->f_prev = NULL;
173 if ( f_tail == remove_item ) { /* only one item on the list */
184 //------------------------------------------------------------------
186 CC_Listbase::removeLast()
189 CC_Link_base *remove_item = f_tail;
190 f_tail = f_tail->f_prev;
191 remove_item->f_prev = NULL;
194 f_tail->f_next = NULL;
196 if ( f_head == remove_item ) { // one item left on the list
206 // /////////////////////////////////////////////////////////////////
207 // CC_List_Iterator::CC_List_Iterator - class constructor
208 // /////////////////////////////////////////////////////////////////
210 CC_List_Iterator_base::CC_List_Iterator_base (CC_Listbase *list)
214 throw(CASTCCEXCEPT ccException());
220 // /////////////////////////////////////////////////////////////////
221 // CC_List_Iterator::reset - reset the iterator to the list start
222 // /////////////////////////////////////////////////////////////////
225 CC_List_Iterator_base::reset()
227 f_current = f_previous = NULL;
231 // /////////////////////////////////////////////////////////////////
232 // CC_List_Iterator:: operator ++ - increment the list iterator
233 // /////////////////////////////////////////////////////////////////
236 CC_List_Iterator_base::operator++()
238 if (!f_current) { // havn't touched the first element
239 f_current = f_list->first();
241 if ( f_current ) return ( TRUE );
245 f_previous = f_current;
246 f_current = f_current->f_next;
257 CC_List_Iterator_base::operator--()
263 f_current = f_previous;
265 f_previous = f_previous->f_prev;
268 if ( f_current ) { return(TRUE); }
269 else { return(FALSE); }