Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / PointerTable.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: PointerTable.h /main/1 1996/07/29 17:01:44 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifndef PointerTable_INCLUDED
28 #define PointerTable_INCLUDED 1
29
30 #include "Vector.h"
31 #include "Boolean.h"
32 #include <stddef.h>
33
34 #ifdef SP_NAMESPACE
35 namespace SP_NAMESPACE {
36 #endif
37
38 template<class P, class K, class HF, class KF> class PointerTableIter;
39
40 template<class P, class K, class HF, class KF>
41 class PointerTable {
42   void constraints() {
43     P p(0);
44     K key = KF::key(*p);
45     unsigned long n = HF::hash(key);
46     n = 0;                      // prevent warning
47   }
48 public:
49   PointerTable();
50   P insert(P, Boolean replace = 0);
51   // Return a reference so that it is possible to do
52   // lookups into a table of smart-pointers from multiple threads.
53   const P &lookup(const K &) const;
54   P remove(const K &);
55   size_t count() const { return used_; }
56   void clear();
57   void swap(PointerTable<P, K, HF, KF> &);
58 protected:
59   size_t used_;
60   size_t usedLimit_;
61   Vector<P> vec_;
62   P null_;
63
64   size_t startIndex(const K &k) const {
65     return size_t(HF::hash(k) & (vec_.size() - 1));
66   }
67   size_t nextIndex(size_t i) const {
68     return i == 0 ? vec_.size() - 1 : i - 1;
69   }
70   friend class PointerTableIter<P, K, HF, KF>;
71 };
72
73 template<class P, class K, class HF, class KF>
74 class PointerTableIter {
75 public:
76   PointerTableIter(const PointerTable<P, K, HF, KF> &);
77   const P &next();
78 private:
79   const PointerTable<P, K, HF, KF> *tablePtr_;
80   size_t i_;
81 };
82
83 #ifdef SP_NAMESPACE
84 }
85 #endif
86
87 #endif /* not PointerTable_INCLUDED */
88
89 #ifdef SP_DEFINE_TEMPLATES
90 #include "PointerTable.C"
91 #endif