home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-bin.lha / lib / g++-include / gen / FPlex.hP < prev    next >
Text File  |  1996-10-12  |  6KB  |  254 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 the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #ifndef _<T>FPlex_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _<T>FPlex_h 1
  25.  
  26. #include "<T>.Plex.h"
  27.  
  28. class <T>FPlex : public <T>Plex
  29. {
  30. public:
  31.                    <T>FPlex();                 // set low = 0;
  32.                                                // fence = 0;
  33.                                                // csize = default
  34.  
  35.                    <T>FPlex(int maxsize);      // low = 0; 
  36.                                                // fence = 0;
  37.                                                // csize = maxsize
  38.  
  39.                    <T>FPlex(int lo,            // low = lo; 
  40.                             int maxsize);      // fence=lo
  41.                                                // csize = maxsize
  42.  
  43.                    <T>FPlex(int lo,            // low = lo
  44.                             int hi,            // fence = hi+1
  45.                             const <T&> initval,// fill with initval,
  46.                             int maxsize = 0);  // csize = maxsize
  47.                                                // or fence - lo if 0
  48.  
  49.                    <T>FPlex(const <T>FPlex&);   // X(X&)
  50.  
  51.   inline                  ~<T>FPlex();
  52.  
  53.   void             operator= (const <T>FPlex&);
  54.  
  55. // virtuals
  56.  
  57.   inline <T>&             high_element ();
  58.   inline <T>&             low_element ();
  59.  
  60.   inline const <T>&       high_element () const;
  61.   inline const <T>&       low_element () const;
  62.  
  63.   inline Pix              first() const;
  64.   inline Pix              last() const;
  65.   inline void             prev(Pix& ptr) const;
  66.   inline void             next(Pix& ptr) const;
  67.   inline int              owns(Pix p) const;
  68.   inline <T>&             operator () (Pix p);
  69.   inline const <T>&       operator () (Pix p) const;
  70.  
  71.   inline int              low() const; 
  72.   inline int              high() const;
  73.   inline int              valid(int idx) const;
  74.   inline void             prev(int& idx) const;
  75.   inline void             next(int& x) const;
  76.   inline <T>&             operator [] (int index);
  77.   inline const <T>&       operator [] (int index) const;
  78.     
  79.   inline int              Pix_to_index(Pix p) const;
  80.   inline Pix              index_to_Pix(int idx) const;    
  81.  
  82.   inline int              can_add_high() const;
  83.   inline int              can_add_low() const;
  84.   inline int              full() const;
  85.  
  86.   inline int              add_high(const <T&> elem);
  87.   inline int              del_high ();
  88.   inline int              add_low (const <T&> elem);
  89.   inline int              del_low ();
  90.  
  91.   void             fill(const <T&> x);
  92.   void             fill(const <T&> x, int from, int to);
  93.   void             clear();
  94.   void             reverse();
  95.  
  96.   int              OK () const; 
  97. };
  98.  
  99.  
  100. inline  int <T>FPlex::valid (int idx) const
  101. {
  102.   return idx >= lo && idx < fnc;
  103. }
  104.  
  105. inline int <T>FPlex::low() const
  106. {
  107.   return lo;
  108. }
  109.  
  110. inline int <T>FPlex::high() const
  111. {
  112.   return fnc - 1;
  113. }
  114.  
  115. inline Pix  <T>FPlex::first() const
  116. {
  117.   return (Pix)(hd-><T>IChunk::first_pointer());
  118. }
  119.  
  120. inline void  <T>FPlex::prev(Pix&  p) const
  121. {
  122.   p = Pix(hd-><T>IChunk::pred((<T>*) p));
  123. }
  124.  
  125. inline void  <T>FPlex::next(Pix&  p) const
  126. {
  127.   p =  Pix(hd-><T>IChunk::succ((<T>*) p));
  128. }
  129.  
  130. inline Pix <T>FPlex::last() const
  131. {
  132.   return Pix(hd-><T>IChunk::last_pointer());
  133. }
  134.  
  135. inline  int <T>FPlex::full () const
  136. {
  137.   return fnc - lo == csize;
  138. }
  139.  
  140. inline void <T>FPlex::prev(int& idx) const
  141. {
  142.   --idx;
  143. }
  144.  
  145. inline void <T>FPlex::next(int& idx) const
  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 const <T>& <T>FPlex:: operator [] (int idx) const
  174. {
  175.   if (idx < lo || idx >= fnc) index_error();
  176.   return *(hd->pointer_to(idx));
  177. }
  178.  
  179. inline const <T>& <T>FPlex:: operator () (Pix p) const
  180. {
  181.   return *((const <T>*)p);
  182. }
  183.  
  184. inline const <T>& <T>FPlex::low_element () const
  185. {
  186.   if (empty()) index_error();
  187.   return *(hd->pointer_to(lo));
  188. }
  189.  
  190. inline const  <T>& <T>FPlex::high_element () const
  191. {
  192.   if (empty()) index_error();
  193.   return *(hd->pointer_to(fnc - 1));
  194. }
  195.  
  196. inline int <T>FPlex::can_add_high() const
  197. {
  198.   return hd->can_grow_high();
  199. }
  200.  
  201. inline int <T>FPlex::can_add_low() const
  202. {
  203.   return hd->can_grow_low();
  204. }
  205.  
  206. inline int <T>FPlex::add_high(const <T&> elem)
  207. {
  208.   if (!can_add_high()) full_error();
  209.   *((hd-><T>IChunk::grow_high())) = elem;
  210.   return fnc++;
  211. }
  212.  
  213. inline  int <T>FPlex::del_high ()
  214. {
  215.   if (empty()) empty_error();
  216.   hd-><T>IChunk::shrink_high();
  217.   return --fnc - 1;
  218. }
  219.  
  220. inline  int <T>FPlex::add_low (const <T&> elem)
  221. {
  222.   if (!can_add_low()) full_error();
  223.   *((hd-><T>IChunk::grow_low())) = elem;
  224.   return --lo;
  225. }
  226.  
  227. inline  int <T>FPlex::del_low ()
  228. {
  229.   if (empty()) empty_error();
  230.   hd-><T>IChunk::shrink_low();
  231.   return ++lo;
  232. }
  233.  
  234. inline  int <T>FPlex::owns (Pix p) const
  235. {
  236.   return hd->actual_pointer((<T>*)p);
  237. }
  238.  
  239. inline  int <T>FPlex::Pix_to_index(Pix p) const
  240. {
  241.   if (!hd->actual_pointer((const <T>*)p)) index_error();
  242.   return hd->index_of((const <T>*)p);
  243. }
  244.  
  245. inline  Pix <T>FPlex::index_to_Pix(int idx) const
  246. {
  247.   if (idx < lo || idx >= fnc) index_error();
  248.   return Pix(hd->pointer_to(idx));
  249. }
  250.  
  251. inline <T>FPlex::~<T>FPlex() {}
  252.  
  253. #endif
  254.