dtinfo subtree dtinfo
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Support / List_base.hh
1 /*
2  * $TOG: List_base.hh /main/5 1997/12/29 10:27:35 bill $
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 _List_base_hh
29 #define _List_base_hh
30
31 #ifndef NULL
32 #define NULL 0
33 #endif
34
35 // Base classes for List template. 
36
37 class Link_base
38 {
39 friend class List_base;
40 friend class List_Iterator_base;
41 private:
42   Link_base *f_next;
43 };
44
45 class List_Iterator_base;
46
47 class List_base
48 {
49 friend class List_Iterator_base;
50 public:
51   List_base()
52     : f_head (NULL), f_tail (NULL), f_length (0)
53     { }
54
55   void insert (Link_base *);
56   void insert_before (List_Iterator_base &, Link_base *);
57   void insert_after (List_Iterator_base &, Link_base *);
58   void append (Link_base *);
59   Link_base *remove (List_Iterator_base &);
60
61   unsigned int length() const
62     { return (f_length); }
63
64 private:
65   Link_base    *f_head;
66   Link_base    *f_tail;
67   unsigned int  f_length;
68 };
69
70
71 class List_Iterator_base
72 {
73 friend class List_base;
74 protected:
75   List_Iterator_base()
76     : f_current (NULL)
77     { }
78   List_Iterator_base (const List_base *list);
79   // Obtain the current link entry.
80   Link_base *item() const
81     { return (f_current); }
82   // Reset the iterator to the first list element. 
83   void reset();
84   // Reset the iterator to the last list element.
85   void last();
86   // Set the iterator to a new list.
87   void operator= (const List_base *list)
88     { f_list = list; reset(); }
89   // Increment the iterator. 
90   void *operator++();
91   // For testing EOL. 
92   operator void*() const
93     { return (f_current); }
94 #ifndef DEC
95   int operator!=(int i)
96     { return (f_current != (Link_base *)(size_t)i); }
97 #endif
98
99   // For internal List_base usage. 
100   Link_base *previous() const
101     { return (f_previous); }
102   
103 private:
104   const List_base *f_list;
105   Link_base       *f_previous;
106   Link_base       *f_current;
107 };
108
109 #endif /* _List_base_hh */
110 /* DO NOT ADD ANY LINES AFTER THIS #endif */