xref: /386bsd/usr/include/nonstd/gnu/g++/gen/DLList.hP (revision a2142627)
1// This may look like C code, but it is really -*- C++ -*-
2/*
3Copyright (C) 1988 Free Software Foundation
4    written by Doug Lea (dl@rocky.oswego.edu)
5
6This file is part of GNU CC.
7
8GNU CC is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY.  No author or distributor
10accepts responsibility to anyone for the consequences of using it
11or for whether it serves any particular purpose or works at all,
12unless he says so in writing.  Refer to the GNU CC General Public
13License for full details.
14
15Everyone is granted permission to copy, modify and redistribute
16GNU CC, but only under the conditions described in the
17GNU CC General Public License.   A copy of this license is
18supposed to have been given to you along with GNU CC so you
19can know your rights and responsibilities.  It should be in a
20file named COPYING.  Among other things, the copyright notice
21and this notice must be preserved on all copies.
22*/
23
24
25#ifndef _<T>DLList_h
26#ifdef __GNUG__
27#pragma once
28#pragma interface
29#endif
30#define _<T>DLList_h 1
31
32#include <Pix.h>
33#include "<T>.defs.h"
34
35#ifndef _<T>DLListNode_h
36#define _<T>DLListNode_h 1
37
38struct <T>DLListNode
39{
40  <T>DLListNode*         bk;
41  <T>DLListNode*         fd;
42  <T>                    hd;
43                         <T>DLListNode();
44                         <T>DLListNode(<T&> h,
45                                       <T>DLListNode* p = 0,
46                                       <T>DLListNode* n = 0);
47                         ~<T>DLListNode();
48};
49
50#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
51
52inline <T>DLListNode::<T>DLListNode() {}
53
54inline <T>DLListNode::<T>DLListNode(<T&> h, <T>DLListNode* p,
55                                    <T>DLListNode* n)
56  :hd(h), bk(p), fd(n) {}
57
58inline <T>DLListNode::~<T>DLListNode() {}
59
60#endif
61
62typedef <T>DLListNode* <T>DLListNodePtr;
63
64#endif
65
66class <T>DLList
67{
68  friend class          <T>DLListTrav;
69
70  <T>DLListNode*        h;
71
72public:
73                        <T>DLList();
74                        <T>DLList(<T>DLList& a);
75                        ~<T>DLList();
76
77  <T>DLList&            operator = (<T>DLList& a);
78
79  int                   empty();
80  int                   length();
81
82  void                  clear();
83
84  Pix                   prepend(<T&> item);
85  Pix                   append(<T&> item);
86  void                  join(<T>DLList&);
87
88  <T>&                  front();
89  <T>                   remove_front();
90  void                  del_front();
91
92  <T>&                  rear();
93  <T>                   remove_rear();
94  void                  del_rear();
95
96  <T>&                  operator () (Pix p);
97  Pix                   first();
98  Pix                   last();
99  void                  next(Pix& p);
100  void                  prev(Pix& p);
101  int                   owns(Pix p);
102  Pix                   ins_after(Pix p, <T&> item);
103  Pix                   ins_before(Pix p, <T&> item);
104  void                  del(Pix& p, int dir = 1);
105
106  void                  error(const char* msg);
107  int                   OK();
108};
109
110#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
111
112inline <T>DLList::~<T>DLList()
113{
114  clear();
115}
116
117inline <T>DLList::<T>DLList()
118{
119  h = 0;
120}
121
122inline int <T>DLList::empty()
123{
124  return h == 0;
125}
126
127
128inline void <T>DLList::next(Pix& p)
129{
130  p = (p == 0 || p == h->bk)? 0 : Pix(((<T>DLListNode*)p)->fd);
131}
132
133inline void <T>DLList::prev(Pix& p)
134{
135  p = (p == 0 || p == h)? 0 : Pix(((<T>DLListNode*)p)->bk);
136}
137
138inline Pix <T>DLList::first()
139{
140  return Pix(h);
141}
142
143inline Pix <T>DLList::last()
144{
145  return (h == 0)? 0 : Pix(h->bk);
146}
147
148inline <T>& <T>DLList::operator () (Pix p)
149{
150  if (p == 0) error("null Pix");
151  return ((<T>DLListNode*)p)->hd;
152}
153
154inline <T>& <T>DLList::front()
155{
156  if (h == 0) error("front: empty list");
157  return h->hd;
158}
159
160inline <T>& <T>DLList::rear()
161{
162  if (h == 0) error("rear: empty list");
163  return h->bk->hd;
164}
165
166
167
168
169#endif
170#endif
171