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