Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / HashTable.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: HashTable.h /main/1 1996/07/29 16:52:57 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef HashTable_INCLUDED
28 #define HashTable_INCLUDED 1
29
30 #include <stddef.h>
31 #include "OwnerTable.h"
32 #include "Hash.h"
33 #include "Boolean.h"
34 #include "HashTableItemBase.h"
35
36 #ifdef SP_NAMESPACE
37 namespace SP_NAMESPACE {
38 #endif
39
40 template<class K, class V>
41 class HashTableItem : public HashTableItemBase<K> {
42 public:
43   HashTableItem(const K &k, const V &v);
44   HashTableItemBase<K> *copy() const;
45   V value;
46 };
47
48 template<class K, class V> class HashTableIter;
49
50 template<class K, class V>
51 class HashTable {
52 public:
53   HashTable() { }
54   void insert(const K &key, const V &value, Boolean replace = 1);
55   const V *lookup(const K &key) const {
56     HashTableItem<K, V> *tem = (HashTableItem<K, V> *)table_.lookup(key);
57     return tem ? &tem->value : 0;
58   }
59   size_t count() const { return table_.count(); }
60 private:
61   CopyOwnerTable<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > table_;
62 friend class HashTableIter<K,V>;
63 };
64
65 template<class K, class V>
66 class HashTableIter {
67 public:
68   HashTableIter(const HashTable<K, V> &table) : iter_(table.table_) { }
69   Boolean next(const K *&key, const V *&value) {
70     HashTableItem<K, V> *p = (HashTableItem<K, V> *)iter_.next();
71     if (p) {
72       key = &p->key;
73       value = &p->value;
74       return 1;
75     }
76     else
77       return 0;
78   }
79 private:
80   OwnerTableIter<HashTableItemBase<K>, K, Hash, HashTableKeyFunction<K> > iter_;
81 };
82
83 #ifdef SP_NAMESPACE
84 }
85 #endif
86
87 #endif /* not HashTable_INCLUDED */
88
89 #ifdef SP_DEFINE_TEMPLATES
90 #include "HashTable.C"
91 #endif