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 /* $XConsortium: CC_Slist.h /main/6 1996/08/21 15:48:46 drk $ */
27 #include "CC_Listbase.h"
28 #include "cc_exceptions.h"
30 template <class T> class CC_TPtrSlist;
31 template <class T> class CC_TPtrSlistIterator;
32 template <class T> class CC_TPtrDlist;
33 template <class T> class CC_TPtrDlistIterator;
34 template <class T> class CC_TValSlist;
35 template <class T> class CC_TValSlistIterator;
36 template <class T> class Stack;
40 class CC_Link : private CC_Link_base
42 friend class CC_TPtrSlist<T>;
43 friend class CC_TPtrSlistIterator<T>;
44 friend class CC_TPtrDlist<T>;
45 friend class CC_TPtrDlistIterator<T>;
46 friend class CC_TValSlist<T>;
47 friend class CC_TValSlistIterator<T>;
48 friend class Stack<T>;
59 template <class T> class CC_List_Iterator;
62 class CC_TPtrSlist : public CC_Listbase
65 //template <class T> friend class CC_List_Iterator;
66 friend class CC_List_Iterator<T>;
69 CC_Boolean destructed;
71 // Inherit public members from CC_Listbase
78 * removeLast, removeFirst
82 CC_TPtrSlist(const CC_TPtrSlist<T> &);
84 CC_TPtrSlist() { destructed = FALSE; }
85 virtual ~CC_TPtrSlist();
87 virtual void clearAndDestroy();
88 virtual void clear(); /* clear only removes item, but not calling
89 * individual item's destructor
92 void prepend(T* element)
93 { CC_Listbase::prepend (new CC_Link<T> (element)); }
95 void append(T* element)
96 { CC_Listbase::append (new CC_Link<T> (element)); }
98 void insert(T* element)
99 { CC_Listbase::append (new CC_Link<T> (element)); }
101 T* at(size_t pos) const /* throw boundaryException
102 * if list size is smaller than pos
105 // Hack to get it passed to iter
106 CC_TPtrSlistIterator<T> iter( *(CC_TPtrSlist<T> *)this );
107 for ( size_t i = 0; i <=pos; i++ ) {
109 throw(CASTCCBEXCEPT ccBoundaryException(0,0,i));
113 return( iter.key() );
116 T* removeAt(size_t pos); /* throw boundaryException
117 * if list size is smaller than pos
120 CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::removeLast());
122 T * ret = t->f_element;
130 CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::removeFirst());
132 T *ret = t->f_element;
141 CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::first());
142 if (t) { return( t->f_element ); }
148 CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::last());
149 if (t) { return( t->f_element ); }
153 T* find(const T*) const;
154 T* find(CC_Boolean (*)(T*, void*), void*) const;
156 CC_Boolean contains(const T*) const;
159 operator CC_Listbase *() { return(this); }
161 CC_Boolean get_destructed() const
162 { return (destructed); }
164 void set_destructed(CC_Boolean what)
165 { destructed = what; }
171 class CC_TPtrSlistIterator : public CC_List_Iterator_base
173 friend class CC_TPtrSlist<T>;
176 Inherit all the public/protected member from CC_List_Iterator_base
182 CC_TPtrSlistIterator (CC_TPtrSlist<T> &list)
183 : CC_List_Iterator_base ( (CC_Listbase *)&list)
188 CC_Link<T> *link_item = (CC_Link<T> *) CC_List_Iterator_base::item();
190 return ( link_item->f_element );
199 if ( ++(*this) ) { return( key() ); }
200 else { return(NULL); }
208 class CC_TValSlist : public CC_Listbase
211 // inherit entries from CC_Listbase
214 CC_TValSlist(const CC_TValSlist<T>&);
218 void append( const T &t) { /* copies the content of t, also
219 * assumes the copy constructor for type T
223 T *new_element = new T( t );
224 CC_Listbase::append(new CC_Link<T>((T *)new_element));
230 class CC_TValSlistIterator:public CC_List_Iterator_base
233 /* inherit public member from CC_List_Iterator_base
234 * Boolean operator++()
238 CC_TValSlistIterator (CC_TValSlist<T> &list)
239 : CC_List_Iterator_base ( (CC_Listbase *)&list)
242 T key() const; // Throw ccException if link is undefined
247 #ifdef EXPAND_TEMPLATES
248 #include "CC_Slist.C"
251 #endif /* __CC_Slist_h */
252 /* DO NOT ADD ANY LINES AFTER THIS #endif */