modules/up/src/gnug++/unsigned.XPlex.h

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. unsignedXPlex
  2. prev
  3. next
  4. full
  5. can_add_high
  6. can_add_low
  7. valid
  8. low
  9. high
  10. low_element
  11. low_element
  12. high_element
  13. high_element
  14. Pix_to_index
  15. index_to_Pix
  16. first
  17. last
  18. prev
  19. next
  20. set_cache

   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 _unsignedXPlex_h
  21 #ifdef __GNUG__
  22 #pragma interface
  23 #endif
  24 #define _unsignedXPlex_h 1
  25 
  26 #include "unsigned.Plex.h"
  27 
  28 class unsignedXPlex: public unsignedPlex
     /* [<][>][^][v][top][bottom][index][help] */
  29 {
  30   unsignedIChunk*       ch;           // cached chunk
  31 
  32   void             make_initial_chunks(int up = 1);
  33 
  34   void             cache(int idx) const;
  35   void             cache(const unsigned* p) const;
  36 
  37   unsigned*             dopred(const unsigned* p) const;
  38   unsigned*             dosucc(const unsigned* p) const;
  39 
  40   inline void             set_cache(const unsignedIChunk* t) const; // logically, 
  41                                                // not physically const
  42 public:
  43                    unsignedXPlex();                 // set low = 0;
  44                                                // fence = 0;
  45                                                // csize = default
  46 
  47                    unsignedXPlex(int ch_size);      // low = 0; 
  48                                                // fence = 0;
  49                                                // csize = ch_size
  50 
  51                    unsignedXPlex(int lo,            // low = lo; 
  52                             int ch_size);      // fence=lo
  53                                                // csize = ch_size
  54 
  55                    unsignedXPlex(int lo,            // low = lo
  56                             int hi,            // fence = hi+1
  57                             const unsigned  initval,// fill with initval,
  58                             int ch_size = 0);  // csize= ch_size
  59                                                // or fence-lo if 0
  60 
  61                    unsignedXPlex(const unsignedXPlex&);
  62   
  63   void             operator= (const unsignedXPlex&);
  64 
  65 // virtuals
  66 
  67 
  68   inline unsigned&             high_element ();
  69   inline unsigned&             low_element ();
  70 
  71   inline const unsigned&       high_element () const;
  72   inline const unsigned&       low_element () const;
  73 
  74   inline Pix              first() const;
  75   inline Pix              last() const;
  76   inline void             prev(Pix& ptr) const;
  77   inline void             next(Pix& ptr) const;
  78   int              owns(Pix p) const;
  79   inline unsigned&             operator () (Pix p);
  80   inline const unsigned&       operator () (Pix p) const;
  81 
  82   inline int              low() const; 
  83   inline int              high() const;
  84   inline int              valid(int idx) const;
  85   inline void             prev(int& idx) const;
  86   inline void             next(int& x) const;
  87   inline unsigned&             operator [] (int index);
  88   inline const unsigned&       operator [] (int index) const;
  89     
  90   inline int              Pix_to_index(Pix p) const;
  91   inline Pix              index_to_Pix(int idx) const;    
  92 
  93   inline int              can_add_high() const;
  94   inline int              can_add_low() const;
  95   inline int              full() const;
  96 
  97   int              add_high(const unsigned  elem);
  98   int              del_high ();
  99   int              add_low (const unsigned  elem);
 100   int              del_low ();
 101 
 102   void             fill(const unsigned  x);
 103   void             fill(const unsigned  x, int from, int to);
 104   void             clear();
 105   void             reverse();
 106     
 107   int              OK () const; 
 108 
 109 };
 110 
 111 
 112 inline void unsignedXPlex::prev(int& idx) const
     /* [<][>][^][v][top][bottom][index][help] */
 113 {
 114   --idx;
 115 }
 116 
 117 inline void unsignedXPlex::next(int& idx) const
     /* [<][>][^][v][top][bottom][index][help] */
 118 {
 119   ++idx;
 120 }
 121 
 122 inline  int unsignedXPlex::full () const
     /* [<][>][^][v][top][bottom][index][help] */
 123 {
 124   return 0;
 125 }
 126 
 127 inline int unsignedXPlex::can_add_high() const
     /* [<][>][^][v][top][bottom][index][help] */
 128 {
 129   return 1;
 130 }
 131 
 132 inline int unsignedXPlex::can_add_low() const
     /* [<][>][^][v][top][bottom][index][help] */
 133 {
 134   return 1;
 135 }
 136 
 137 inline  int unsignedXPlex::valid (int idx) const
     /* [<][>][^][v][top][bottom][index][help] */
 138 {
 139   return idx >= lo && idx < fnc;
 140 }
 141 
 142 inline int unsignedXPlex::low() const
     /* [<][>][^][v][top][bottom][index][help] */
 143 {
 144   return lo;
 145 }
 146 
 147 inline int unsignedXPlex::high() const
     /* [<][>][^][v][top][bottom][index][help] */
 148 {
 149   return fnc - 1;
 150 }
 151 
 152 inline unsigned& unsignedXPlex:: operator [] (int idx)
 153 {
 154   if (!ch->actual_index(idx)) cache(idx);
 155   return *(ch->pointer_to(idx));
 156 }
 157 
 158 inline const unsigned& unsignedXPlex:: operator [] (int idx) const
 159 {
 160   if (!ch->actual_index(idx)) cache(idx);
 161   return *((const unsigned*)(ch->pointer_to(idx)));
 162 }
 163 
 164 inline  unsigned& unsignedXPlex::low_element ()
     /* [<][>][^][v][top][bottom][index][help] */
 165 {
 166   if (empty()) index_error();
 167   return *(hd->pointer_to(lo));
 168 }
 169 
 170 inline  const unsigned& unsignedXPlex::low_element () const
     /* [<][>][^][v][top][bottom][index][help] */
 171 {
 172   if (empty()) index_error();
 173   return *((const unsigned*)(hd->pointer_to(lo)));
 174 }
 175 
 176 inline  unsigned& unsignedXPlex::high_element ()
     /* [<][>][^][v][top][bottom][index][help] */
 177 {
 178   if (empty()) index_error();
 179   return *(tl()->pointer_to(fnc - 1));
 180 }
 181 
 182 inline const unsigned& unsignedXPlex::high_element () const
     /* [<][>][^][v][top][bottom][index][help] */
 183 {
 184   if (empty()) index_error();
 185   return *((const unsigned*)(tl()->pointer_to(fnc - 1)));
 186 }
 187 
 188 inline  int unsignedXPlex::Pix_to_index(Pix px) const
     /* [<][>][^][v][top][bottom][index][help] */
 189 {
 190   unsigned* p = (unsigned*)px;
 191   if (!ch->actual_pointer(p)) cache(p);
 192   return ch->index_of(p);
 193 }
 194 
 195 inline  Pix unsignedXPlex::index_to_Pix(int idx) const
     /* [<][>][^][v][top][bottom][index][help] */
 196 {
 197   if (!ch->actual_index(idx)) cache(idx);
 198   return (Pix)(ch->pointer_to(idx));
 199 }
 200 
 201 inline Pix unsignedXPlex::first() const
     /* [<][>][^][v][top][bottom][index][help] */
 202 {
 203   return Pix(hd->unsignedIChunk::first_pointer());
 204 }
 205 
 206 inline Pix unsignedXPlex::last() const
     /* [<][>][^][v][top][bottom][index][help] */
 207 {
 208   return Pix(tl()->unsignedIChunk::last_pointer());
 209 }
 210 
 211 inline void unsignedXPlex::prev(Pix& p) const
     /* [<][>][^][v][top][bottom][index][help] */
 212 {
 213   Pix q = Pix(ch->unsignedIChunk::pred((unsigned*) p));
 214   p = (q == 0)? Pix(dopred((const unsigned*) p)) : q;
 215 }
 216 
 217 inline void unsignedXPlex::next(Pix& p) const
     /* [<][>][^][v][top][bottom][index][help] */
 218 {
 219   Pix q = Pix(ch->unsignedIChunk::succ((unsigned*) p));
 220   p = (q == 0)? Pix(dosucc((const unsigned*)p)) : q;
 221 }
 222 
 223 inline unsigned& unsignedXPlex:: operator () (Pix p)
 224 {
 225   return *((unsigned*)p);
 226 }
 227 
 228 inline const unsigned& unsignedXPlex:: operator () (Pix p) const
 229 {
 230   return *((const unsigned*)p);
 231 }
 232 
 233 inline void unsignedXPlex::set_cache(const unsignedIChunk* t) const
     /* [<][>][^][v][top][bottom][index][help] */
 234 {
 235   ((unsignedXPlex*)(this))->ch = (unsignedIChunk*)t;
 236 }
 237 
 238 #endif

/* [<][>][^][v][top][bottom][index][help] */