xref: /386bsd/usr/include/nonstd/gnu/g++/gen/XPlex.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    based on code by Marc Shapiro (shapiro@sor.inria.fr)
6
7This file is part of GNU CC.
8
9GNU CC is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY.  No author or distributor
11accepts responsibility to anyone for the consequences of using it
12or for whether it serves any particular purpose or works at all,
13unless he says so in writing.  Refer to the GNU CC General Public
14License for full details.
15
16Everyone is granted permission to copy, modify and redistribute
17GNU CC, but only under the conditions described in the
18GNU CC General Public License.   A copy of this license is
19supposed to have been given to you along with GNU CC so you
20can know your rights and responsibilities.  It should be in a
21file named COPYING.  Among other things, the copyright notice
22and this notice must be preserved on all copies.
23*/
24
25#ifndef _<T>XPlex_h
26#ifdef __GNUG__
27#pragma once
28#pragma interface
29#endif
30#define _<T>XPlex_h 1
31
32#include "<T>.Plex.h"
33
34class <T>XPlex: public <T>Plex
35{
36  <T>IChunk*       ch;           // cached chunk
37
38  void             make_initial_chunks(int up = 1);
39
40  void             cache(int idx) const;
41  void             cache(const <T>* p) const;
42
43  <T>*             dopred(const <T>* p) const;
44  <T>*             dosucc(const <T>* p) const;
45
46  void             set_cache(const <T>IChunk* t) const; // logically,
47                                               // not physically const
48public:
49                   <T>XPlex();                 // set low = 0;
50                                               // fence = 0;
51                                               // csize = default
52
53                   <T>XPlex(int ch_size);      // low = 0;
54                                               // fence = 0;
55                                               // csize = ch_size
56
57                   <T>XPlex(int lo,            // low = lo;
58                            int ch_size);      // fence=lo
59                                               // csize = ch_size
60
61                   <T>XPlex(int lo,            // low = lo
62                            int hi,            // fence = hi+1
63                            const <T&> initval,// fill with initval,
64                            int ch_size = 0);  // csize= ch_size
65                                               // or fence-lo if 0
66
67                   <T>XPlex(const <T>XPlex&);
68
69  void             operator= (const <T>XPlex&);
70
71// virtuals
72
73
74  <T>&             high_element ();
75  <T>&             low_element ();
76
77  const <T>&       high_element () const;
78  const <T>&       low_element () const;
79
80  Pix              first() const;
81  Pix              last() const;
82  void             prev(Pix& ptr) const;
83  void             next(Pix& ptr) const;
84  int              owns(Pix p) const;
85  <T>&             operator () (Pix p);
86  const <T>&       operator () (Pix p) const;
87
88  int              low() const;
89  int              high() const;
90  int              valid(int idx) const;
91  void             prev(int& idx) const;
92  void             next(int& x) const;
93  <T>&             operator [] (int index);
94  const <T>&       operator [] (int index) const;
95
96  int              Pix_to_index(Pix p) const;
97  Pix              index_to_Pix(int idx) const;
98
99  int              can_add_high() const;
100  int              can_add_low() const;
101  int              full() const;
102
103  int              add_high(const <T&> elem);
104  int              del_high ();
105  int              add_low (const <T&> elem);
106  int              del_low ();
107
108  void             fill(const <T&> x);
109  void             fill(const <T&> x, int from, int to);
110  void             clear();
111  void             reverse();
112  void             append(const <T>XPlex& a);
113  void             prepend(const <T>XPlex& a);
114
115  int              OK () const;
116
117};
118
119#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
120
121inline void <T>XPlex::prev(int& idx) const
122{
123  --idx;
124}
125
126inline void <T>XPlex::next(int& idx) const
127{
128  ++idx;
129}
130
131inline  int <T>XPlex::full () const
132{
133  return 0;
134}
135
136inline int <T>XPlex::can_add_high() const
137{
138  return 1;
139}
140
141inline int <T>XPlex::can_add_low() const
142{
143  return 1;
144}
145
146inline  int <T>XPlex::valid (int idx) const
147{
148  return idx >= lo && idx < fnc;
149}
150
151inline int <T>XPlex::low() const
152{
153  return lo;
154}
155
156inline int <T>XPlex::high() const
157{
158  return fnc - 1;
159}
160
161inline <T>& <T>XPlex:: operator [] (int idx)
162{
163  if (!ch->actual_index(idx)) cache(idx);
164  return *(ch->pointer_to(idx));
165}
166
167inline const <T>& <T>XPlex:: operator [] (int idx) const
168{
169  if (!ch->actual_index(idx)) cache(idx);
170  return *((const <T>*)(ch->pointer_to(idx)));
171}
172
173inline  <T>& <T>XPlex::low_element ()
174{
175  if (empty()) index_error();
176  return *(hd->pointer_to(lo));
177}
178
179inline  const <T>& <T>XPlex::low_element () const
180{
181  if (empty()) index_error();
182  return *((const <T>*)(hd->pointer_to(lo)));
183}
184
185inline  <T>& <T>XPlex::high_element ()
186{
187  if (empty()) index_error();
188  return *(tl()->pointer_to(fnc - 1));
189}
190
191inline const <T>& <T>XPlex::high_element () const
192{
193  if (empty()) index_error();
194  return *((const <T>*)(tl()->pointer_to(fnc - 1)));
195}
196
197inline  int <T>XPlex::Pix_to_index(Pix px) const
198{
199  <T>* p = (<T>*)px;
200  if (!ch->actual_pointer(p)) cache(p);
201  return ch->index_of(p);
202}
203
204inline  Pix <T>XPlex::index_to_Pix(int idx) const
205{
206  if (!ch->actual_index(idx)) cache(idx);
207  return (Pix)(ch->pointer_to(idx));
208}
209
210inline Pix <T>XPlex::first() const
211{
212  return Pix(hd-><T>IChunk::first_pointer());
213}
214
215inline Pix <T>XPlex::last() const
216{
217  return Pix(tl()-><T>IChunk::last_pointer());
218}
219
220inline void <T>XPlex::prev(Pix& p) const
221{
222  Pix q = Pix(ch-><T>IChunk::pred((<T>*) p));
223  p = (q == 0)? Pix(dopred((const <T>*) p)) : q;
224}
225
226inline void <T>XPlex::next(Pix& p) const
227{
228  Pix q = Pix(ch-><T>IChunk::succ((<T>*) p));
229  p = (q == 0)? Pix(dosucc((const <T>*)p)) : q;
230}
231
232inline <T>& <T>XPlex:: operator () (Pix p)
233{
234  return *((<T>*)p);
235}
236
237inline const <T>& <T>XPlex:: operator () (Pix p) const
238{
239  return *((const <T>*)p);
240}
241
242inline void <T>XPlex::set_cache(const <T>IChunk* t) const
243{
244  ((<T>XPlex*)(this))->ch = (<T>IChunk*)t;
245}
246
247#endif
248#endif
249