Commit | Line | Data |
---|---|---|
9acadf40 WJ |
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>CHMap_h | |
26 | #ifdef __GNUG__ | |
27 | #pragma once | |
28 | #pragma interface | |
29 | #endif | |
30 | #define _<T><C>CHMap_h 1 | |
31 | ||
32 | #include "<T>.<C>.Map.h" | |
33 | ||
34 | #ifndef _<T><C>CHNode_h | |
35 | #define _<T><C>CHNode_h 1 | |
36 | ||
37 | struct <T><C>CHNode | |
38 | { | |
39 | <T><C>CHNode* tl; | |
40 | <T> hd; | |
41 | <C> cont; | |
42 | <T><C>CHNode(); | |
43 | <T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t = 0); | |
44 | ~<T><C>CHNode(); | |
45 | }; | |
46 | ||
47 | #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) | |
48 | ||
49 | inline <T><C>CHNode::<T><C>CHNode() {} | |
50 | ||
51 | inline <T><C>CHNode::<T><C>CHNode(<T&> h, <C&> c, <T><C>CHNode* t) | |
52 | : hd(h), cont(c), tl(t) {} | |
53 | ||
54 | inline <T><C>CHNode::~<T><C>CHNode() {} | |
55 | ||
56 | ||
57 | #endif | |
58 | ||
59 | typedef <T><C>CHNode* <T><C>CHNodePtr; | |
60 | ||
61 | #endif | |
62 | ||
63 | ||
64 | class <T><C>CHMap : public <T><C>Map | |
65 | { | |
66 | protected: | |
67 | <T><C>CHNode** tab; | |
68 | unsigned int size; | |
69 | ||
70 | public: | |
71 | <T><C>CHMap(<C&> dflt,unsigned int sz=DEFAULT_INITIAL_CAPACITY); | |
72 | <T><C>CHMap(<T><C>CHMap& a); | |
73 | ~<T><C>CHMap(); | |
74 | ||
75 | <C>& operator [] (<T&> key); | |
76 | ||
77 | void del(<T&> key); | |
78 | ||
79 | Pix first(); | |
80 | void next(Pix& i); | |
81 | <T>& key(Pix i); | |
82 | <C>& contents(Pix i); | |
83 | ||
84 | Pix seek(<T&> key); | |
85 | int contains(<T&> key); | |
86 | ||
87 | void clear(); | |
88 | int OK(); | |
89 | }; | |
90 | ||
91 | #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES) | |
92 | ||
93 | inline <T><C>CHMap::~<T><C>CHMap() | |
94 | { | |
95 | clear(); | |
96 | delete tab; | |
97 | } | |
98 | ||
99 | inline int <T><C>CHMap::contains(<T&> key) | |
100 | { | |
101 | return seek(key) != 0; | |
102 | } | |
103 | ||
104 | inline <T>& <T><C>CHMap::key(Pix p) | |
105 | { | |
106 | if (p == 0) error("null Pix"); | |
107 | return ((<T><C>CHNode*)p)->hd; | |
108 | } | |
109 | ||
110 | inline <C>& <T><C>CHMap::contents(Pix p) | |
111 | { | |
112 | if (p == 0) error("null Pix"); | |
113 | return ((<T><C>CHNode*)p)->cont; | |
114 | } | |
115 | ||
116 | ||
117 | #endif | |
118 | #endif |