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>FPlex_h 26#ifdef __GNUG__ 27#pragma once 28#pragma interface 29#endif 30#define _<T>FPlex_h 1 31 32#include "<T>.Plex.h" 33 34class <T>FPlex : public <T>Plex 35{ 36public: 37 <T>FPlex(); // set low = 0; 38 // fence = 0; 39 // csize = default 40 41 <T>FPlex(int maxsize); // low = 0; 42 // fence = 0; 43 // csize = maxsize 44 45 <T>FPlex(int lo, // low = lo; 46 int maxsize); // fence=lo 47 // csize = maxsize 48 49 <T>FPlex(int lo, // low = lo 50 int hi, // fence = hi+1 51 const <T&> initval,// fill with initval, 52 int maxsize = 0); // csize = maxsize 53 // or fence - lo if 0 54 55 <T>FPlex(const <T>FPlex&); // X(X&) 56 57 ~<T>FPlex(); 58 59 void operator= (const <T>FPlex&); 60 61// virtuals 62 63 <T>& high_element (); 64 <T>& low_element (); 65 66 const <T>& high_element () const; 67 const <T>& low_element () const; 68 69 Pix first() const; 70 Pix last() const; 71 void prev(Pix& ptr) const; 72 void next(Pix& ptr) const; 73 int owns(Pix p) const; 74 <T>& operator () (Pix p); 75 const <T>& operator () (Pix p) const; 76 77 int low() const; 78 int high() const; 79 int valid(int idx) const; 80 void prev(int& idx) const; 81 void next(int& x) const; 82 <T>& operator [] (int index); 83 const <T>& operator [] (int index) const; 84 85 int Pix_to_index(Pix p) const; 86 Pix index_to_Pix(int idx) const; 87 88 int can_add_high() const; 89 int can_add_low() const; 90 int full() const; 91 92 int add_high(const <T&> elem); 93 int del_high (); 94 int add_low (const <T&> elem); 95 int del_low (); 96 97 void fill(const <T&> x); 98 void fill(const <T&> x, int from, int to); 99 void clear(); 100 void reverse(); 101 void append(const <T>FPlex& a); 102 void prepend(const <T>FPlex& a); 103 104 int OK () const; 105}; 106 107#if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) 108 109inline int <T>FPlex::valid (int idx) const 110{ 111 return idx >= lo && idx < fnc; 112} 113 114inline int <T>FPlex::low() const 115{ 116 return lo; 117} 118 119inline int <T>FPlex::high() const 120{ 121 return fnc - 1; 122} 123 124inline Pix <T>FPlex::first() const 125{ 126 return (Pix)(hd-><T>IChunk::first_pointer()); 127} 128 129inline void <T>FPlex::prev(Pix& p) const 130{ 131 p = Pix(hd-><T>IChunk::pred((<T>*) p)); 132} 133 134inline void <T>FPlex::next(Pix& p) const 135{ 136 p = Pix(hd-><T>IChunk::succ((<T>*) p)); 137} 138 139inline Pix <T>FPlex::last() const 140{ 141 return Pix(hd-><T>IChunk::last_pointer()); 142} 143 144inline int <T>FPlex::full () const 145{ 146 return fnc - lo == csize; 147} 148 149inline void <T>FPlex::prev(int& idx) const 150{ 151 --idx; 152} 153 154inline void <T>FPlex::next(int& idx) const 155{ 156 ++idx; 157} 158 159inline <T>& <T>FPlex:: operator [] (int idx) 160{ 161 if (idx < lo || idx >= fnc) index_error(); 162 return *(hd->pointer_to(idx)); 163} 164 165inline <T>& <T>FPlex:: operator () (Pix p) 166{ 167 return *((<T>*)p); 168} 169 170inline <T>& <T>FPlex::low_element () 171{ 172 if (empty()) index_error(); 173 return *(hd->pointer_to(lo)); 174} 175 176inline <T>& <T>FPlex::high_element () 177{ 178 if (empty()) index_error(); 179 return *(hd->pointer_to(fnc - 1)); 180} 181 182inline const <T>& <T>FPlex:: operator [] (int idx) const 183{ 184 if (idx < lo || idx >= fnc) index_error(); 185 return *(hd->pointer_to(idx)); 186} 187 188inline const <T>& <T>FPlex:: operator () (Pix p) const 189{ 190 return *((const <T>*)p); 191} 192 193inline const <T>& <T>FPlex::low_element () const 194{ 195 if (empty()) index_error(); 196 return *(hd->pointer_to(lo)); 197} 198 199inline const <T>& <T>FPlex::high_element () const 200{ 201 if (empty()) index_error(); 202 return *(hd->pointer_to(fnc - 1)); 203} 204 205inline int <T>FPlex::can_add_high() const 206{ 207 return hd->can_grow_high(); 208} 209 210inline int <T>FPlex::can_add_low() const 211{ 212 return hd->can_grow_low(); 213} 214 215inline int <T>FPlex::add_high(const <T&> elem) 216{ 217 if (!can_add_high()) full_error(); 218 *((hd-><T>IChunk::grow_high())) = elem; 219 return fnc++; 220} 221 222inline int <T>FPlex::del_high () 223{ 224 if (empty()) empty_error(); 225 hd-><T>IChunk::shrink_high(); 226 return --fnc - 1; 227} 228 229inline int <T>FPlex::add_low (const <T&> elem) 230{ 231 if (!can_add_low()) full_error(); 232 *((hd-><T>IChunk::grow_low())) = elem; 233 return --lo; 234} 235 236inline int <T>FPlex::del_low () 237{ 238 if (empty()) empty_error(); 239 hd-><T>IChunk::shrink_low(); 240 return ++lo; 241} 242 243inline int <T>FPlex::owns (Pix p) const 244{ 245 return hd->actual_pointer((<T>*)p); 246} 247 248inline int <T>FPlex::Pix_to_index(Pix p) const 249{ 250 if (!hd->actual_pointer((const <T>*)p)) index_error(); 251 return hd->index_of((const <T>*)p); 252} 253 254inline Pix <T>FPlex::index_to_Pix(int idx) const 255{ 256 if (idx < lo || idx >= fnc) index_error(); 257 return Pix(hd->pointer_to(idx)); 258} 259 260inline <T>FPlex::~<T>FPlex() {} 261 262#endif 263#endif 264