home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / fplex.hp < prev    next >
Text File  |  1993-07-23  |  5KB  |  235 lines

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