Don't truncate pointers on Windows x64 platform
[platform/upstream/dbus.git] / dbus / dbus-hash.h
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifndef DBUS_HASH_H
25 #define DBUS_HASH_H
26
27 #ifdef HAVE_CONFIG_H
28 #include <config.h>
29 #endif
30
31 #ifdef HAVE_INTTYPES_H
32 #include <inttypes.h>
33 #endif
34
35 #include <dbus/dbus-memory.h>
36 #include <dbus/dbus-types.h>
37
38 DBUS_BEGIN_DECLS
39
40 /**
41  * @addtogroup DBusHashTable
42  * @{
43  */
44
45 /** Hash iterator object. The iterator is on the stack, but its real
46  * fields are hidden privately.
47  */
48 struct DBusHashIter
49 {
50   void *dummy1; /**< Do not use. */
51   void *dummy2; /**< Do not use. */
52   void *dummy3; /**< Do not use. */
53   void *dummy4; /**< Do not use. */
54   int   dummy5; /**< Do not use. */
55   int   dummy6; /**< Do not use. */
56 };
57
58 typedef struct DBusHashTable DBusHashTable;
59 typedef struct DBusHashIter  DBusHashIter;
60
61 /* Allowing an arbitrary function as with GLib
62  * would be nicer for a public API, but for
63  * an internal API this saves typing, we can add
64  * more whenever we feel like it.
65  */
66 typedef enum
67 {
68   DBUS_HASH_STRING,        /**< Hash keys are strings. */
69   DBUS_HASH_TWO_STRINGS,   /**< Hash key is two strings in one memory block, i.e. foo\\0bar\\0 */
70   DBUS_HASH_INT,           /**< Hash keys are integers. */
71   DBUS_HASH_POINTER,       /**< Hash keys are pointers. */
72   DBUS_HASH_UINTPTR        /**< Hash keys are integer capable to hold a pointer. */
73 } DBusHashType;
74
75 DBusHashTable* _dbus_hash_table_new                (DBusHashType      type,
76                                                     DBusFreeFunction  key_free_function,
77                                                     DBusFreeFunction  value_free_function);
78 DBusHashTable* _dbus_hash_table_ref                (DBusHashTable    *table);
79 void           _dbus_hash_table_unref              (DBusHashTable    *table);
80 void           _dbus_hash_table_remove_all         (DBusHashTable    *table);
81 void           _dbus_hash_iter_init                (DBusHashTable    *table,
82                                                     DBusHashIter     *iter);
83 dbus_bool_t    _dbus_hash_iter_next                (DBusHashIter     *iter);
84 void           _dbus_hash_iter_remove_entry        (DBusHashIter     *iter);
85 void*          _dbus_hash_iter_get_value           (DBusHashIter     *iter);
86 void           _dbus_hash_iter_set_value           (DBusHashIter     *iter,
87                                                     void             *value);
88 int            _dbus_hash_iter_get_int_key         (DBusHashIter     *iter);
89 const char*    _dbus_hash_iter_get_string_key      (DBusHashIter     *iter);
90 const char*    _dbus_hash_iter_get_two_strings_key (DBusHashIter     *iter);
91 uintptr_t      _dbus_hash_iter_get_uintptr_key     (DBusHashIter     *iter);
92 dbus_bool_t    _dbus_hash_iter_lookup              (DBusHashTable    *table,
93                                                     void             *key,
94                                                     dbus_bool_t       create_if_not_found,
95                                                     DBusHashIter     *iter);
96 void*          _dbus_hash_table_lookup_string      (DBusHashTable    *table,
97                                                     const char       *key);
98 void*          _dbus_hash_table_lookup_two_strings (DBusHashTable    *table,
99                                                     const char       *key);
100 void*          _dbus_hash_table_lookup_int         (DBusHashTable    *table,
101                                                     int               key);
102 void*          _dbus_hash_table_lookup_pointer     (DBusHashTable    *table,
103                                                     void             *key);
104 void*          _dbus_hash_table_lookup_uintptr     (DBusHashTable    *table,
105                                                     uintptr_t         key);
106 dbus_bool_t    _dbus_hash_table_remove_string      (DBusHashTable    *table,
107                                                     const char       *key);
108 dbus_bool_t    _dbus_hash_table_remove_two_strings (DBusHashTable    *table,
109                                                     const char       *key);
110 dbus_bool_t    _dbus_hash_table_remove_int         (DBusHashTable    *table,
111                                                     int               key);
112 dbus_bool_t    _dbus_hash_table_remove_pointer     (DBusHashTable    *table,
113                                                     void             *key);
114 dbus_bool_t    _dbus_hash_table_remove_uintptr     (DBusHashTable    *table,
115                                                     uintptr_t         key);
116 dbus_bool_t    _dbus_hash_table_insert_string      (DBusHashTable    *table,
117                                                     char             *key,
118                                                     void             *value);
119 dbus_bool_t    _dbus_hash_table_insert_two_strings (DBusHashTable    *table,
120                                                     char             *key,
121                                                     void             *value);
122 dbus_bool_t    _dbus_hash_table_insert_int         (DBusHashTable    *table,
123                                                     int               key,
124                                                     void             *value);
125 dbus_bool_t    _dbus_hash_table_insert_pointer     (DBusHashTable    *table,
126                                                     void             *key,
127                                                     void             *value);
128 dbus_bool_t    _dbus_hash_table_insert_uintptr     (DBusHashTable    *table,
129                                                     uintptr_t         key,
130                                                     void             *value);
131 int            _dbus_hash_table_get_n_entries      (DBusHashTable    *table);
132
133 /* Preallocation */
134
135 /** A preallocated hash entry */
136 typedef struct DBusPreallocatedHash DBusPreallocatedHash;
137
138 DBusPreallocatedHash *_dbus_hash_table_preallocate_entry          (DBusHashTable        *table);
139 void                  _dbus_hash_table_free_preallocated_entry    (DBusHashTable        *table,
140                                                                    DBusPreallocatedHash *preallocated);
141 void                  _dbus_hash_table_insert_string_preallocated (DBusHashTable        *table,
142                                                                    DBusPreallocatedHash *preallocated,
143                                                                    char                 *key,
144                                                                    void                 *value);
145
146 /** @} */
147
148 DBUS_END_DECLS
149
150 #endif /* DBUS_HASH_H */