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