2006-10-19 Havoc Pennington <hp@redhat.com>
[platform/upstream/dbus.git] / dbus / dbus-hash.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-hash.h Generic hash table utility (internal to D-Bus implementation)
3  * 
4  * Copyright (C) 2002  Red Hat, Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #ifndef DBUS_HASH_H
25 #define DBUS_HASH_H
26
27 #include <dbus/dbus-memory.h>
28 #include <dbus/dbus-types.h>
29
30 DBUS_BEGIN_DECLS
31
32 /** Hash iterator object. The iterator is on the stack, but its real
33  * fields are hidden privately.
34  */
35 struct DBusHashIter
36 {
37   void *dummy1; /**< Do not use. */
38   void *dummy2; /**< Do not use. */
39   void *dummy3; /**< Do not use. */
40   void *dummy4; /**< Do not use. */
41   int   dummy5; /**< Do not use. */
42   int   dummy6; /**< Do not use. */
43 };
44
45 typedef struct DBusHashTable DBusHashTable;
46 typedef struct DBusHashIter  DBusHashIter;
47
48 /* Allowing an arbitrary function as with GLib
49  * would be nicer for a public API, but for
50  * an internal API this saves typing, we can add
51  * more whenever we feel like it.
52  */
53 typedef enum
54 {
55   DBUS_HASH_STRING,        /**< Hash keys are strings. */
56   DBUS_HASH_TWO_STRINGS,   /**< Hash key is two strings in one memory block, i.e. foo\\0bar\\0 */
57   DBUS_HASH_INT,           /**< Hash keys are integers. */
58   DBUS_HASH_POINTER,       /**< Hash keys are pointers. */
59   DBUS_HASH_ULONG          /**< Hash keys are unsigned long. */
60 } DBusHashType;
61
62 DBusHashTable* _dbus_hash_table_new                (DBusHashType      type,
63                                                     DBusFreeFunction  key_free_function,
64                                                     DBusFreeFunction  value_free_function);
65 DBusHashTable* _dbus_hash_table_ref                (DBusHashTable    *table);
66 void           _dbus_hash_table_unref              (DBusHashTable    *table);
67 void           _dbus_hash_table_remove_all         (DBusHashTable    *table);
68 void           _dbus_hash_iter_init                (DBusHashTable    *table,
69                                                     DBusHashIter     *iter);
70 dbus_bool_t    _dbus_hash_iter_next                (DBusHashIter     *iter);
71 void           _dbus_hash_iter_remove_entry        (DBusHashIter     *iter);
72 void*          _dbus_hash_iter_get_value           (DBusHashIter     *iter);
73 void           _dbus_hash_iter_set_value           (DBusHashIter     *iter,
74                                                     void             *value);
75 int            _dbus_hash_iter_get_int_key         (DBusHashIter     *iter);
76 const char*    _dbus_hash_iter_get_string_key      (DBusHashIter     *iter);
77 const char*    _dbus_hash_iter_get_two_strings_key (DBusHashIter     *iter);
78 unsigned long  _dbus_hash_iter_get_ulong_key       (DBusHashIter     *iter);
79 dbus_bool_t    _dbus_hash_iter_lookup              (DBusHashTable    *table,
80                                                     void             *key,
81                                                     dbus_bool_t       create_if_not_found,
82                                                     DBusHashIter     *iter);
83 void*          _dbus_hash_table_lookup_string      (DBusHashTable    *table,
84                                                     const char       *key);
85 void*          _dbus_hash_table_lookup_two_strings (DBusHashTable    *table,
86                                                     const char       *key);
87 void*          _dbus_hash_table_lookup_int         (DBusHashTable    *table,
88                                                     int               key);
89 void*          _dbus_hash_table_lookup_pointer     (DBusHashTable    *table,
90                                                     void             *key);
91 void*          _dbus_hash_table_lookup_ulong       (DBusHashTable    *table,
92                                                     unsigned long     key);
93 dbus_bool_t    _dbus_hash_table_remove_string      (DBusHashTable    *table,
94                                                     const char       *key);
95 dbus_bool_t    _dbus_hash_table_remove_two_strings (DBusHashTable    *table,
96                                                     const char       *key);
97 dbus_bool_t    _dbus_hash_table_remove_int         (DBusHashTable    *table,
98                                                     int               key);
99 dbus_bool_t    _dbus_hash_table_remove_pointer     (DBusHashTable    *table,
100                                                     void             *key);
101 dbus_bool_t    _dbus_hash_table_remove_ulong       (DBusHashTable    *table,
102                                                     unsigned long     key);
103 dbus_bool_t    _dbus_hash_table_insert_string      (DBusHashTable    *table,
104                                                     char             *key,
105                                                     void             *value);
106 dbus_bool_t    _dbus_hash_table_insert_two_strings (DBusHashTable    *table,
107                                                     char             *key,
108                                                     void             *value);
109 dbus_bool_t    _dbus_hash_table_insert_int         (DBusHashTable    *table,
110                                                     int               key,
111                                                     void             *value);
112 dbus_bool_t    _dbus_hash_table_insert_pointer     (DBusHashTable    *table,
113                                                     void             *key,
114                                                     void             *value);
115 dbus_bool_t    _dbus_hash_table_insert_ulong       (DBusHashTable    *table,
116                                                     unsigned long     key,
117                                                     void             *value);
118 int            _dbus_hash_table_get_n_entries      (DBusHashTable    *table);
119
120 /* Preallocation */
121 typedef struct DBusPreallocatedHash DBusPreallocatedHash;
122
123 DBusPreallocatedHash *_dbus_hash_table_preallocate_entry          (DBusHashTable        *table);
124 void                  _dbus_hash_table_free_preallocated_entry    (DBusHashTable        *table,
125                                                                    DBusPreallocatedHash *preallocated);
126 void                  _dbus_hash_table_insert_string_preallocated (DBusHashTable        *table,
127                                                                    DBusPreallocatedHash *preallocated,
128                                                                    char                 *key,
129                                                                    void                 *value);
130
131
132 DBUS_END_DECLS
133
134 #endif /* DBUS_HASH_H */