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
23 // $TOG: CC_Slist.C /main/5 1998/04/17 11:44:28 mgreess $
27 #include "cc_exceptions.h"
30 //-----------------------------------------------------------------------
32 CC_TPtrSlist<T>::CC_TPtrSlist(const CC_TPtrSlist<T>&slist)
36 CC_TPtrSlistIterator<T> slist_iter( *(CC_TPtrSlist<T> *)&slist );
38 while ( slist_iter() ) {
39 insert( slist_iter.key() );
44 //------------------------------------------------------------------
46 T *CC_TPtrSlist<T>::removeAt(size_t pos) {
48 CC_TPtrSlistIterator<T> iter( *this );
49 for( size_t i = 0; i <= pos; i++ ) {
51 throw(CASTCCBEXCEPT ccBoundaryException(0,0,i));
55 T *key_val = iter.key();
56 CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( iter );
63 //------------------------------------------------------------------
65 T *CC_TPtrSlist<T>::find(const T* elem) const
67 CC_TPtrSlistIterator<T> iter( *(CC_TPtrSlist<T> *)this );
70 if ( *(iter.key()) == *elem )
77 //------------------------------------------------------------------
79 T *CC_TPtrSlist<T>::find(CC_Boolean (*testFunc)(T*, void *),
82 CC_TPtrSlistIterator<T> iter( *(CC_TPtrSlist<T> *)this );
84 if ( testFunc( iter.key(), d ) ) {
85 return ( iter.key() );
92 //------------------------------------------------------------------
94 CC_Boolean CC_TPtrSlist<T>::contains(const T *elem) const
96 CC_TPtrSlistIterator<T> iter( *(CC_TPtrSlist<T> *)this );
98 if ( *(iter.key()) == *elem )
105 //------------------------------------------------------------------
107 T *CC_TPtrSlist<T>::remove(const T *elem)
109 CC_TPtrSlistIterator<T> iter( *this );
111 if ( *(iter.key()) == *elem ) {
112 CC_Link<T> *key_rec = (CC_Link<T> *)CC_Listbase::remove( iter );
113 T *ret = key_rec->f_element;
114 delete key_rec; /* since key_rec does not allocate any memory for
115 * f_element, it is ok to delete key_rec
125 //---------------------------------------------------------------------
127 CC_TPtrSlist<T>::~CC_TPtrSlist()
130 CC_TPtrSlistIterator<T> iter(*this);
133 CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
143 //---------------------------------------------------------------------
145 void CC_TPtrSlist<T>::clearAndDestroy()
148 CC_TPtrSlistIterator<T> iter(*this);
151 CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
153 T *temp_elem = elem->f_element;
155 elem->f_element = NULL; // prevent further destruction on the pointer
163 //---------------------------------------------------------------------
165 void CC_TPtrSlist<T>::clear()
167 CC_TPtrSlistIterator<T> iter(*this);
170 CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
180 //---------------------------------------------------------------------
182 CC_TValSlist<T>::CC_TValSlist(const CC_TValSlist<T> &sval_list)
184 CC_TValSlistIterator<T> slist_val_iter( *(CC_TValSlist<T> *)&sval_list );
185 while ( ++slist_val_iter ) {
186 append( slist_val_iter.key() );
190 //---------------------------------------------------------------------
192 CC_TValSlist<T>::~CC_TValSlist()
194 CC_TValSlistIterator<T> iter( *this );
197 CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
199 if ( elem->f_element ) {
200 T *temp_elem = elem->f_element;
212 //---------------------------------------------------------------------
214 T CC_TValSlistIterator<T>::key() const
216 CC_Link<T> *link_item = (CC_Link<T> *) CC_List_Iterator_base::item();
218 return ( *(link_item->f_element) );
221 throw (CASTCCEXCEPT ccException() );
225 #endif /* _CC_Slist_cc */
226 /* DO NOT ADD ANY LINES AFTER THIS #endif */