2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
24 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
25 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
26 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
27 /*%% $XConsortium: tt_table.h /main/3 1995/10/23 10:45:54 rswiston $ */
32 * Generic hash table implementation
34 * Copyright (c) 1990 by Sun Microsystems, Inc.
36 #if !defined(_TT_TABLE_H)
38 #include "util/tt_generic.h"
39 #include "util/tt_list.h"
40 #include "util/tt_object_table.h"
42 #define table_of(t) name2(t,_table)
43 #define ptr_to_table_of(t) name2(table_of(t),_ptr)
44 #define cursor_in_table_of(t) name2(table_of(t),_cursor)
46 #define declare_table_of(TYPE) \
47 class table_of(TYPE) : public _Tt_object_table { \
48 friend class cursor_in_table_of(TYPE); \
50 table_of(TYPE)(int nbkts = 19): _Tt_object_table(nbkts) {} \
51 table_of(TYPE)(_Tt_object_table_keyfn kf, \
52 int nbkts = 19): _Tt_object_table(nbkts) { \
55 virtual ~table_of(TYPE)(); \
56 void insert(ptr_to(TYPE) &o) { \
57 _Tt_object_table::insert(o); \
59 ptr_to(TYPE) &lookup(const _Tt_string &key) { \
60 return (ptr_to(TYPE)&)_Tt_object_table::lookup(key); \
62 int lookup(const _Tt_string &key, ptr_to(TYPE) &obj) {\
63 return _Tt_object_table::lookup(key, obj); \
65 bool_t xdr(XDR *xdrs); \
67 declare_derived_ptr_to(table_of(TYPE),_Tt_object_table) \
69 class cursor_in_table_of(TYPE) : public _Tt_object_table_cursor { \
71 cursor_in_table_of(TYPE)() {} \
72 cursor_in_table_of(TYPE)(const _Tt_object_table_ptr &l) : \
73 _Tt_object_table_cursor(l){} \
74 cursor_in_table_of(TYPE)(const _Tt_object_table_cursor &c) : \
75 _Tt_object_table_cursor(c) {} \
76 ~cursor_in_table_of(TYPE)(); \
77 cursor_in_table_of(TYPE)& reset() { \
78 return (cursor_in_table_of(TYPE)&)_Tt_object_table_cursor::reset(); \
80 cursor_in_table_of(TYPE)& reset(ptr_to(table_of(TYPE)) &l) { \
81 return (cursor_in_table_of(TYPE)&)_Tt_object_table_cursor::reset(l); \
84 return _Tt_object_table_cursor::next(); \
87 return _Tt_object_table_cursor::prev(); \
89 int is_valid() const { \
90 return _Tt_object_table_cursor::is_valid(); \
92 ptr_to(TYPE) &operator*() { \
93 return (ptr_to(TYPE)&)_Tt_object_table_cursor::operator*(); \
95 ptr_to(TYPE) &operator->() { \
96 return (ptr_to(TYPE)&)_Tt_object_table_cursor::operator*(); \
100 #define implement_table_of(TYPE) \
106 bool_t table_of(TYPE):: \
109 return _Tt_object_table::xdr(xdrs, (_Tt_new_xdrfn)xdrfn_of(TYPE), \
110 (_Tt_object *(*)()) \
111 constructor_of(TYPE)); \
113 cursor_in_table_of(TYPE):: \
114 ~cursor_in_table_of(TYPE)() \
117 implement_derived_ptr_to(table_of(TYPE),_Tt_object_table)