42e5b04d37589a861481e035d357bd8421871b7c
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Support / xList.hh
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 libraries 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 /*
24  * $TOG: xList.hh /main/14 1998/04/17 11:40:11 mgreess $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50 #ifndef _xList_hh
51 #define _xList_hh
52
53 #include "List_base.hh"
54
55 template <class T> class xList;
56 template <class T> class List_Iterator;
57
58
59 template <class T>
60 class Link : private Link_base
61 {
62 friend class xList<T>;
63 friend class List_Iterator<T>;
64
65 private:
66   Link (const T &element)
67     : f_element (element)
68     { }
69   
70   T     f_element;
71 };
72
73 template <class T>
74 #if defined(__uxp__) || defined(_IBMR2) || defined(__osf__) || \
75     defined(USL) || defined(linux) || defined(CSRG_BASED) || defined(sun)
76 class xList : public List_base
77 #else
78 class xList : private List_base
79 #endif
80 {
81 // NOTE: This friend declaration is too general because cfront
82 // barfs when I do it the correct way.  22:05 22-Jul-93 DJB
83 #ifdef SC3
84 friend class List_Iterator<T>;
85 #else
86 #if !defined(_IBMR2) && !defined(__osf__) && !defined(USL) && \
87     !defined(linux) && !defined(CSRG_BASED) && !defined(sun)
88 template <class T> friend class List_Iterator;
89 #endif
90 #endif
91 public:
92   xList() { } 
93   ~xList();
94
95   void insert (const T &element)
96     { List_base::insert (new Link<T> (element)); }
97
98   void insert_before (List_Iterator<T> &iterator, const T &element);
99
100   void insert_after (List_Iterator<T> &iterator, const T &element);
101
102   void append (const T &element);
103
104   // Element must have an operator == that works. 
105   void remove (T &element);
106
107   void remove (List_Iterator<T> &iterator);
108
109
110   unsigned int length() const
111     { return (List_base::length()); }
112
113   // Another hack.  CC gets a bus error if we pass a reference to
114   // to List_Iter constructor.  So we add an automatic conversion
115   // here to avoid the hassle of taking the address of a List.
116   operator const xList<T> *() const
117     { return (this); }
118
119 };
120
121
122 template <class T>
123 #if defined(_IBMR2) || defined(__osf__) || defined(linux) || \
124     defined(CSRG_BASED) || defined(sun)
125 class List_Iterator : public List_Iterator_base
126 #else
127 class List_Iterator : private List_Iterator_base
128 #endif
129 {
130 friend class xList<T>;
131 public:
132   List_Iterator()
133     { }
134
135   List_Iterator (const xList<T> *list)
136     : List_Iterator_base (list)
137     { }
138
139   void reset()
140     { List_Iterator_base::reset(); }
141
142   void last()
143     { List_Iterator_base::last(); }
144
145   void operator= (const xList<T> *list)
146     { List_Iterator_base::operator= (list); }
147
148 #ifndef DEC
149   int operator!= (int i)
150     { return (List_Iterator_base::operator!= (i)); }
151 #endif
152
153   T& item() const
154     { return (((Link<T> *) List_Iterator_base::item())->f_element); }
155
156   void *operator++ ()
157     { return (List_Iterator_base::operator++ ()); }
158
159   void *operator++ (int)
160     { return (List_Iterator_base::operator++ ()); }
161
162   operator void *() const
163     { return (List_Iterator_base::operator void *()); }
164 };
165
166 #ifdef EXPAND_TEMPLATES
167 #include "xList.C"
168 #endif
169
170 #endif /* _xList_hh */
171 /* DO NOT ADD ANY LINES AFTER THIS #endif */