Oh GACK! src-clean doesn't quite work that easily since cleandist rebuilds the
[unix-history] / gnu / lib / libg++ / g++-include / gen / XPlex.hP
CommitLineData
e87b4ac1
PR
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 the GNU C++ Library. This library is free
8software; you can redistribute it and/or modify it under the terms of
9the GNU Library General Public License as published by the Free
10Software Foundation; either version 2 of the License, or (at your
11option) any later version. This library is distributed in the hope
12that it will be useful, but WITHOUT ANY WARRANTY; without even the
13implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14PURPOSE. See the GNU Library General Public License for more details.
15You should have received a copy of the GNU Library General Public
16License along with this library; if not, write to the Free Software
17Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#ifndef _<T>XPlex_h
21#ifdef __GNUG__
22#pragma interface
23#endif
24#define _<T>XPlex_h 1
25
26#include "<T>.Plex.h"
27
28class <T>XPlex: public <T>Plex
29{
30 <T>IChunk* ch; // cached chunk
31
32 void make_initial_chunks(int up = 1);
33
34 void cache(int idx) const;
35 void cache(const <T>* p) const;
36
37 <T>* dopred(const <T>* p) const;
38 <T>* dosucc(const <T>* p) const;
39
40 void set_cache(const <T>IChunk* t) const; // logically,
41 // not physically const
42public:
43 <T>XPlex(); // set low = 0;
44 // fence = 0;
45 // csize = default
46
47 <T>XPlex(int ch_size); // low = 0;
48 // fence = 0;
49 // csize = ch_size
50
51 <T>XPlex(int lo, // low = lo;
52 int ch_size); // fence=lo
53 // csize = ch_size
54
55 <T>XPlex(int lo, // low = lo
56 int hi, // fence = hi+1
57 const <T&> initval,// fill with initval,
58 int ch_size = 0); // csize= ch_size
59 // or fence-lo if 0
60
61 <T>XPlex(const <T>XPlex&);
62
63 void operator= (const <T>XPlex&);
64
65// virtuals
66
67
68 <T>& high_element ();
69 <T>& low_element ();
70
71 const <T>& high_element () const;
72 const <T>& low_element () const;
73
74 Pix first() const;
75 Pix last() const;
76 void prev(Pix& ptr) const;
77 void next(Pix& ptr) const;
78 int owns(Pix p) const;
79 <T>& operator () (Pix p);
80 const <T>& operator () (Pix p) const;
81
82 int low() const;
83 int high() const;
84 int valid(int idx) const;
85 void prev(int& idx) const;
86 void next(int& x) const;
87 <T>& operator [] (int index);
88 const <T>& operator [] (int index) const;
89
90 int Pix_to_index(Pix p) const;
91 Pix index_to_Pix(int idx) const;
92
93 int can_add_high() const;
94 int can_add_low() const;
95 int full() const;
96
97 int add_high(const <T&> elem);
98 int del_high ();
99 int add_low (const <T&> elem);
100 int del_low ();
101
102 void fill(const <T&> x);
103 void fill(const <T&> x, int from, int to);
104 void clear();
105 void reverse();
106
107 int OK () const;
108
109};
110
111
112inline void <T>XPlex::prev(int& idx) const
113{
114 --idx;
115}
116
117inline void <T>XPlex::next(int& idx) const
118{
119 ++idx;
120}
121
122inline int <T>XPlex::full () const
123{
124 return 0;
125}
126
127inline int <T>XPlex::can_add_high() const
128{
129 return 1;
130}
131
132inline int <T>XPlex::can_add_low() const
133{
134 return 1;
135}
136
137inline int <T>XPlex::valid (int idx) const
138{
139 return idx >= lo && idx < fnc;
140}
141
142inline int <T>XPlex::low() const
143{
144 return lo;
145}
146
147inline int <T>XPlex::high() const
148{
149 return fnc - 1;
150}
151
152inline <T>& <T>XPlex:: operator [] (int idx)
153{
154 if (!ch->actual_index(idx)) cache(idx);
155 return *(ch->pointer_to(idx));
156}
157
158inline const <T>& <T>XPlex:: operator [] (int idx) const
159{
160 if (!ch->actual_index(idx)) cache(idx);
161 return *((const <T>*)(ch->pointer_to(idx)));
162}
163
164inline <T>& <T>XPlex::low_element ()
165{
166 if (empty()) index_error();
167 return *(hd->pointer_to(lo));
168}
169
170inline const <T>& <T>XPlex::low_element () const
171{
172 if (empty()) index_error();
173 return *((const <T>*)(hd->pointer_to(lo)));
174}
175
176inline <T>& <T>XPlex::high_element ()
177{
178 if (empty()) index_error();
179 return *(tl()->pointer_to(fnc - 1));
180}
181
182inline const <T>& <T>XPlex::high_element () const
183{
184 if (empty()) index_error();
185 return *((const <T>*)(tl()->pointer_to(fnc - 1)));
186}
187
188inline int <T>XPlex::Pix_to_index(Pix px) const
189{
190 <T>* p = (<T>*)px;
191 if (!ch->actual_pointer(p)) cache(p);
192 return ch->index_of(p);
193}
194
195inline Pix <T>XPlex::index_to_Pix(int idx) const
196{
197 if (!ch->actual_index(idx)) cache(idx);
198 return (Pix)(ch->pointer_to(idx));
199}
200
201inline Pix <T>XPlex::first() const
202{
203 return Pix(hd-><T>IChunk::first_pointer());
204}
205
206inline Pix <T>XPlex::last() const
207{
208 return Pix(tl()-><T>IChunk::last_pointer());
209}
210
211inline void <T>XPlex::prev(Pix& p) const
212{
213 Pix q = Pix(ch-><T>IChunk::pred((<T>*) p));
214 p = (q == 0)? Pix(dopred((const <T>*) p)) : q;
215}
216
217inline void <T>XPlex::next(Pix& p) const
218{
219 Pix q = Pix(ch-><T>IChunk::succ((<T>*) p));
220 p = (q == 0)? Pix(dosucc((const <T>*)p)) : q;
221}
222
223inline <T>& <T>XPlex:: operator () (Pix p)
224{
225 return *((<T>*)p);
226}
227
228inline const <T>& <T>XPlex:: operator () (Pix p) const
229{
230 return *((const <T>*)p);
231}
232
233inline void <T>XPlex::set_cache(const <T>IChunk* t) const
234{
235 ((<T>XPlex*)(this))->ch = (<T>IChunk*)t;
236}
237
238#endif