home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__lib / map.hp < prev    next >
Text File  |  1993-07-23  |  2KB  |  89 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.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor
  10. accepts responsibility to anyone for the consequences of using it
  11. or for whether it serves any particular purpose or works at all,
  12. unless he says so in writing.  Refer to the GNU CC General Public
  13. License for full details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute
  16. GNU CC, but only under the conditions described in the
  17. GNU CC General Public License.   A copy of this license is
  18. supposed to have been given to you along with GNU CC so you
  19. can know your rights and responsibilities.  It should be in a
  20. file named COPYING.  Among other things, the copyright notice
  21. and this notice must be preserved on all copies.  
  22. */
  23.  
  24.  
  25. #ifndef _<T><C>Map_h
  26. #pragma once
  27. #define _<T><C>Map_h 1
  28.  
  29. #include <Pix.h>
  30. #include "<T>.defs.h"
  31.  
  32. class <T><C>Map
  33. {
  34. protected:
  35.   int                   count;
  36.   <C>                   def;
  37.  
  38. public:
  39.                         <T><C>Map(<C&> dflt);
  40.  
  41.   int                   length();                // current number of items
  42.   int                   empty();
  43.  
  44.   virtual int           contains(<T&> key);      // is key mapped?
  45.  
  46.   virtual void          clear();                 // delete all items
  47.  
  48.   virtual <C>&          operator [] (<T&> key);  // access contents by key
  49.  
  50.   virtual void          del(<T&> key);           // delete entry
  51.  
  52.   virtual Pix           first();                 // Pix of first item or 0
  53.   virtual void          next(Pix& i);            // advance to next or 0
  54.   virtual <T>&          key(Pix i);              // access key at i
  55.   virtual <C>&          contents(Pix i);         // access contents at i
  56.  
  57.   virtual int           owns(Pix i);             // is i a valid Pix  ?
  58.   virtual Pix           seek(<T&> key);          // Pix of key
  59.  
  60.   <C>&                  dflt();                  // access default val
  61.  
  62.   void                  error(char* msg);
  63.   virtual int           OK();                    // rep invariant
  64. };
  65.  
  66.  
  67. inline int <T><C>Map::length()
  68. {
  69.   return count;
  70. }
  71.  
  72. inline int <T><C>Map::empty()
  73. {
  74.   return count == 0;
  75. }
  76.  
  77. inline <C>& <T><C>Map::dflt()
  78. {
  79.   return def;
  80. }
  81.  
  82. inline <T><C>Map::<T><C>Map(<C&> dflt) :def(dflt)
  83. {
  84.   count = 0;
  85. }
  86.  
  87.  
  88. #endif
  89.