Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_cc / CC_Slist.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /* $XConsortium: CC_Slist.h /main/6 1996/08/21 15:48:46 drk $ */
24 #ifndef __CC_Slist_h
25 #define __CC_Slist_h
26
27 #include "CC_Listbase.h"
28 #include "cc_exceptions.h"
29
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;
37
38
39 template <class T>
40 class CC_Link : private CC_Link_base
41 {
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>;
49
50 private:
51   CC_Link (T *element)
52     : f_element (element)
53     { }
54   
55   T*    f_element;
56 };
57
58    
59 template <class T> class CC_List_Iterator;
60
61 template <class T>
62 class CC_TPtrSlist : public CC_Listbase
63 {
64
65 //template <class T> friend class CC_List_Iterator;
66    friend class CC_List_Iterator<T>;
67
68 protected:
69    CC_Boolean destructed;
70
71 // Inherit public members from CC_Listbase
72 /*
73  * insert
74  * append
75  * prepend
76  * entries
77  * first, last
78  * removeLast, removeFirst
79  */
80
81 public:
82   CC_TPtrSlist(const CC_TPtrSlist<T> &);
83
84   CC_TPtrSlist() { destructed = FALSE; }
85   virtual ~CC_TPtrSlist();
86
87   virtual void clearAndDestroy();
88   virtual void clear();           /* clear only removes item, but not calling
89                                    * individual item's destructor
90                                    */
91
92   void prepend(T* element)
93   { CC_Listbase::prepend (new CC_Link<T> (element)); } 
94
95   void append(T* element) 
96   { CC_Listbase::append (new CC_Link<T> (element)); }
97
98   void insert(T* element)
99   { CC_Listbase::append (new CC_Link<T> (element)); }
100
101   T*  at(size_t pos) const  /* throw boundaryException
102                              * if list size is smaller than pos
103                              */
104   {
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++ ) {
108       if ( !(++iter) ) {
109         throw(CASTCCBEXCEPT ccBoundaryException(0,0,i));
110       }
111     }
112
113     return( iter.key() );
114   }
115
116   T*  removeAt(size_t pos); /* throw boundaryException 
117                              * if list size is smaller than pos 
118                              */
119   T*  removeLast() {
120     CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::removeLast());
121     if ( t ) { 
122       T * ret = t->f_element;
123       delete t;
124       return(ret);
125     }
126     else return(NULL);
127   }
128
129   T*  removeFirst() {
130     CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::removeFirst());
131     if ( t ) { 
132       T *ret = t->f_element;
133       delete t;
134       return (ret);
135     }
136     else return(NULL);
137   }
138
139   T*  first() const
140   { 
141     CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::first());
142     if (t) { return( t->f_element ); }
143     else return(NULL);
144   }
145
146   T*  last() const
147   {
148     CC_Link<T> *t = (CC_Link<T> *)(CC_Listbase::last());
149     if (t) { return( t->f_element ); }
150     else return(NULL);
151   }
152
153   T*  find(const T*) const;
154   T*  find(CC_Boolean (*)(T*, void*), void*) const;
155
156   CC_Boolean contains(const T*) const;
157   T*        remove(const T*);
158
159   operator CC_Listbase *() { return(this); }
160
161   CC_Boolean get_destructed() const
162     { return (destructed); }
163
164   void set_destructed(CC_Boolean what)
165     { destructed = what; }
166
167 };
168
169
170 template <class T>
171 class CC_TPtrSlistIterator : public CC_List_Iterator_base
172 {
173 friend class CC_TPtrSlist<T>;
174
175 /*
176   Inherit all the public/protected member from CC_List_Iterator_base
177   reset;
178   operator++
179   */
180 public:
181
182   CC_TPtrSlistIterator (CC_TPtrSlist<T> &list)
183     : CC_List_Iterator_base ( (CC_Listbase *)&list)
184     { }
185
186   T* key() const
187     { 
188       CC_Link<T> *link_item = (CC_Link<T> *) CC_List_Iterator_base::item();
189       if ( link_item ) {
190         return ( link_item->f_element );
191       }
192       else { 
193         return(NULL);
194       }
195     }
196
197   T *operator()()
198   {
199     if ( ++(*this) ) { return( key() ); }
200     else { return(NULL); }
201   }
202
203
204 };
205
206
207 template <class T>
208 class CC_TValSlist : public CC_Listbase 
209 {
210
211 // inherit entries from CC_Listbase
212
213 public:
214   CC_TValSlist(const CC_TValSlist<T>&);
215
216   CC_TValSlist() {}
217   ~CC_TValSlist();
218   void append( const T &t) {  /* copies the content of t, also
219                                * assumes the copy constructor for type T
220                                * exists
221                                */
222
223     T *new_element = new T( t );
224     CC_Listbase::append(new CC_Link<T>((T *)new_element));
225   }
226
227 };
228   
229 template <class T>
230 class CC_TValSlistIterator:public CC_List_Iterator_base
231 {
232
233   /* inherit public member from CC_List_Iterator_base
234    * Boolean operator++()
235    */
236   
237 public:
238   CC_TValSlistIterator (CC_TValSlist<T> &list)
239     : CC_List_Iterator_base ( (CC_Listbase *)&list)
240   {}
241
242   T key() const; // Throw ccException if link is undefined
243
244 };
245
246
247 #ifdef EXPAND_TEMPLATES
248 #include "CC_Slist.C"
249 #endif
250
251 #endif /* __CC_Slist_h */
252 /* DO NOT ADD ANY LINES AFTER THIS #endif */