Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / util / tt_table.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 /*%%  (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 $                                                    */
28 /* -*-C++-*-
29  *
30  * tt_table.h
31  *
32  * Generic hash table implementation
33  *
34  * Copyright (c) 1990 by Sun Microsystems, Inc.
35  */
36 #if !defined(_TT_TABLE_H)
37 #define _TT_TABLE_H
38 #include "util/tt_generic.h"
39 #include "util/tt_list.h"
40 #include "util/tt_object_table.h"
41
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)
45
46 #define declare_table_of(TYPE)                                                  \
47 class table_of(TYPE) : public _Tt_object_table {                                \
48     friend class cursor_in_table_of(TYPE);                                      \
49       public:                                                                   \
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) {               \
53                                set_keyfn(kf);                                   \
54         }                                                                       \
55         virtual ~table_of(TYPE)();                                              \
56         void                    insert(ptr_to(TYPE) &o) {                       \
57                 _Tt_object_table::insert(o);                                    \
58         }                                                                       \
59         ptr_to(TYPE)            &lookup(const _Tt_string &key) {                \
60                 return (ptr_to(TYPE)&)_Tt_object_table::lookup(key);            \
61         }                                                                       \
62         int                     lookup(const _Tt_string &key, ptr_to(TYPE) &obj) {\
63                 return _Tt_object_table::lookup(key, obj);              \
64         }                                                               \
65         bool_t                  xdr(XDR *xdrs);                                 \
66 };                                                                              \
67 declare_derived_ptr_to(table_of(TYPE),_Tt_object_table)                         \
68                                                                                 \
69 class cursor_in_table_of(TYPE) : public _Tt_object_table_cursor {               \
70       public:                                                                   \
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();     \
79         }                                                                       \
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);    \
82         }                                                                       \
83         int                             next() {                                \
84                 return _Tt_object_table_cursor::next();                         \
85         }                                                                       \
86         int                             prev() {                                \
87                 return _Tt_object_table_cursor::prev();                         \
88         }                                                                       \
89         int                             is_valid() const {                      \
90                 return _Tt_object_table_cursor::is_valid();                     \
91         }                                                                       \
92         ptr_to(TYPE)                    &operator*() {                          \
93                 return (ptr_to(TYPE)&)_Tt_object_table_cursor::operator*();     \
94         }                                                                       \
95         ptr_to(TYPE)                    &operator->() {                         \
96                 return (ptr_to(TYPE)&)_Tt_object_table_cursor::operator*();     \
97         }                                                                       \
98 };
99
100 #define implement_table_of(TYPE)                                                \
101 table_of(TYPE)::                                                                \
102 ~table_of(TYPE)()                                                               \
103 {                                                                               \
104 }                                                                               \
105                                                                                 \
106 bool_t table_of(TYPE)::                                                       \
107 xdr(XDR *xdrs)                                                                \
108 {                                                                             \
109     return _Tt_object_table::xdr(xdrs, (_Tt_new_xdrfn)xdrfn_of(TYPE),         \
110                              (_Tt_object *(*)())                              \
111                              constructor_of(TYPE));                           \
112 }                                                                             \
113 cursor_in_table_of(TYPE)::                                                      \
114 ~cursor_in_table_of(TYPE)()                                                     \
115 {                                                                               \
116 }                                                                               \
117 implement_derived_ptr_to(table_of(TYPE),_Tt_object_table)
118
119 #endif                          // TT_TABLE_H